From: Jean-Philippe Orsini Date: Tue, 23 Apr 2013 17:20:16 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=commitdiff_plain;h=1087cf87f08c0311004e47b05cae0f6649d835f7 --- diff --git a/src/Makefile.am b/src/Makefile.am index d3055e2..671429e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,14 +12,14 @@ LIBS = $(CURL_LIBS) $(JSON_LIBS) $(GTK_LIBS) $(WEBKIT_LIBS) bin_PROGRAMS = prss prss_SOURCES = main.c \ - phttp.c \ - phttp.h \ - ttrss.c \ - ttrss.h \ - url.c \ - url.h \ - webbrowser.c \ - webbrowser.h + http.c \ + http.h \ + ttrss.c \ + ttrss.h \ + url.c \ + url.h \ + webbrowser.c \ + webbrowser.h gsettings_SCHEMAS=prss.gschema.xml diff --git a/src/Makefile.in b/src/Makefile.in index db54ec0..fee124c 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -64,7 +64,7 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" PROGRAMS = $(bin_PROGRAMS) -am_prss_OBJECTS = main.$(OBJEXT) phttp.$(OBJEXT) ttrss.$(OBJEXT) \ +am_prss_OBJECTS = main.$(OBJEXT) http.$(OBJEXT) ttrss.$(OBJEXT) \ url.$(OBJEXT) webbrowser.$(OBJEXT) prss_OBJECTS = $(am_prss_OBJECTS) prss_LDADD = $(LDADD) @@ -292,14 +292,14 @@ SUBDIRS = glade AM_LDFLAGS = -Wl,--as-needed -export-dynamic AM_CPPFLAGS = -Wall -Werror $(CURL_CFLAGS) $(GTK_CFLAGS) $(JSON_CFLAGS) $(WEBKIT_CFLAGS) prss_SOURCES = main.c \ - phttp.c \ - phttp.h \ - ttrss.c \ - ttrss.h \ - url.c \ - url.h \ - webbrowser.c \ - webbrowser.h + http.c \ + http.h \ + ttrss.c \ + ttrss.h \ + url.c \ + url.h \ + webbrowser.c \ + webbrowser.h gsettings_SCHEMAS = prss.gschema.xml dist_man_MANS = prss.1 @@ -387,8 +387,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/http.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/phttp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/url.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/webbrowser.Po@am__quote@ diff --git a/src/http.c b/src/http.c new file mode 100644 index 0000000..a1d0211 --- /dev/null +++ b/src/http.c @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2010-2013 jeanfi@gmail.com + * + * 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 + */ +#include +#include +#define _(str) gettext(str) + +#include +#include +#include + +#include +#include + +#include "url.h" + +struct ucontent { + char *data; + size_t len; +}; + +static CURL *curl; + +static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp) +{ + size_t realsize; + struct ucontent *mem; + + realsize = size * nmemb; + mem = (struct ucontent *)userp; + + mem->data = realloc(mem->data, mem->len + realsize + 1); + + memcpy(&(mem->data[mem->len]), buffer, realsize); + mem->len += realsize; + mem->data[mem->len] = 0; + + return realsize; +} + +void phttp_init() +{ + curl = curl_easy_init(); +} + +void phttp_cleanup() +{ + curl_easy_cleanup(curl); +} + +json_object *get_json_object(const char *url) +{ + struct ucontent chunk; + json_object *obj; + + obj = NULL; + + if (!curl) + return NULL; + + chunk.data = malloc(1); + chunk.len = 0; + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + + if (curl_easy_perform(curl) == CURLE_OK) + obj = json_tokener_parse(chunk.data); + else + fprintf(stderr, _("Fail to connect to: %s"), url); + + free(chunk.data); + + return obj; +} + +static json_object *post(const char *url, const char *body) +{ + struct ucontent chunk; + json_object *obj; + + obj = NULL; + + chunk.data = malloc(1); + chunk.len = 0; + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); + if (body) { + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(body)); + } + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + + if (curl_easy_perform(curl) == CURLE_OK) + obj = json_tokener_parse(chunk.data); + else + fprintf(stderr, _("Fail to connect to: %s"), url); + free(chunk.data); + + return obj; +} + +json_object *post_json_object(const char *url, struct json_object *j) +{ + return post(url, json_object_to_json_string(j)); +} diff --git a/src/http.h b/src/http.h new file mode 100644 index 0000000..3c717c9 --- /dev/null +++ b/src/http.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010-2013 jeanfi@gmail.com + * + * 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 _PHTTP_H_ +#define _PHTTP_H_ + +void phttp_init(); +json_object *get_json_object(const char *url); +json_object *post_json_object(const char *url, struct json_object *); + +#endif diff --git a/src/main.c b/src/main.c index b01700e..bc1805c 100644 --- a/src/main.c +++ b/src/main.c @@ -22,12 +22,12 @@ #include #include -#include "ttrss.h" #include #include #include -#include "phttp.h" +#include "http.h" +#include "ttrss.h" #include "webbrowser.h" static const char *program_name; diff --git a/src/phttp.c b/src/phttp.c deleted file mode 100644 index a1d0211..0000000 --- a/src/phttp.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2010-2013 jeanfi@gmail.com - * - * 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 - */ -#include -#include -#define _(str) gettext(str) - -#include -#include -#include - -#include -#include - -#include "url.h" - -struct ucontent { - char *data; - size_t len; -}; - -static CURL *curl; - -static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp) -{ - size_t realsize; - struct ucontent *mem; - - realsize = size * nmemb; - mem = (struct ucontent *)userp; - - mem->data = realloc(mem->data, mem->len + realsize + 1); - - memcpy(&(mem->data[mem->len]), buffer, realsize); - mem->len += realsize; - mem->data[mem->len] = 0; - - return realsize; -} - -void phttp_init() -{ - curl = curl_easy_init(); -} - -void phttp_cleanup() -{ - curl_easy_cleanup(curl); -} - -json_object *get_json_object(const char *url) -{ - struct ucontent chunk; - json_object *obj; - - obj = NULL; - - if (!curl) - return NULL; - - chunk.data = malloc(1); - chunk.len = 0; - - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - - if (curl_easy_perform(curl) == CURLE_OK) - obj = json_tokener_parse(chunk.data); - else - fprintf(stderr, _("Fail to connect to: %s"), url); - - free(chunk.data); - - return obj; -} - -static json_object *post(const char *url, const char *body) -{ - struct ucontent chunk; - json_object *obj; - - obj = NULL; - - chunk.data = malloc(1); - chunk.len = 0; - - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); - if (body) { - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(body)); - } - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - - if (curl_easy_perform(curl) == CURLE_OK) - obj = json_tokener_parse(chunk.data); - else - fprintf(stderr, _("Fail to connect to: %s"), url); - free(chunk.data); - - return obj; -} - -json_object *post_json_object(const char *url, struct json_object *j) -{ - return post(url, json_object_to_json_string(j)); -} diff --git a/src/phttp.h b/src/phttp.h deleted file mode 100644 index 3c717c9..0000000 --- a/src/phttp.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2010-2013 jeanfi@gmail.com - * - * 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 _PHTTP_H_ -#define _PHTTP_H_ - -void phttp_init(); -json_object *get_json_object(const char *url); -json_object *post_json_object(const char *url, struct json_object *); - -#endif diff --git a/src/ttrss.c b/src/ttrss.c index e64c7af..7f9e8df 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -23,7 +23,7 @@ #include #include -#include "phttp.h" +#include "http.h" #include "ttrss.h" #include "url.h"