Changeset 44530
- Timestamp:
- 01/16/20 15:12:00 (3 years ago)
- Location:
- titan
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/plugins/makesh4.sh
r44077 r44530 166 166 compile "hello" "hello" "" "" 167 167 compile "panel" "panel" "" "" 168 compile "mc" "mc" "" " "168 compile "mc" "mc" "" "-l curl" 169 169 compile "TopfieldVFD" "TopfieldVFD" "" "" 170 170 compile "mboxinfo" "mboxinfo" "" "" -
titan/plugins/mc/mc_global.h
r42897 r44530 1175 1175 } 1176 1176 1177 #include <stdio.h> 1178 #include <curl/curl.h> 1179 1180 /* This callback is, currently, a simple wrapper around fwrite(). You 1181 could get it to write to memory, or do anything else you'd like 1182 with the output. For more info, see 1183 http://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html 1184 */ 1185 1186 struct MemoryStruct { 1187 char *memory; 1188 size_t size; 1189 }; 1190 1191 static size_t 1192 WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) 1193 { 1194 size_t realsize = size * nmemb; 1195 struct MemoryStruct *mem = (struct MemoryStruct *)userp; 1196 1197 mem->memory = realloc(mem->memory, mem->size + realsize + 1); 1198 if(mem->memory == NULL) { 1199 /* out of memory! */ 1200 printf("not enough memory (realloc returned NULL)\n"); 1201 return 0; 1202 } 1203 1204 memcpy(&(mem->memory[mem->size]), contents, realsize); 1205 mem->size += realsize; 1206 mem->memory[mem->size] = 0; 1207 1208 return realsize; 1209 } 1210 1211 static size_t writeCallback(void *contents, size_t size, size_t nitems, FILE *file) { 1212 return fwrite(contents, size, nitems, file); 1213 } 1214 1215 // flag = 0 (without header in output) 1216 // flag = 1 (with header in output) 1217 char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, char* referer, int flag) 1218 { 1219 debug(99, "url: %s", url); 1220 1221 int debuglevel = getconfigint("debuglevel", NULL); 1222 1223 char* tmpstr = NULL; 1224 FILE *fp; 1225 1226 CURL *curl_handle; 1227 CURLcode res; 1228 1229 struct MemoryStruct chunk; 1230 1231 chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ 1232 chunk.size = 0; /* no data at this point */ 1233 1234 curl_global_init(CURL_GLOBAL_ALL); 1235 1236 /* init the curl session */ 1237 curl_handle = curl_easy_init(); 1238 if(curl_handle) 1239 { 1240 if(localfile != NULL) 1241 fp = fopen(localfile,"wb"); 1242 1243 /* specify URL to get */ 1244 curl_easy_setopt(curl_handle, CURLOPT_URL, url); 1245 1246 if(user != NULL && pass != NULL) 1247 { 1248 curl_easy_setopt(curl_handle, CURLOPT_USERNAME, user); 1249 curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, pass); 1250 curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 1251 } 1252 if(data == NULL) 1253 curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1L); 1254 else 1255 { 1256 curl_easy_setopt(curl_handle, CURLOPT_POST, 1); 1257 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data); 1258 1259 /* example.com is redirected, so we tell libcurl to send POST on 301, 302 and 1260 303 HTTP response codes */ 1261 curl_easy_setopt(curl_handle, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); 1262 } 1263 if(flag == 1) 1264 curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1L); 1265 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 5); 1266 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 3); 1267 // curl_easy_setopt(curl_handle, CURLOPT_RETURNTRANSFER, 1); 1268 1269 if(localfile == NULL) 1270 { 1271 /* send all data to this function */ 1272 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); 1273 } 1274 else 1275 { 1276 /* When data arrives, curl will call writeCallback. */ 1277 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeCallback); 1278 } 1279 1280 1281 1282 if(localfile == NULL) 1283 { 1284 /* we pass our 'chunk' struct to the callback function */ 1285 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); 1286 } 1287 else 1288 { 1289 /* The last argument to writeCallback will be our file: */ 1290 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)fp); 1291 } 1292 1293 /* some servers don't like requests that are made without a user-agent field, so we provide one */ 1294 // curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); 1295 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.7.3000 Chrome/30.0.1599.101 Safari/537.36"); 1296 1297 // This is occassionally required to stop CURL from verifying the peers certificate. 1298 // CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if 1299 // CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a 1300 // common name and also verify that it matches the hostname provided) 1301 #ifdef MIPSEL 1302 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L); 1303 #else 1304 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); 1177 1305 #endif 1306 1307 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); 1308 if(debuglevel == 99) 1309 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1); 1310 curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "/mnt/network/cookies"); 1311 curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "/mnt/network/cookies"); 1312 /* enable redirect following */ 1313 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); 1314 /* allow three redirects */ 1315 curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L); 1316 1317 1318 /* enable all supported built-in compressions */ 1319 curl_easy_setopt(curl_handle, CURLOPT_ACCEPT_ENCODING, ""); 1320 1321 if(referer == NULL) 1322 curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1L); 1323 else 1324 curl_easy_setopt(curl_handle, CURLOPT_REFERER, referer); 1325 1326 1327 /* get it! */ 1328 res = curl_easy_perform(curl_handle); 1329 1330 /* check for errors */ 1331 if(res != CURLE_OK) 1332 { 1333 err("failed: %s", curl_easy_strerror(res)); 1334 printf("curl error\n"); 1335 } 1336 else 1337 { 1338 /* 1339 * Now, our chunk.memory points to a memory block that is chunk.size 1340 * bytes big and contains the remote file. 1341 * 1342 * Do something nice with it! 1343 */ 1344 printf("%lu bytes retrieved\n", (long)chunk.size); 1345 } 1346 1347 /* cleanup curl stuff */ 1348 curl_easy_cleanup(curl_handle); 1349 if(localfile != NULL) 1350 fclose(fp); 1351 } 1352 1353 if(localfile == NULL) 1354 tmpstr = ostrcat(chunk.memory, NULL, 0, 0); 1355 1356 free(chunk.memory); 1357 /* we're done with libcurl, so clean it up */ 1358 1359 curl_global_cleanup(); 1360 1361 if(localfile != NULL) 1362 free(tmpstr), tmpstr = NULL; 1363 1364 return tmpstr; 1365 } 1366 1367 int update_iptv(char* file) 1368 { 1369 char* tmpstr = NULL, *link = NULL; 1370 int ret = 0; 1371 1372 tmpstr = dirname(file); 1373 link = getconfig("iptvserver", NULL); 1374 1375 if(link != NULL) 1376 { 1377 debug(10, "update %s", link); 1378 1379 if(!file_exist(tmpstr)) 1380 mkdir(tmpstr, 0777); 1381 1382 tmpstr = ostrcat(tmpstr, "/iptv.m3u", 1, 0); 1383 if(file_exist(tmpstr)) 1384 unlink(tmpstr); 1385 1386 if(!file_exist(tmpstr)) 1387 gethttps(link, tmpstr, NULL, NULL, NULL, NULL, 0); 1388 1389 if(file_exist(tmpstr)) ret = 1; 1390 1391 } 1392 1393 free(tmpstr), tmpstr = NULL; 1394 free(link), link = NULL; 1395 1396 return ret; 1397 } 1398 1399 #endif -
titan/plugins/mc/mc_header.h
r40266 r44530 27 27 void screenmc_iptvplayer_settings(); 28 28 void mc_iptvplayer_infobar(struct skin* apskin, struct skin* infobar, struct skin* spos, struct skin* slen, struct skin* sreverse, struct skin* sprogress, struct skin* b12, struct skin* b13, char* filename); 29 char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, char* referer, int flag); 29 30 30 31 #endif -
titan/titan/global.h
r44303 r44530 8184 8184 } 8185 8185 8186 int update_iptv(char* file)8187 {8188 char* tmpstr = NULL, *link = NULL;8189 int ret = 0;8190 8191 tmpstr = dirname(file);8192 link = getconfig("iptvserver", NULL);8193 8194 if(link != NULL)8195 {8196 debug(10, "update %s", link);8197 8198 if(!file_exist(tmpstr))8199 mkdir(tmpstr, 0777);8200 8201 tmpstr = ostrcat(tmpstr, "/iptv.m3u", 1, 0);8202 if(file_exist(tmpstr))8203 unlink(tmpstr);8204 8205 if(!file_exist(tmpstr))8206 gethttps(link, tmpstr, NULL, NULL, NULL, NULL, 0);8207 8208 if(file_exist(tmpstr)) ret = 1;8209 8210 }8211 8212 free(tmpstr), tmpstr = NULL;8213 free(link), link = NULL;8214 8215 return ret;8216 }8217 8218 8186 #endif -
titan/titan/header.h
r44294 r44530 313 313 void gethttpstruct(struct stimerthread* timernode, struct download* node, int flag); 314 314 void gethttpstructmsg(struct stimerthread* timernode, struct download* node, int flag); 315 char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, char* referer, int flag);316 315 317 316 //numinput.h -
titan/titan/sock.h
r44294 r44530 1150 1150 } 1151 1151 1152 #include <stdio.h>1153 #include <curl/curl.h>1154 1155 struct MemoryStruct {1156 char *memory;1157 size_t size;1158 };1159 1160 static size_t1161 WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)1162 {1163 size_t realsize = size * nmemb;1164 struct MemoryStruct *mem = (struct MemoryStruct *)userp;1165 1166 mem->memory = realloc(mem->memory, mem->size + realsize + 1);1167 if(mem->memory == NULL) {1168 /* out of memory! */1169 printf("not enough memory (realloc returned NULL)\n");1170 return 0;1171 }1172 1173 memcpy(&(mem->memory[mem->size]), contents, realsize);1174 mem->size += realsize;1175 mem->memory[mem->size] = 0;1176 1177 return realsize;1178 }1179 1180 static size_t writeCallback(void *contents, size_t size, size_t nitems, FILE *file) {1181 return fwrite(contents, size, nitems, file);1182 }1183 1184 // flag = 0 (without header in output)1185 // flag = 1 (with header in output)1186 char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, char* referer, int flag)1187 {1188 debug(99, "url: %s", url);1189 1190 int debuglevel = getconfigint("debuglevel", NULL);1191 1192 char* tmpstr = NULL;1193 FILE *fp;1194 1195 CURL *curl_handle;1196 CURLcode res;1197 1198 struct MemoryStruct chunk;1199 1200 chunk.memory = malloc(1); /* will be grown as needed by the realloc above */1201 chunk.size = 0; /* no data at this point */1202 1203 curl_global_init(CURL_GLOBAL_ALL);1204 1205 /* init the curl session */1206 curl_handle = curl_easy_init();1207 if(curl_handle)1208 {1209 if(localfile != NULL)1210 fp = fopen(localfile,"wb");1211 1212 /* specify URL to get */1213 curl_easy_setopt(curl_handle, CURLOPT_URL, url);1214 1215 if(user != NULL && pass != NULL)1216 {1217 curl_easy_setopt(curl_handle, CURLOPT_USERNAME, user);1218 curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, pass);1219 curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);1220 }1221 if(data == NULL)1222 curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1L);1223 else1224 {1225 curl_easy_setopt(curl_handle, CURLOPT_POST, 1);1226 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);1227 1228 /* example.com is redirected, so we tell libcurl to send POST on 301, 302 and1229 303 HTTP response codes */1230 curl_easy_setopt(curl_handle, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);1231 }1232 if(flag == 1)1233 curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1L);1234 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 5);1235 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 3);1236 // curl_easy_setopt(curl_handle, CURLOPT_RETURNTRANSFER, 1);1237 1238 if(localfile == NULL)1239 {1240 /* send all data to this function */1241 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);1242 }1243 else1244 {1245 /* When data arrives, curl will call writeCallback. */1246 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeCallback);1247 }1248 1249 1250 1251 if(localfile == NULL)1252 {1253 /* we pass our 'chunk' struct to the callback function */1254 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);1255 }1256 else1257 {1258 /* The last argument to writeCallback will be our file: */1259 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)fp);1260 }1261 1262 /* some servers don't like requests that are made without a user-agent field, so we provide one */1263 // curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");1264 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Maxthon/4.4.7.3000 Chrome/30.0.1599.101 Safari/537.36");1265 1266 // This is occassionally required to stop CURL from verifying the peers certificate.1267 // CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if1268 // CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a1269 // common name and also verify that it matches the hostname provided)1270 #ifdef MIPSEL1271 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L);1272 #else1273 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);1274 1152 #endif 1275 1276 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);1277 if(debuglevel == 99)1278 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);1279 curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "/mnt/network/cookies");1280 curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "/mnt/network/cookies");1281 /* enable redirect following */1282 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);1283 /* allow three redirects */1284 curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 3L);1285 1286 1287 /* enable all supported built-in compressions */1288 curl_easy_setopt(curl_handle, CURLOPT_ACCEPT_ENCODING, "");1289 1290 if(referer == NULL)1291 curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1L);1292 else1293 curl_easy_setopt(curl_handle, CURLOPT_REFERER, referer);1294 1295 1296 /* get it! */1297 res = curl_easy_perform(curl_handle);1298 1299 /* check for errors */1300 if(res != CURLE_OK)1301 {1302 err("failed: %s", curl_easy_strerror(res));1303 printf("curl error\n");1304 }1305 else1306 {1307 /*1308 * Now, our chunk.memory points to a memory block that is chunk.size1309 * bytes big and contains the remote file.1310 *1311 * Do something nice with it!1312 */1313 printf("%lu bytes retrieved\n", (long)chunk.size);1314 }1315 1316 /* cleanup curl stuff */1317 curl_easy_cleanup(curl_handle);1318 if(localfile != NULL)1319 fclose(fp);1320 }1321 1322 if(localfile == NULL)1323 tmpstr = ostrcat(chunk.memory, NULL, 0, 0);1324 1325 free(chunk.memory);1326 /* we're done with libcurl, so clean it up */1327 1328 curl_global_cleanup();1329 1330 if(localfile != NULL)1331 free(tmpstr), tmpstr = NULL;1332 1333 return tmpstr;1334 }1335 1336 #endif
Note: See TracChangeset
for help on using the changeset viewer.