Rev 4364 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4364 | Rev 4821 | ||
---|---|---|---|
Line 285... | Line 285... | ||
285 | 285 | ||
286 | static inline bool fetch_curl_send_callback(const fetch_msg *msg, |
286 | static inline bool fetch_curl_send_callback(const fetch_msg *msg, |
287 | struct fetch_curl_context *ctx) |
287 | struct fetch_curl_context *ctx) |
288 | { |
288 | { |
- | 289 | ctx->locked = true; |
|
- | 290 | __menuet__debug_out("Inside curl_send_cb, Calling send_cb()\n"); |
|
289 | ctx->locked = true; |
291 | |
290 | fetch_send_callback(msg, ctx->fetchh); |
292 | fetch_send_callback(msg, ctx->fetchh); |
- | 293 | ctx->locked = false; |
|
Line 291... | Line 294... | ||
291 | ctx->locked = false; |
294 | __menuet__debug_out("Returning ctx->aborted.\n"); |
292 | 295 | ||
Line 293... | Line 296... | ||
293 | return ctx->aborted; |
296 | return ctx->aborted; |
294 | } |
297 | } |
295 | 298 | ||
296 | static bool fetch_curl_send_header(struct fetch_curl_context *ctx, |
299 | static bool fetch_curl_send_header(struct fetch_curl_context *ctx, |
297 | const char *fmt, ...) |
300 | const char *fmt, ...) |
298 | { |
301 | { |
299 | fetch_msg msg; |
- | |
- | 302 | fetch_msg msg; |
|
300 | char header[64]; |
303 | char header[64]; |
Line 301... | Line 304... | ||
301 | va_list ap; |
304 | va_list ap; |
Line 302... | Line 305... | ||
302 | 305 | __menuet__debug_out("Inside fetch_curl_send_header\n"); |
|
- | 306 | va_start(ap, fmt); |
|
- | 307 | ||
Line 303... | Line 308... | ||
303 | va_start(ap, fmt); |
308 | vsnprintf(header, sizeof header, fmt, ap); |
304 | 309 | ||
305 | vsnprintf(header, sizeof header, fmt, ap); |
310 | va_end(ap); |
- | 311 | __menuet__debug_out("Header is : "); |
|
- | 312 | __menuet__debug_out(header); |
|
306 | 313 | ||
Line -... | Line 314... | ||
- | 314 | msg.type = FETCH_HEADER; |
|
307 | va_end(ap); |
315 | msg.data.header_or_data.buf = (const uint8_t *) header; |
308 | 316 | msg.data.header_or_data.len = strlen(header); |
|
Line 309... | Line 317... | ||
309 | msg.type = FETCH_HEADER; |
317 | __menuet__debug_out("\nCalling fetch_curl_send_callback\n"); |
310 | msg.data.header_or_data.buf = (const uint8_t *) header; |
318 | |
Line 348... | Line 356... | ||
348 | fetch_file_process_error_aborted: |
356 | fetch_file_process_error_aborted: |
349 | return; |
357 | return; |
350 | } |
358 | } |
Line 351... | Line -... | ||
351 | - | ||
352 | - | ||
353 | int is_pid(int k) |
- | |
354 | { |
- | |
355 | int error; |
- | |
356 | asm volatile ("int $0x40":"=a"(error):"a"(18), "b"(21), "c"(k)); |
- | |
357 | return error; |
- | |
358 | } |
- | |
359 | - | ||
360 | - | ||
361 | int kill_pid(int k) |
- | |
362 | { |
- | |
363 | int error; |
- | |
364 | asm volatile ("int $0x40":"=a"(error):"a"(18), "b"(18), "c"(k)); |
- | |
365 | return error; |
- | |
366 | } |
- | |
367 | 359 | ||
368 | 360 | ||
369 | static void fetch_curl_process(struct fetch_curl_context *ctx) { |
361 | static void fetch_curl_process(struct fetch_curl_context *ctx) { |
370 | char ps[96], str[128]; |
362 | char ps[96], str[128]; |
Line 371... | Line 363... | ||
371 | sprintf(ps, "Yay! Path is %s", ctx->path); |
363 | sprintf(ps, "Yay! Path is %s", ctx->path); |
Line 372... | Line -... | ||
372 | execl ("/sys/@notify", ps, 0); |
- | |
373 | - | ||
374 | fetch_msg msg; |
- | |
375 | - | ||
376 | /* ERSATZ DOWNLOADER */ |
- | |
377 | - | ||
378 | /* |
- | |
379 | char zapzap[]=" |
- | |
380 | size_t file_size=strlen(zapzap); |
- | |
381 | char *buffer = (char*)malloc(file_size * sizeof(char)); |
- | |
382 | memcpy(buffer, zapzap, file_size * sizeof(char)); |
- | |
383 | */ |
- | |
384 | - | ||
385 | 364 | execl ("/sys/@notify", ps, 0); |
|
386 | 365 | ||
Line 387... | Line 366... | ||
387 | 366 | fetch_msg msg; |
|
388 | 367 | ||
389 | __menuet__debug_out("AHOY!\n"); |
368 | __menuet__debug_out("AHOY!\n"); |
390 | struct http_msg *http_ahoy; |
369 | struct http_msg *http_ahoy; |
391 | 370 | ||
392 | unsigned int wererat = 0; |
- | |
393 | char * pa=ctx->path; |
- | |
394 | asm volatile ("pusha"); |
371 | unsigned int wererat = 0; |
395 | wererat = http_get(pa); |
372 | char * pa=ctx->path; |
396 | asm volatile ("popa"); |
- | |
397 | __menuet__debug_out("HTTP GOT!\n"); |
373 | // asm volatile ("pusha"); // TODO: verify if this is still needed. It used to be an issue with the library but should be fixed now. |
- | 374 | wererat = http_get(pa, NULL); // TODO: a pointer to additional headers (for cookies etc) can be placed here in the future. |
|
398 | int result; |
375 | // asm volatile ("popa"); // .... |
Line 399... | Line -... | ||
399 | - | ||
400 | http_ahoy=wererat; |
376 | |
401 | 377 | if(wererat == 0) /* Error condition : http_get returned 0 */ |
|
402 | sprintf (str, "Header %d bytes, content %d bytes, recieved %d bytes\n", http_ahoy->header_length, http_ahoy->content_length, http_ahoy->content_received); |
378 | __menuet__debug_out("http_get() failed. [ Return Value 0 ]\n"); |
403 | __menuet__debug_out(str); |
379 | else |
404 | - | ||
405 | asm volatile ("pusha"); |
- | |
406 | result = http_process(wererat); |
- | |
Line 407... | Line 380... | ||
407 | asm volatile ("popa"); |
380 | __menuet__debug_out("http_get() Succeeded!. [ Return Value Non zero ]\n"); |
Line 408... | Line 381... | ||
408 | while (result == -1) { |
381 | |
409 | asm volatile ("pusha"); |
382 | __menuet__debug_out("HTTP GOT!\n"); |
Line -... | Line 383... | ||
- | 383 | int result = 1337; |
|
Line -... | Line 384... | ||
- | 384 | char result_str[12]; |
|
- | 385 | char wererat_str[13]; |
|
410 | result = http_process(wererat); |
386 | |
- | 387 | http_ahoy = wererat; |
|
- | 388 | ||
Line 411... | Line -... | ||
411 | asm volatile ("popa"); |
- | |
412 | } |
- | |
413 | 389 | sprintf (str, "Header %u bytes, content %u bytes, received %u bytes\n", http_ahoy->header_length, http_ahoy->content_length, http_ahoy->content_received); |
|
414 | http_ahoy=wererat; |
- | |
415 | 390 | __menuet__debug_out(str); |
|
416 | sprintf (str, "Header %d bytes, content %d bytes, recieved %d bytes\n", http_ahoy->header_length, http_ahoy->content_length, http_ahoy->content_received); |
391 | |
417 | __menuet__debug_out(str); |
- | |
418 | 392 | __menuet__debug_out("Going into the do while loop for http_process\n"); |
|
419 | - | ||
Line -... | Line 393... | ||
- | 393 | ||
Line 420... | Line -... | ||
420 | __menuet__debug_out("All content is here\n"); |
- | |
421 | 394 | do { |
|
422 | size_t file_size=http_ahoy->content_received; |
395 | // sprintf(result_str, "%d", result); |
- | 396 | // __menuet__debug_out("Result is : "); |
|
423 | char *buffer = (char*)malloc(file_size * sizeof(char)); |
397 | // __menuet__debug_out(result_str); |
Line -... | Line 398... | ||
- | 398 | // __menuet__debug_out("\n"); |
|
- | 399 | ||
- | 400 | // asm volatile ("pusha"); // TODO: verify if this is still needed. It used to be an issue with the library but should be fixed now. |
|
Line 424... | Line 401... | ||
424 | memcpy(buffer, &(http_ahoy->data)+http_ahoy->header_length, file_size); |
401 | result = http_process(wererat); |
- | 402 | // asm volatile ("popa"); // .... |
|
425 | 403 | } while ((result != 0)); |
|
- | 404 | ||
Line 426... | Line 405... | ||
426 | // http_free(wererat); |
405 | __menuet__debug_out("After the do while loop for http_process.\n"); |
427 | __menuet__debug_out("memcopied\n==\n"); |
406 | |
428 | 407 | if(result == 0) |
|
429 | //__menuet__debug_out(buffer); |
408 | __menuet__debug_out("http_process() worked successfully!\n"); |
Line 430... | Line -... | ||
430 | //__menuet__debug_out("memcopied\n==\n"); |
- | |
- | 409 | else |
|
431 | 410 | __menuet__debug_out("http_process() failed!\n"); |
|
432 | 411 | ||
433 | //char zapzap[]=" |
412 | // http_ahoy = wererat; // really needed again?? |
Line 434... | Line 413... | ||
434 | //file_size=strlen(zapzap); |
413 | sprintf (str, "Header %u bytes, content %u bytes, received %u bytes\n", http_ahoy->header_length, http_ahoy->content_length, http_ahoy->content_received); |
435 | //char *buffer = (char*)malloc(file_size * sizeof(char)); |
- | |
- | 414 | __menuet__debug_out(str); |
|
436 | //memcpy(buffer, zapzap, file_size * sizeof(char)); |
415 | |
- | 416 | /* fetch is going to be successful */ |
|
437 | 417 | __menuet__debug_out("Calling fetch_set_http_code call\n"); |
|
- | 418 | fetch_set_http_code(ctx->fetchh, http_ahoy->status); |
|
438 | 419 | __menuet__debug_out("Returned from fetch_set_http_code call\n"); |
|
- | 420 | ||
439 | /* fetch is going to be successful */ |
421 | /* Any callback can result in the fetch being aborted. |
Line -... | Line 422... | ||
- | 422 | * Therefore, we _must_ check for this after _every_ call to |
|
- | 423 | * fetch_file_send_callback(). |
|
- | 424 | */ |
|
- | 425 | ||
Line -... | Line 426... | ||
- | 426 | __menuet__debug_out("Calling fetch_curl_send_header: 1\n"); |
|
Line 440... | Line 427... | ||
440 | fetch_set_http_code(ctx->fetchh, 200); |
427 | if (fetch_curl_send_header(ctx, "Content-Type: %s", |
- | 428 | fetch_filetype(ctx->path))) |
|
441 | 429 | goto fetch_file_process_aborted; |
|
- | 430 | ||
442 | /* Any callback can result in the fetch being aborted. |
431 | |
- | 432 | /* main data loop */ |
|
443 | * Therefore, we _must_ check for this after _every_ call to |
433 | __menuet__debug_out("inside main data loop\n"); |
Line 444... | Line 434... | ||
444 | * fetch_file_send_callback(). |
434 | msg.type = FETCH_DATA; |
- | 435 | ||
445 | */ |
436 | msg.data.header_or_data.buf = http_ahoy->content_ptr; // lets pray this works..x2 |
Line 446... | Line 437... | ||
446 | 437 | ||
Line 447... | Line -... | ||
447 | - | ||
448 | if (fetch_curl_send_header(ctx, "Content-Type: %s", |
438 | msg.data.header_or_data.len = http_ahoy->content_received; |
449 | fetch_filetype(ctx->path))) |
439 | __menuet__debug_out("Calling fetch_curl_send_callback\n"); |
450 | goto fetch_file_process_aborted; |
440 | fetch_curl_send_callback(&msg, ctx); |
451 | 441 | ||
452 | 442 | __menuet__debug_out("Calling http_free with wererat = "); |