Subversion Repositories Kolibri OS

Rev

Rev 3624 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3624 Rev 4224
Line 26... Line 26...
26
 *
26
 *
27
 * The CURL handles are cached in the curl_handle_ring. There are at most
27
 * The CURL handles are cached in the curl_handle_ring. There are at most
28
 * ::max_cached_fetch_handles in this ring.
28
 * ::max_cached_fetch_handles in this ring.
29
 */
29
 */
Line -... Line 30...
-
 
30
 
-
 
31
 
-
 
32
#include "http.c"
30
 
33
 
31
#include 
34
#include 
32
#include 
35
#include 
33
#include 
36
#include 
34
#include 
37
#include 
Line 153... Line 156...
153
 * Initialise a cURL fetcher.
156
 * Initialise a cURL fetcher.
154
 */
157
 */
Line 155... Line 158...
155
 
158
 
156
bool fetch_curl_initialise(lwc_string *scheme)
159
bool fetch_curl_initialise(lwc_string *scheme)
157
{
-
 
158
 
160
{
159
LOG(("curl initi lwc\n"));
161
LOG(("curl initi lwc\n"));
160
	return true; /* Always succeeds */
162
	return true; /* Always succeeds */
Line 361... Line 363...
361
	int error;
363
	int error;
362
asm volatile ("int $0x40":"=a"(error):"a"(18), "b"(18), "c"(k));
364
asm volatile ("int $0x40":"=a"(error):"a"(18), "b"(18), "c"(k));
363
return error;
365
return error;
364
}
366
}
Line -... Line 367...
-
 
367
 
365
 
368
 
-
 
369
static void fetch_curl_process(struct fetch_curl_context *ctx) {
-
 
370
	char ps[96], str[128];
-
 
371
	sprintf(ps, "Yay! Path is %s", ctx->path);
Line 366... Line 372...
366
static void fetch_curl_process(struct fetch_curl_context *ctx) {
372
	execl ("/sys/@notify", ps, 0);
Line -... Line 373...
-
 
373
	
Line -... Line 374...
-
 
374
	fetch_msg msg;
-
 
375
 
-
 
376
 /* ERSATZ DOWNLOADER */
-
 
377
 
-
 
378
 /*
-
 
379
char zapzap[]="

HOOLE!

";
Line 367... Line -...
367
	
-
 
368
	int pid=execl ("/sys/network/downloader", ctx->path, 0);
-
 
369
	
-
 
Line 370... Line -...
370
	
-
 
Line 371... Line -...
371
	
-
 
372
//	while (is_pid(pid)) {
-
 
373
	kill_pid(pid);
-
 
Line -... Line 380...
-
 
380
size_t file_size=strlen(zapzap);
374
//	}
381
char *buffer = (char*)malloc(file_size * sizeof(char));
Line -... Line 382...
-
 
382
memcpy(buffer, zapzap, file_size * sizeof(char));
-
 
383
*/
-
 
384
 
-
 
385
 
-
 
386
  
-
 
387
 
-
 
388
 
Line 375... Line 389...
375
	
389
    __menuet__debug_out("AHOY!\n");
376
	pid=execl ("/sys/network/downloader", ctx->path, 0);
-
 
Line -... Line 390...
-
 
390
	struct http_msg *http_ahoy;
-
 
391
 
Line 377... Line -...
377
	
-
 
378
	char ps[255];
392
	unsigned int wererat = 0;
379
	sprintf(ps, "pid %d", pid);
393
    char * pa=ctx->path;
380
	execl ("/sys/network/@notify", ps, 0);
394
    asm volatile ("pusha");
-
 
395
    wererat = http_get(pa);
381
	
396
	asm volatile ("popa");
-
 
397
	__menuet__debug_out("HTTP GOT!\n");
382
	
398
	int result;
383
	while (is_pid(pid));
399
 
Line 384... Line 400...
384
	
400
    http_ahoy=wererat;
385
	
-
 
Line 386... Line -...
386
	sprintf(ps, "Yay! Finished");
-
 
-
 
401
 
387
	execl ("/sys/network/@notify", ps, 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);
Line 388... Line -...
388
	
-
 
389
	
-
 
390
	/*
-
 
391
	char pzz[255];
-
 
Line 392... Line -...
392
	sprintf(pzz, "Pid is %d", pid);
-
 
393
	execl ("/sys/@notify", pzz, 0); */
403
    __menuet__debug_out(str);
394
	//int status;
-
 
Line -... Line 404...
-
 
404
 
395
	//waitpid(pid, &status, 0); 
405
    asm volatile ("pusha");
396
	
-
 
397
	
-
 
398
	fetch_msg msg;
406
    result = http_process(wererat);
399
	//const char * buf = "

Hello, file fetcher!

";
-
 
400
 
407
    asm volatile ("popa");
401
 FILE *infile;
-
 
402
  infile = fopen("/sys/.download", "rb");
-
 
403
 
-
 
404
  if (infile == NULL) {
408
    while (result == -1)  {
405
    printf("file does not exist.\n");
409
		asm volatile ("pusha");
406
    return -1;
-
 
407
  }
-
 
408
 
-
 
Line -... Line 410...
-
 
410
		result = http_process(wererat);
-
 
411
		asm volatile ("popa");
Line -... Line 412...
-
 
412
	}
-
 
413
 
-
 
414
    http_ahoy=wererat;
-
 
415
    
-
 
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);
Line 409... Line 417...
409
  fseek(infile, 0, SEEK_END);
417
    __menuet__debug_out(str);
410
  size_t file_size = ftell(infile);
418
 
Line 411... Line 419...
411
  rewind(infile);
419
    
412
 
420
    __menuet__debug_out("All content is here\n");
413
  char *buffer = (char*)malloc(file_size * sizeof(char));
421
    
414
  if (buffer == NULL) {
422
	size_t file_size=http_ahoy->content_received;
Line 415... Line -...
415
    fclose(infile);
-
 
416
    printf("Error allocating %d bytes.\n", file_size * sizeof(char));
-
 
Line 417... Line 423...
417
    return -1;
423
	char *buffer = (char*)malloc(file_size * sizeof(char));
418
  }
424
	memcpy(buffer, &(http_ahoy->data)+http_ahoy->header_length, file_size);
419
  size_t bytes_read = fread(buffer, sizeof(char), file_size, infile);
425
 
Line 420... Line 426...
420
  if (bytes_read != file_size) {
426
	// http_free(wererat);
Line 421... Line 427...
421
    printf("Have read only %d bytes of %d.\n", bytes_read, file_size);
427
    __menuet__debug_out("memcopied\n==\n");
422
    free(buffer);
428
 
423
    fclose(infile);
429
	//__menuet__debug_out(buffer);
424
    return -1;
430
	//__menuet__debug_out("memcopied\n==\n");