FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 03-28-2011, 07:15 PM
Dave Reisner
 
Default lib/handle: add get/set methods for useragent

Signed-off-by: Dave Reisner <d@falconindy.com>
---
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
 
Old 03-28-2011, 07:21 PM
Rémy Oudompheng
 
Default lib/handle: add get/set methods for useragent

On 2011/3/28 Dave Reisner <d@falconindy.com> wrote:
> @@ -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: */

I'd rather have alpm_option_set_useragent() return an int, just like
alpm_option_set_root(), and make alpm_option_get_useragent() return
NULL and set pm_errno if handle is NULL, just like
alpm_option_set_root().

As a matter or personal taste (and a bit of consistency obsession).
--
Rémy.
 
Old 04-21-2011, 12:00 AM
Dan McGee
 
Default lib/handle: add get/set methods for useragent

On Mon, Mar 28, 2011 at 2:15 PM, Dave Reisner <d@falconindy.com> wrote:
> Signed-off-by: Dave Reisner <d@falconindy.com>
I'm not applying these, I think our current approach is reasonable enough.
 

Thread Tools




All times are GMT. The time now is 08:36 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org