@@ -435,9 +435,7 @@ struct http_connection_t *net_http_connection_new(const char *url,
435435 if (!conn -> url )
436436 goto error ;
437437 if (memcmp (url , "http://" , 7 ) == 0 )
438- {
439438 conn -> scan = conn -> url + 7 ;
440- }
441439 else if (memcmp (url , "https://" , 8 ) == 0 )
442440 {
443441 conn -> scan = conn -> url + 8 ;
@@ -650,7 +648,8 @@ static void net_http_dns_cache_remove_expired(void)
650648 }
651649}
652650
653- static struct dns_cache_entry * net_http_dns_cache_find (const char * domain , int port )
651+ static struct dns_cache_entry * net_http_dns_cache_find (
652+ const char * domain , int port )
654653{
655654 struct dns_cache_entry * entry ;
656655
@@ -678,9 +677,11 @@ static struct dns_cache_entry *net_http_dns_cache_find(const char *domain, int p
678677 return NULL ;
679678}
680679
681- static struct dns_cache_entry * net_http_dns_cache_add (const char * domain , int port , struct addrinfo * addr )
680+ static struct dns_cache_entry * net_http_dns_cache_add (
681+ const char * domain , int port , struct addrinfo * addr )
682682{
683- struct dns_cache_entry * entry = (struct dns_cache_entry * )calloc (1 , sizeof (* entry ));
683+ struct dns_cache_entry * entry = (struct dns_cache_entry * )
684+ calloc (1 , sizeof (* entry ));
684685 if (!entry )
685686 return NULL ;
686687 entry -> domain = strdup (domain );
@@ -765,7 +766,8 @@ static void net_http_conn_pool_remove_expired(void)
765766 {
766767 if (!entry -> in_use && FD_ISSET (entry -> fd , & fds ))
767768 {
768- /* if it's not in use and it's reaadable we assume that means it's closed without checking recv */
769+ /* If it's not in use and it's readable,
770+ * we assume that means it's closed without checking recv */
769771 if (prev )
770772 prev -> next = entry -> next ;
771773 else
@@ -818,7 +820,8 @@ static void net_http_conn_pool_move_to_end(struct conn_pool_entry *entry)
818820 entry -> next = NULL ;
819821}
820822
821- static struct conn_pool_entry * net_http_conn_pool_find (const char * domain , int port )
823+ static struct conn_pool_entry * net_http_conn_pool_find (
824+ const char * domain , int port )
822825{
823826 struct conn_pool_entry * entry ;
824827
@@ -829,7 +832,9 @@ static struct conn_pool_entry *net_http_conn_pool_find(const char *domain, int p
829832 entry = conn_pool ;
830833 while (entry )
831834 {
832- if (!entry -> in_use && port == entry -> port && strcmp (entry -> domain , domain ) == 0 )
835+ if ( !entry -> in_use
836+ && port == entry -> port
837+ && strcmp (entry -> domain , domain ) == 0 )
833838 {
834839 entry -> in_use = true;
835840 net_http_conn_pool_move_to_end (entry );
@@ -844,7 +849,8 @@ static struct conn_pool_entry *net_http_conn_pool_find(const char *domain, int p
844849
845850static struct conn_pool_entry * net_http_conn_pool_add (const char * domain , int port , int fd , bool ssl )
846851{
847- struct conn_pool_entry * entry = (struct conn_pool_entry * )calloc (1 , sizeof (* entry ));
852+ struct conn_pool_entry * entry = (struct conn_pool_entry * )
853+ calloc (1 , sizeof (* entry ));
848854 if (!entry )
849855 return NULL ;
850856 entry -> domain = strdup (domain );
@@ -883,9 +889,9 @@ struct http_t *net_http_new(struct http_connection_t *conn)
883889 state -> request .postdata = malloc (conn -> contentlength );
884890 memcpy (state -> request .postdata , conn -> postdata , conn -> contentlength );
885891 }
886- state -> request .useragent = conn -> useragent ? strdup (conn -> useragent ) : NULL ;
887- state -> request .headers = conn -> headers ? strdup (conn -> headers ) : NULL ;
888- state -> request .port = conn -> port ;
892+ state -> request .useragent = conn -> useragent ? strdup (conn -> useragent ) : NULL ;
893+ state -> request .headers = conn -> headers ? strdup (conn -> headers ) : NULL ;
894+ state -> request .port = conn -> port ;
889895
890896 state -> response .status = -1 ;
891897 state -> response .buflen = 64 * 1024 ; /* Start with larger buffer to reduce reallocations */
@@ -897,21 +903,21 @@ struct http_t *net_http_new(struct http_connection_t *conn)
897903
898904static void net_http_resolve (void * data )
899905{
906+ int port ;
907+ char * domain ;
908+ char port_buf [6 ];
900909 struct dns_cache_entry * entry = (struct dns_cache_entry * )data ;
901910 struct addrinfo hints = {0 };
902911 struct addrinfo * addr = NULL ;
903- char * domain ;
904- int port ;
905- char port_buf [6 ];
906912#if defined(HAVE_SOCKET_LEGACY ) || defined(WIIU )
907913 int family = AF_INET ;
908914#else
909915 int family = AF_UNSPEC ;
910916#endif
911917
912- hints .ai_family = family ;
913- hints .ai_socktype = SOCK_STREAM ;
914- hints .ai_flags |= AI_NUMERICSERV ;
918+ hints .ai_family = family ;
919+ hints .ai_socktype = SOCK_STREAM ;
920+ hints .ai_flags |= AI_NUMERICSERV ;
915921
916922 LOCK_DNS_CACHE ();
917923 domain = strdup (entry -> domain );
@@ -1235,7 +1241,8 @@ static ssize_t net_http_receive_header(struct http_t *state, ssize_t len)
12351241 }
12361242 else
12371243 {
1238- if (string_starts_with_case_insensitive (response -> data , "Content-Length:" ))
1244+ if (string_starts_with_case_insensitive (response -> data ,
1245+ "Content-Length:" ))
12391246 {
12401247 char * ptr = response -> data + (sizeof ("Content-Length:" )- 1 );
12411248 while (* ptr == ' ' || * ptr == '\t' || * ptr == '\r' || * ptr == '\n' )
@@ -1244,15 +1251,14 @@ static ssize_t net_http_receive_header(struct http_t *state, ssize_t len)
12441251 response -> bodytype = T_LEN ;
12451252 response -> len = strtol (ptr , NULL , 10 );
12461253 }
1247- else if (string_is_equal_case_insensitive (response -> data , "Transfer-Encoding: chunked" ))
1254+ else if (string_is_equal_case_insensitive (response -> data ,
1255+ "Transfer-Encoding: chunked" ))
12481256 response -> bodytype = T_CHUNK ;
12491257
12501258 if (response -> data [0 ]== '\0' )
12511259 {
12521260 if (response -> status == 100 )
1253- {
12541261 response -> part = P_HEADER_TOP ;
1255- }
12561262 else
12571263 {
12581264 response -> part = P_BODY ;
@@ -1303,7 +1309,7 @@ static bool net_http_receive_body(struct http_t *state, ssize_t newlen)
13031309 return false;
13041310 response -> part = P_DONE ;
13051311 if (response -> buflen != response -> len )
1306- response -> data = (char * )realloc (response -> data , response -> len );
1312+ response -> data = (char * )realloc (response -> data , response -> len );
13071313 return true;
13081314 }
13091315
@@ -1322,8 +1328,8 @@ static bool net_http_receive_body(struct http_t *state, ssize_t newlen)
13221328 */
13231329
13241330 char * fullend = response -> data + response -> pos ;
1325- char * end = (char * )memchr (response -> data + response -> len + 2 , '\n' ,
1326- response -> pos - response -> len - 2 );
1331+ char * end = (char * )memchr (response -> data + response -> len + 2 ,
1332+ '\n' , response -> pos - response -> len - 2 );
13271333
13281334 if (end )
13291335 {
@@ -1393,16 +1399,17 @@ static bool net_http_receive_body(struct http_t *state, ssize_t newlen)
13931399
13941400static bool net_http_redirect (struct http_t * state , const char * location )
13951401{
1396- /* this reinitializes state based on the new location */
1402+ /* This reinitializes state based on the new location */
13971403
1398- /* url may be absolute or relative to the current url */
1404+ /* URL may be absolute or relative to the current URL */
13991405 bool absolute = (!strncmp (location , "http://" , sizeof ("http://" )- 1 )
14001406 || !strncmp (location , "https://" , sizeof ("https://" )- 1 ));
14011407
14021408 if (absolute )
14031409 {
14041410 /* this block is a little wasteful, memory-wise */
1405- struct http_connection_t * new_url = net_http_connection_new (location , NULL , NULL );
1411+ struct http_connection_t * new_url = net_http_connection_new (
1412+ location , NULL , NULL );
14061413 net_http_connection_iterate (new_url );
14071414 if (!net_http_connection_done (new_url ))
14081415 {
@@ -1430,16 +1437,19 @@ static bool net_http_redirect(struct http_t *state, const char *location)
14301437 else
14311438 {
14321439 char * path = (char * )malloc (PATH_MAX_LENGTH );
1433- fill_pathname_resolve_relative (path , state -> request .path , location , PATH_MAX_LENGTH );
1440+ fill_pathname_resolve_relative (path , state -> request .path ,
1441+ location , PATH_MAX_LENGTH );
14341442 free (state -> request .path );
14351443 state -> request .path = path ;
14361444 }
14371445 }
14381446 state -> request_sent = false;
14391447 state -> response .part = P_HEADER_TOP ;
14401448 state -> response .status = -1 ;
1441- state -> response .buflen = 64 * 1024 ; /* Start with larger buffer to reduce reallocations */
1442- state -> response .data = (char * )realloc (state -> response .data , state -> response .buflen );
1449+ /* Start with larger buffer to reduce reallocations */
1450+ state -> response .buflen = 64 * 1024 ;
1451+ state -> response .data = (char * )realloc (state -> response .data ,
1452+ state -> response .buflen );
14431453 state -> response .pos = 0 ;
14441454 state -> response .len = 0 ;
14451455 state -> response .bodytype = T_FULL ;
0 commit comments