[maemo-commits] [maemo-commits] r16501 - projects/haf/trunk/apt/methods
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Oct 27 18:27:43 EET 2008
- Previous message: [maemo-commits] r16500 - projects/haf/trunk/hildon-control-panel/src
- Next message: [maemo-commits] r16502 - projects/haf/trunk/apt
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: marivoll Date: 2008-10-27 18:27:42 +0200 (Mon, 27 Oct 2008) New Revision: 16501 Modified: projects/haf/trunk/apt/methods/https.cc Log: Add device identification to urls. Modified: projects/haf/trunk/apt/methods/https.cc =================================================================== --- projects/haf/trunk/apt/methods/https.cc 2008-10-27 15:45:41 UTC (rev 16500) +++ projects/haf/trunk/apt/methods/https.cc 2008-10-27 16:27:42 UTC (rev 16501) @@ -33,6 +33,75 @@ /*}}}*/ using namespace std; +static const char * +get_osso_product_hardware () +{ + static char *product_hardware = NULL; + + if (product_hardware) + return product_hardware; + + /* XXX - There is a library in maemo somewhere to do this, but it is + not included in the maemo SDK, so we have to do it + ourselves. Ridiculous, I know. + */ + + product_hardware = ""; + FILE *f = fopen ("/proc/component_version", "r"); + if (f) + { + char *line = NULL; + size_t len = 0; + ssize_t n; + + while ((n = getline (&line, &len, f)) != -1) + { + if (n > 0 && line[n-1] == '\n') + line[n-1] = '\0'; + + if (sscanf (line, "product %as", &product_hardware) == 1) + break; + } + + free (line); + fclose (f); + } + + return product_hardware; +} + +char* +maybe_add_device_id (const char *uri) +{ + const char *product_hardware = get_osso_product_hardware (); + const char *host_part, *host_end, *at_pos; + char *result; + + if (product_hardware == NULL || product_hardware[0] == '\0') + { +dont_add_device_id: + return strdup (uri); + } + + host_part = strstr (uri, "//"); + if (host_part == NULL) + goto dont_add_device_id; + host_part += 2; + + host_end = strchr (host_part, '/'); + if (host_end == NULL) + host_end = host_part + strlen (host_part); + + at_pos = strchr (host_part, '@'); + if (at_pos && at_pos < host_end) + goto dont_add_device_id; + + asprintf (&result, "%.*sNOKIA-OSSO-%s:JOSHUA@%s", + host_part - uri, uri, product_hardware, host_part); + + return result; +} + size_t HttpsMethod::write_data(void *buffer, size_t size, size_t nmemb, void *userp) { @@ -118,7 +187,8 @@ SetupProxy(); // callbacks - curl_easy_setopt(curl, CURLOPT_URL, Itm->Uri.c_str()); + char *url = maybe_add_device_id (Itm->Uri.c_str ()); + curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); @@ -261,6 +331,9 @@ delete File; curl_slist_free_all(headers); + if (url) + free (url); + return true; };
- Previous message: [maemo-commits] r16500 - projects/haf/trunk/hildon-control-panel/src
- Next message: [maemo-commits] r16502 - projects/haf/trunk/apt
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]