Rev 3616 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3616 | Rev 3620 | ||
---|---|---|---|
Line 214... | Line 214... | ||
214 | 214 | ||
215 | ctx = calloc(1, sizeof(*ctx)); |
215 | ctx = calloc(1, sizeof(*ctx)); |
216 | if (ctx == NULL) |
216 | if (ctx == NULL) |
Line 217... | Line 217... | ||
217 | return NULL; |
217 | return NULL; |
- | 218 | ||
- | 219 | //ctx->path = url_to_path(nsurl_access(url)); |
|
- | 220 | char *zz; |
|
- | 221 | int pr; |
|
- | 222 | nsurl_get(url, NSURL_WITH_FRAGMENT, &zz, &pr); |
|
218 | 223 | ||
219 | ctx->path = url_to_path(nsurl_access(url)); |
224 | ctx->path = zz; |
220 | if (ctx->path == NULL) { |
225 | if (ctx->path == NULL) { |
221 | free(ctx); |
226 | free(ctx); |
Line 341... | Line 346... | ||
341 | fetch_file_process_error_aborted: |
346 | fetch_file_process_error_aborted: |
342 | return; |
347 | return; |
343 | } |
348 | } |
Line -... | Line 349... | ||
- | 349 | ||
- | 350 | ||
- | 351 | int is_pid(int k) |
|
- | 352 | { |
|
- | 353 | int error; |
|
- | 354 | asm volatile ("int $0x40":"=a"(error):"a"(18), "b"(21), "c"(k)); |
|
- | 355 | return error; |
|
- | 356 | } |
|
- | 357 | ||
- | 358 | ||
- | 359 | int kill_pid(int k) |
|
- | 360 | { |
|
- | 361 | int error; |
|
- | 362 | asm volatile ("int $0x40":"=a"(error):"a"(18), "b"(18), "c"(k)); |
|
- | 363 | return error; |
|
344 | 364 | } |
|
Line -... | Line 365... | ||
- | 365 | ||
- | 366 | static void fetch_curl_process(struct fetch_curl_context *ctx) { |
|
- | 367 | ||
- | 368 | int pid=execl ("/sys/network/downloader", ctx->path, 0); |
|
- | 369 | ||
- | 370 | ||
- | 371 | ||
- | 372 | // while (is_pid(pid)) { |
|
- | 373 | kill_pid(pid); |
|
- | 374 | // } |
|
- | 375 | ||
- | 376 | pid=execl ("/sys/network/downloader", ctx->path, 0); |
|
- | 377 | ||
- | 378 | char ps[255]; |
|
- | 379 | sprintf(ps, "pid %d", pid); |
|
- | 380 | execl ("/sys/network/@notify", ps, 0); |
|
- | 381 | ||
- | 382 | ||
- | 383 | while (is_pid(pid)); |
|
- | 384 | ||
- | 385 | ||
- | 386 | sprintf(ps, "Yay! Finished"); |
|
- | 387 | execl ("/sys/network/@notify", ps, 0); |
|
- | 388 | ||
- | 389 | ||
- | 390 | /* |
|
- | 391 | char pzz[255]; |
|
- | 392 | sprintf(pzz, "Pid is %d", pid); |
|
- | 393 | execl ("/sys/@notify", pzz, 0); */ |
|
- | 394 | //int status; |
|
345 | 395 | //waitpid(pid, &status, 0); |
|
346 | static void fetch_curl_process(struct fetch_curl_context *ctx) { |
396 | |
- | 397 | ||
- | 398 | fetch_msg msg; |
|
- | 399 | //const char * buf = " |
|
- | 400 | ||
- | 401 | FILE *infile; |
|
347 | 402 | infile = fopen("/sys/.download", "rb"); |
|
- | 403 | ||
- | 404 | if (infile == NULL) { |
|
- | 405 | printf("file does not exist.\n"); |
|
- | 406 | return -1; |
|
- | 407 | } |
|
- | 408 | ||
- | 409 | fseek(infile, 0, SEEK_END); |
|
- | 410 | size_t file_size = ftell(infile); |
|
- | 411 | rewind(infile); |
|
- | 412 | ||
- | 413 | char *buffer = (char*)malloc(file_size * sizeof(char)); |
|
- | 414 | if (buffer == NULL) { |
|
- | 415 | fclose(infile); |
|
- | 416 | printf("Error allocating %d bytes.\n", file_size * sizeof(char)); |
|
- | 417 | return -1; |
|
- | 418 | } |
|
- | 419 | size_t bytes_read = fread(buffer, sizeof(char), file_size, infile); |
|
- | 420 | if (bytes_read != file_size) { |
|
348 | fetch_msg msg; |
421 | printf("Have read only %d bytes of %d.\n", bytes_read, file_size); |
- | 422 | free(buffer); |
|
- | 423 | fclose(infile); |
|
- | 424 | return -1; |
|
- | 425 | } |
|
- | 426 | fclose(infile); |
|
Line 349... | Line 427... | ||
349 | const char * buf = " |
427 | |
350 | // fetch_curl_process_error(ctx, 501); |
428 | |
Line 351... | Line 429... | ||
351 | // return; |
429 | |
Line 364... | Line 442... | ||
364 | 442 | ||
Line 365... | Line 443... | ||
365 | 443 | ||
366 | /* main data loop */ |
444 | /* main data loop */ |
367 | 445 | ||
368 | msg.type = FETCH_DATA; |
446 | msg.type = FETCH_DATA; |
Line 369... | Line 447... | ||
369 | msg.data.header_or_data.buf = (const uint8_t *) buf; |
447 | msg.data.header_or_data.buf = (const uint8_t *) buffer; |