Michal Toman mtoman@redhat.com writes:
From 3f18b10b8b416839496e50d6b8c83f08c2a9193e Mon Sep 17 00:00:00 2001 From: Michal Toman mtoman@redhat.com Date: Fri, 3 Feb 2012 10:19:43 +0100 Subject: [PATCH 1/2] split HTTPS util functions to a separate file
po/POTFILES.in | 1 + src/plugins/Makefile.am | 6 +- src/plugins/abrt-retrace-client.c | 394 +----------------------------------- src/plugins/https-utils.c | 403 +++++++++++++++++++++++++++++++++++++ src/plugins/https-utils.h | 62 ++++++ 5 files changed, 475 insertions(+), 391 deletions(-) create mode 100644 src/plugins/https-utils.c create mode 100644 src/plugins/https-utils.h +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
+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
diff --git a/src/plugins/https-utils.h b/src/plugins/https-utils.h new file mode 100644 index 0000000..a6b53a8 --- /dev/null +++ b/src/plugins/https-utils.h @@ -0,0 +1,62 @@ +/*
- Copyright (C) 2012 ABRT Team
- Copyright (C) 2012 Red Hat, Inc.
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#ifndef ABRT_HTTPS_UTILS_H_ +#define ABRT_HTTPS_UTILS_H_
+#include <libreport/client.h> +#include <nspr.h> +#include <nss.h> +#include <pk11pub.h> +#include <ssl.h> +#include <sslproto.h> +#include <sslerr.h> +#include <secerr.h> +#include <secmod.h> +#include "libabrt.h"
+#if HAVE_LOCALE_H +#include <locale.h> +#endif
+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);
+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.