get PPA template from file
[ppastats.git] / src / lp_ws.c
index 81b8b63..3de408b 100644 (file)
@@ -1,21 +1,22 @@
 /*
-    Copyright (C) 2011 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
-*/
+ * Copyright (C) 2011-2012 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 <libintl.h>
 #define _(String) gettext(String)
 
@@ -61,15 +62,8 @@ static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp)
        return realsize;
 }
 
-static char *fetch_url(const char *url)
+static void init()
 {
-       struct ucontent *content = malloc(sizeof(struct ucontent));
-       char *result;
-       long code;
-       int retries;
-
-       log_debug(_("fetch_url(): %s"), url);
-
        if (!curl) {
                log_debug(_("initializing CURL"));
                curl_global_init(CURL_GLOBAL_ALL);
@@ -78,6 +72,18 @@ static char *fetch_url(const char *url)
 
        if (!curl)
                exit(EXIT_FAILURE);
+}
+
+static char *fetch_url(const char *url)
+{
+       struct ucontent *content = malloc(sizeof(struct ucontent));
+       char *result;
+       long code;
+       int retries;
+
+       log_debug(_("fetch_url(): %s"), url);
+
+       init();
 
        result = NULL;
 
@@ -105,12 +111,11 @@ static char *fetch_url(const char *url)
                case 502:
                case 503:
                case 504:
-                       if (retries) {
-                               log_err(_("Fetch failed with code %ld "
-                                         "for URL %s"),
-                                       code,
-                                       url);
+                       log_err(_("Fetch failed with code %ld for URL %s"),
+                               code,
+                               url);
 
+                       if (retries) {
                                log_debug(_("Wait 5s before retry"));
                                sleep(5);
 
@@ -118,8 +123,12 @@ static char *fetch_url(const char *url)
                                retries--;
                                goto retrieve;
                        }
+
+                       break;
                default:
-                       log_err(_("Fetch failed: %ld"), code);
+                       log_err(_("Fetch failed with code %ld for URL %s"),
+                               code,
+                               url);
                }
        }