On 08.02.2012 14:47, Nikola Pajkovsky wrote:
+char *http_get_header_value(const char *message,
const char *header_name)
+{
- char *headers_end = strstr(message, "\r\n\r\n");
- if (!headers_end)
return NULL;
- char *search_string = xasprintf("\r\n%s:", header_name);
- char *header = strcasestr(message, search_string);
- if (!header || header> headers_end)
return NULL;
you are leaking search_string
fixed
+char *http_get_body(const char *message) +{
- char *body = strstr(message, "\r\n\r\n");
- if (!body)
return NULL;
- body += strlen("\r\n\r\n");
- while (*body == ' ')
++body;
- int len = strlen(body);
- while (body[len - 1] == ' ')
--len;
use strtrimch, it will trim from left and right specified char
done
+struct language +{
- char *locale;
- char *encoding;
+};
+extern const char *url; +extern bool ssl_allow_insecure; +extern bool http_show_headers; +extern unsigned port;
according to me, this is way better solution, than extern 4 variables from one binary to another through header
struct https_utls { const char *url; bool ssl_allow_insecure; bool http_show_headers; unsigned port; };
#define INIT_HTTPS_UTLS(name) \ static struct https_utls name = { \ .url = "some-url", \ .ssl_allow_insecure = true, \ .http_show_headers = false, \ .port = 100, \ }
INIT_HTTPS_UTLS(https_struct);
hopefully done :) ssl_allow_insecure needs to be a global, because it is used in a callback function with fixed parameters. However it does not need to be shared anymore, so it became static in https-utils.c
+extern void get_language(struct language *lang); +extern void alert_server_error(); +extern void alert_connection_error(); +extern void ssl_connect(PRFileDesc **tcp_sock, PRFileDesc **ssl_sock); +extern void ssl_disconnect(PRFileDesc *ssl_sock); +extern char *http_get_header_value(const char *message, const char *header_name); +extern char *http_get_body(const char *message); +extern int http_get_response_code(const char *message); +extern void http_print_headers(FILE *file, const char *message); +extern char *tcp_read_response(PRFileDesc *tcp_sock); +extern void nss_init(SECMODModule **mod, PK11GenericObject **cert); +extern void nss_close(SECMODModule *mod, PK11GenericObject *cert);
you don't have to extern; if you have header foo.h, foo.c and function bar() which is in foo.h, but not belongs to foo.c it's good to prefix it with extern. otherwise it's pointless to use extern.
done