Me revoilà

J'ai essayé de refaire fonctionner le programme avec la nouvelle version publiée récemment, et cela ne fonctionne pas, la calculatrice crash toujours
Avec des étapes longues de débug, j'ai réussi à isoler le morceau qui réalise le crash, mais la calculatrice ne reçoit aucune données malgré ça.
Voici ce que j'ai modifié :
http.c
- Code: Select all
web_status_t http_request(const char *request_type, const char* url, http_data_t **data, bool keep_http_header,
char *params, bool is_https) {
/* Ignoring http:// or https:// */
const char *https_str = "https://";
const char *http_str = "http://";
if(is_https && strncmp(url, https_str, strlen(https_str)) == 0) {
url += 8;
} else if(!is_https && strncmp(url, http_str, strlen(http_str)) == 0) {
url += 7;
}
printf("HTTP %s %s\n", request_type, url);
while(!os_GetCSC()) {}
bool is_ip = true;
size_t websitelen = 0;
while(url[websitelen] != '/' && url[websitelen] != 0x00) {
is_ip &= url[websitelen] < 'A';
websitelen++;
}
printf("Websitelen %d\n", websitelen);
while(!os_GetCSC()) {}
bool has_path = url[websitelen] == '/'; /* '/' or 0x00 ? */
/* Formatting website name */
char websitename[websitelen + 1];
memcpy(websitename, url, websitelen);
websitename[websitelen] = 0x00;
printf("Websitename %s\n", websitename);
while(!os_GetCSC()) {}
uint32_t ip;
if(!is_ip) {
ip = web_SendDNSRequest(websitename);
} else {
ip = ip_ascii_to_hex(websitename);
}
printf("IP %x\n", (unsigned int)ip);
while(!os_GetCSC()) {}
if(ip == 0xffffffff) {
return WEB_DNS_ERROR;
}
/* Configuring request information */
http_exchange_t *http_exch = _malloc(sizeof(http_exchange_t), "httpx");
if(http_exch == NULL) {
return WEB_NOT_ENOUGH_MEM;
}
printf("Allocating %d bytes\n", sizeof(http_exchange_t));
while(!os_GetCSC()) {}
memset(http_exch, 0, sizeof(http_exchange_t));
http_exch->buffer_size = 536; /* Starting size, will be resized later */
http_exch->data = data;
http_exch->buffer = _malloc(http_exch->buffer_size, "httpb");
if(http_exch->buffer == NULL) {
_free(http_exch);
return WEB_NOT_ENOUGH_MEM;
}
printf("Allocating %d bytes\n", http_exch->buffer_size);
while(!os_GetCSC()) {}
http_exch->keep_http_header = keep_http_header;
http_exch->timeout = false;
http_exch->dirty = false;
void *exchange; /* Opaque type depending on the underlying protocol used to send data (TCP or TLS) */
if(is_https) {
exchange = web_TLSConnect(ip, HTTPS_PORT, websitename, fetch_http_msg, http_exch);
} else {
exchange = web_TCPConnect(ip, HTTP_PORT, fetch_http_msg, http_exch);
}
printf("Exchange %p\n", exchange);
while(!os_GetCSC()) {}
if(exchange == NULL) {
_free(http_exch->buffer);
_free(http_exch);
return WEB_ERROR_FAILED;
}
web_status_t ret_val = delay_event(TIMEOUT_HTTP * 1000, boolean_scheduler, boolean_destructor, &http_exch->timeout);
printf("Ret_val %d\n", ret_val);
while(!os_GetCSC()) {}
if(ret_val != WEB_SUCCESS) {
if(is_https) {
web_TLSClose(exchange, true);
} else {
web_TCPClose(exchange, true);
}
_free(http_exch->buffer);
_free(http_exch);
return ret_val;
}
/* Building HTTP request */
uint24_t length = (strlen(BASIC_HTTP_REQUEST) - (4 * 2) /* 4 '%s' options */ + strlen(request_type) +
!has_path /* if no path, add 1 for '/' char */ + strlen(url) + strlen(params));
char request[length + 1];
snprintf(request, length + 1, BASIC_HTTP_REQUEST, request_type, has_path ? &url[websitelen] : "/", websitename, params);
printf("Request %s\n", request);
while(!os_GetCSC()) {}
/* Sending HTTP request */
if(is_https) {
ret_val = web_DeliverTLSData(exchange, request, length);
} else {
ret_val = web_DeliverTCPSegment(exchange, request, length);
}
printf("Delivering data %d\n", ret_val);
while(!os_GetCSC()) {}
/*if(ret_val != WEB_SUCCESS) {
http_exch->dirty = true;
http_exch->status = ret_val;
}*/
/* Waiting for the end of the request */
/*while(!http_exch->dirty) {
web_WaitForEvents();
if(http_exch->timeout) {
http_exch->dirty = true;
http_exch->status = WEB_TIMEOUT;
dbg_err("HTTP Timeout");
}
}*/
printf("Request finished\n");
while(!os_GetCSC()) {}
remove_event(&http_exch->timeout);
printf("Event removed\n");
while(!os_GetCSC()) {}
const web_status_t ret_status = http_exch->status;
const bool is_succeeded = ret_status >= 100; /* 100 = minimum HTTP status code, below this is the lib status codes */
if(is_https) {
web_TLSClose(exchange, !is_succeeded);
} else {
web_TCPClose(exchange, !is_succeeded);
}
printf("Closing connection\n");
while(!os_GetCSC()) {}
_free(http_exch->buffer);
_free(http_exch);
printf("Freeing buffer\n");
while(!os_GetCSC()) {}
/* To send the FIN and potential ACK segments (in case the user quits) */
force_send_queue();
printf("Forcing send queue\n");
while(!os_GetCSC()) {}
return ret_status;
}
Et le retour console que j'ai eu:
HTTP GET http://www.perdu.com
Websitelen 13 bytes
Websitename http://www.perdu.com
IP 51568
Allocating 31 bytes
Allocating 536 bytes
Exchange 0xd053e4
Ret_val 0
Request GET / HTTP/1.1
HOST: http://www.perdu.com
Delivering data 0
Request finished
Event removed
Closing connection
Freeing buffer
Forcing send queue
Something after requestErr 0: couldn't retrieve foreign data
Je continuerais à effectuer des recherches, mais si certains ont des idées
EDIT:
Après analyse WireShark, la calculatrice fetch l'ip du domaine à l'aide des DNS google (ceux de mon téléphone), et obtient leur réponse, mais tjrs pas fetch auprès de l'ip (qui est par ailleur mal interprétée)