Signed-off-by: Dave Reisner <[email protected]>
---
 lib/libalpm/alpm.h   |    3 +++
 lib/libalpm/dload.c  |    4 ++--
 lib/libalpm/handle.c |   15 +++++++++++++++
 lib/libalpm/handle.h |    1 +
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index b08191d..43ff4ba 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -165,6 +165,9 @@ void alpm_option_set_checkspace(int checkspace);
 pmdb_t *alpm_option_get_localdb(void);
 alpm_list_t *alpm_option_get_syncdbs(void);
 
+const char *alpm_option_get_useragent(void);
+void alpm_option_set_useragent(char *useragent);
+
 /*
  * Install reasons -- ie, why the package was installed
  */
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index d9e9488..948e623 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -193,8 +193,8 @@ static int curl_download_internal(const char *url, const 
char *localpath,
        curl_easy_setopt(handle->curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
        curl_easy_setopt(handle->curl, CURLOPT_PROGRESSDATA, (void*)&dlfile);
 
-       useragent = getenv("HTTP_USER_AGENT");
-       if (useragent != NULL) {
+       useragent = alpm_option_get_useragent();
+       if(useragent != NULL) {
                curl_easy_setopt(handle->curl, CURLOPT_USERAGENT, useragent);
        }
 
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 42c0cd1..df4ed54 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -90,6 +90,7 @@ void _alpm_handle_free(pmhandle_t *handle)
        FREELIST(handle->noextract);
        FREELIST(handle->ignorepkg);
        FREELIST(handle->ignoregrp);
+       FREE(handle->useragent);
        FREE(handle);
 
 }
@@ -597,4 +598,18 @@ void SYMEXPORT alpm_option_set_checkspace(int checkspace)
        handle->checkspace = checkspace;
 }
 
+void SYMEXPORT alpm_option_set_useragent(char *useragent)
+{
+       if(handle == NULL) {
+               pm_errno = PM_ERR_HANDLE_NULL;
+               return;
+       }
+       handle->useragent = useragent;
+}
+
+const char SYMEXPORT *alpm_option_get_useragent()
+{
+       return handle->useragent;
+}
+
 /* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index cf192bc..2a0bcd4 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -72,6 +72,7 @@ typedef struct _pmhandle_t {
        char *arch;       /* Architecture of packages we should allow */
        int usedelta;     /* Download deltas if possible */
        int checkspace;   /* Check disk space before installing */
+       char *useragent;  /* User agent string to set for internal downloader */
 } pmhandle_t;
 
 /* global handle variable */
-- 
1.7.4.2


Reply via email to