sscanf problems, not the user the function July 14, 2009 09:50PM | Registered: 15 years ago Posts: 405 |
sscanf (line, "Location: %s", read)
char *line = tcp_readln (s, 0xff, gettime(), HTTP_TIMEOUT);
Re: sscanf problems, not the user the function July 14, 2009 10:57PM | Registered: 15 years ago Posts: 97 |
Re: sscanf problems, not the user the function July 16, 2009 09:59PM | Registered: 15 years ago Posts: 405 |
Re: sscanf problems, not the user the function July 17, 2009 05:53AM | Registered: 15 years ago Posts: 97 |
Quote
SteelSLasher
btw, strcpy, strncpy and any other function does not work in the place i was going to but instead i transfer the second line to another variable which is later used to be processed.
my sscanf is completely fine
sprintf(read,"Location: %s",line);
Re: sscanf problems, not the user the function July 17, 2009 08:32AM | Registered: 15 years ago Posts: 276 |
Re: sscanf problems, not the user the function July 17, 2009 11:22AM | Registered: 15 years ago Posts: 405 |
for (linecount=0; linecount < 32; linecount++) { Debugs("tcp_readIn"); char *line = tcp_readln (s, 0xff, gettime(), HTTP_TIMEOUT); // debug_printf("tcp_readln returned %p (%s)\n", line, line?line:"(null)"); if (!line) { http_status = 404; result = HTTPR_ERR_REQUEST; break; } if (strlen (line) < 1) { free (line); line = NULL; break; } Debugs("sscanf"); sscanf (line, "HTTP/1.%*u %u", &http_status); sscanf (line, "Content-Length: %u", &content_length); Debugs("error"); //sscanf (line, "Location: %s", read); if(linecount == 1) { redirect = line; //set the second line of the response which contains the redirect location to redirect for processing later (workaround that fails since the sscanf fails later as well Debugs(redirect); } free (line); line = NULL; }
int http_request (const char *url, const u32 max_size) { int linecount; Debugs("Split"); if (!http_split_url(&http_host, &http_path, url)) return false; http_port = 80; http_max_size = max_size; http_status = 404; content_length = 0; http_data = NULL; Debugs("tcp_connect"); int s = tcp_connect (http_host, http_port); // debug_printf("tcp_connect(%s, %hu) = %d\n", http_host, http_port, s); if (s < 0) { result = HTTPR_ERR_CONNECT; Debugs("s is less than 0???"); return false; } char *request = (char *) malloc (1024); char *r = request; r += sprintf (r, "GET %s HTTP/1.1\r\n", http_path); r += sprintf (r, "Host: %s\r\n", http_host); r += sprintf (r, "Cache-Control: no-cache\r\n\r\n"); Debugs(r); // debug_printf("request = %s\n", request); Debugs("tcp_write"); bool b = tcp_write (s, (u8 *) request, strlen (request)); // debug_printf("tcp_write returned %d\n", b); free (request); linecount = 0; Debugs("linecount"); for (linecount=0; linecount < 32; linecount++) { Debugs("tcp_readIn"); char *line = tcp_readln (s, 0xff, gettime(), HTTP_TIMEOUT); // debug_printf("tcp_readln returned %p (%s)\n", line, line?line:"(null)"); if (!line) { http_status = 404; result = HTTPR_ERR_REQUEST; break; } if (strlen (line) < 1) { free (line); line = NULL; break; } Debugs("sscanf"); sscanf (line, "HTTP/1.%*u %u", &http_status); sscanf (line, "Content-Length: %u", &content_length); Debugs("error"); //sscanf (line, "Location: %s", read); if(linecount == 1) { redirect = line; Debugs(redirect); } free (line); line = NULL; } Debugs(redirect); // debug_printf("content_length = %d, status = %d, linecount = %d\n", content_length, http_status, linecount); if (linecount == 32 || !content_length) http_status = 404; char*read = NULL; Debugs("If this is the last debug message please don't bother"); if(redirect != NULL) { Debugs("redirect"); char * pos = strchr ( redirect, 'Location: '); strcpy(read, pos); redirect = read; Debugs(redirect); if(sscanf(redirect, "http://%*s")) { Debugs("http1"); result = HTTPR_ERR_MOVED; report = redirect; Debugs("http"); return HTTPR_ERR_MOVED; } if(strchr ( redirect, '/') == 1) { Debugs("path"); result = HTTPR_ERR_MOVED; sprintf(report, "http://%s%s", http_path, redirect); return HTTPR_ERR_MOVED; } } /* if (399 > http_status < 200) { result = HTTPR_ERR_STATUS; net_close (s); return false; }*/ if (content_length > http_max_size) { result = HTTPR_ERR_TOOBIG; net_close (s); return false; } http_data = (u8 *) malloc (content_length); Debugs("tcp_read"); b = tcp_read (s, &http_data, content_length); if (!b) { free (http_data); http_data = NULL; result = HTTPR_ERR_RECEIVE; net_close (s); return false; } result = HTTPR_OK; net_close (s); Debugs("request complete"); return true; }
Re: sscanf problems, not the user the function July 17, 2009 05:43PM | Registered: 15 years ago Posts: 276 |
char*read = NULL; char * pos = strchr ( redirect, 'Location: '); strcpy(read, pos);
if(linecount == 1) { redirect = line; Debugs(redirect); } free (line); line = NULL;
Re: sscanf problems, not the user the function July 17, 2009 08:10PM | Registered: 15 years ago Posts: 405 |
Re: sscanf problems, not the user the function July 17, 2009 09:44PM | Registered: 15 years ago Posts: 405 |