"Fossies" - the Fresh Open Source Software Archive

Member "geoipupdate-3.1.1/bin/geoipupdate_s.c" (23 Aug 2018, 1884 Bytes) of package /linux/misc/geoipupdate-3.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "geoipupdate_s.c" see the Fossies "Dox" file reference documentation.

    1 
    2 #include "geoipupdate.h"
    3 #include <errno.h>
    4 #include <stdlib.h>
    5 #include <string.h>
    6 
    7 geoipupdate_s *geoipupdate_s_new(void) {
    8     size_t size = sizeof(geoipupdate_s);
    9     geoipupdate_s *gu = xcalloc(1, size);
   10 
   11     gu->license_file = strdup(SYSCONFDIR "/GeoIP.conf");
   12     exit_if(NULL == gu->license_file,
   13             "Unable to allocate memory for license file path: %s\n",
   14             strerror(errno));
   15 
   16     gu->database_dir = strdup(DATADIR);
   17     exit_if(NULL == gu->database_dir,
   18             "Unable to allocate memory for database directory path: %s\n",
   19             strerror(errno));
   20 
   21     gu->host = strdup("updates.maxmind.com");
   22     exit_if(NULL == gu->host,
   23             "Unable to allocate memory for update host: %s\n",
   24             strerror(errno));
   25 
   26     gu->proxy = strdup("");
   27     exit_if(NULL == gu->proxy,
   28             "Unable to allocate memory for proxy host: %s\n",
   29             strerror(errno));
   30 
   31     gu->proxy_user_password = strdup("");
   32     exit_if(NULL == gu->proxy_user_password,
   33             "Unable to allocate memory for proxy credentials: %s\n",
   34             strerror(errno));
   35 
   36     gu->lock_file = strdup("");
   37     exit_if(NULL == gu->lock_file,
   38             "Unable to allocate memory for lock file path: %s\n",
   39             strerror(errno));
   40 
   41     // curl_easy_init() provides no useful error messages or codes:
   42     // https://curl.haxx.se/mail/lib-2009-11/0243.html
   43     gu->curl = curl_easy_init();
   44     exit_if(NULL == gu->curl, "Unable to initialize curl.\n");
   45 
   46     return gu;
   47 }
   48 
   49 void geoipupdate_s_delete(geoipupdate_s *gu) {
   50     if (gu) {
   51         edition_delete_all(gu);
   52         free(gu->license_file);
   53         free(gu->database_dir);
   54         free(gu->proxy);
   55         free(gu->proxy_user_password);
   56         free(gu->lock_file);
   57         free(gu->host);
   58         if (gu->curl != NULL) {
   59             curl_easy_cleanup(gu->curl);
   60         }
   61         free(gu);
   62     }
   63 }