Skip to content

Commit

Permalink
Support for read 'useragent' attr. (RhBug: 947346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tojaj committed Apr 3, 2013
1 parent 056a115 commit 4955704
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 3 deletions.
15 changes: 12 additions & 3 deletions librepo/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ lr_handle_free(lr_Handle handle)
lr_free(handle->mirrorlist);
lr_free(handle->used_mirror);
lr_free(handle->destdir);
lr_free(handle->useragent);
lr_internalmirrorlist_free(handle->internal_mirrorlist);
lr_metalink_free(handle->metalink);
lr_handle_free_list(&handle->yumdlist);
Expand Down Expand Up @@ -239,9 +240,13 @@ lr_handle_setopt(lr_Handle handle, lr_HandleOption option, ...)
handle->interruptible = va_arg(arg, long) ? 1 : 0;
break;

case LRO_USERAGENT:
c_rc = curl_easy_setopt(c_h, CURLOPT_USERAGENT, va_arg(arg, char *));
case LRO_USERAGENT: {
char *useragent = va_arg(arg, char *);
if (handle->useragent) lr_free(handle->useragent);
handle->useragent = lr_strdup(useragent);
c_rc = curl_easy_setopt(c_h, CURLOPT_USERAGENT, useragent);
break;
}

case LRO_GPGCHECK:
if (va_arg(arg, long))
Expand Down Expand Up @@ -603,6 +608,11 @@ lr_handle_getinfo(lr_Handle handle, lr_HandleOption option, ...)
*lnum = (long) handle->repotype;
break;

case LRI_USERAGENT:
str = va_arg(arg, char **);
*str = handle->useragent;
break;

case LRI_YUMDLIST: {
char ***strlist = va_arg(arg, char ***);
*strlist = handle->yumdlist;
Expand Down Expand Up @@ -656,7 +666,6 @@ lr_handle_getinfo(lr_Handle handle, lr_HandleOption option, ...)
break;
}


default:
rc = LRE_UNKNOWNOPT;
break;
Expand Down
1 change: 1 addition & 0 deletions librepo/handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef enum {
LRI_PROGRESSDATA, /* (lr_ProgressCb) */
LRI_DESTDIR, /* (char **) */
LRI_REPOTYPE, /* (long *) */
LRI_USERAGENT, /* (char **) */
LRI_YUMDLIST, /* (char ***) */
LRI_YUMBLIST, /* (char ***) */
LRI_LASTCURLERR, /* (long *) */
Expand Down
1 change: 1 addition & 0 deletions librepo/handle_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct _lr_Handle {
char *used_mirror; /*!< Finally used mirror (if any) */
int retries; /*!< Number of maximum retries */
char *destdir; /*!< Destination directory */
char *useragent; /*!< User agent */
lr_Repotype repotype; /*!< Type of repository */
lr_Checks checks; /*!< Which check sould be applied */
long status_code; /*!< Last HTTP or FTP status code */
Expand Down
3 changes: 3 additions & 0 deletions librepo/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
.. data:: LRI_PROGRESSDATA
.. data:: LRI_DESTDIR
.. data:: LRI_REPOTYPE
.. data:: LRI_USERAGENT
.. data:: LRI_YUMDLIST
.. data:: LRI_YUMBLIST
.. data:: LRI_LASTCURLERR
Expand Down Expand Up @@ -512,6 +513,7 @@
LRI_PROGRESSDATA = _librepo.LRI_PROGRESSDATA
LRI_DESTDIR = _librepo.LRI_DESTDIR
LRI_REPOTYPE = _librepo.LRI_REPOTYPE
LRI_USERAGENT = _librepo.LRI_USERAGENT
LRI_YUMDLIST = _librepo.LRI_YUMDLIST
LRI_YUMBLIST = _librepo.LRI_YUMBLIST
LRI_LASTCURLERR = _librepo.LRI_LASTCURLERR
Expand All @@ -530,6 +532,7 @@
"progressdata": LRI_PROGRESSDATA,
"destdir": LRI_DESTDIR,
"repotype": LRI_REPOTYPE,
"useragent": LRI_USERAGENT,
"yumdlist": LRI_YUMDLIST,
"yumblist": LRI_YUMBLIST,
"lastcurlerr": LRI_LASTCURLERR,
Expand Down
1 change: 1 addition & 0 deletions librepo/python/handle-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ getinfo(_HandleObject *self, PyObject *args)
case LRI_URL:
case LRI_MIRRORLIST:
case LRI_DESTDIR:
case LRI_USERAGENT:
case LRI_LASTCURLSTRERR:
case LRI_LASTCURLMSTRERR:
res = lr_handle_getinfo(self->handle, (lr_HandleInfoOption)option, &str);
Expand Down
1 change: 1 addition & 0 deletions librepo/python/librepomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ init_librepo(void)
PyModule_AddIntConstant(m, "LRI_PROGRESSDATA", LRI_PROGRESSDATA);
PyModule_AddIntConstant(m, "LRI_DESTDIR", LRI_DESTDIR);
PyModule_AddIntConstant(m, "LRI_REPOTYPE", LRI_REPOTYPE);
PyModule_AddIntConstant(m, "LRI_USERAGENT", LRI_USERAGENT);
PyModule_AddIntConstant(m, "LRI_YUMDLIST", LRI_YUMDLIST);
PyModule_AddIntConstant(m, "LRI_YUMBLIST", LRI_YUMBLIST);
PyModule_AddIntConstant(m, "LRI_LASTCURLERR", LRI_LASTCURLERR);
Expand Down
16 changes: 16 additions & 0 deletions tests/python/tests/test_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def test_handle_setopt_getinfo(self):
h.setopt(librepo.LRO_DESTDIR, "")
self.assertEqual(h.getinfo(librepo.LRI_DESTDIR), "")

self.assertEqual(h.getinfo(librepo.LRI_USERAGENT), None)
h.setopt(librepo.LRO_USERAGENT, "librepo/0.0")
self.assertEqual(h.getinfo(librepo.LRI_USERAGENT), "librepo/0.0")
h.setopt(librepo.LRO_USERAGENT, None)
self.assertEqual(h.getinfo(librepo.LRI_USERAGENT), None)
h.setopt(librepo.LRO_USERAGENT, "")
self.assertEqual(h.getinfo(librepo.LRI_USERAGENT), "")

self.assertEqual(h.getinfo(librepo.LRI_YUMDLIST), None)
h.setopt(librepo.LRO_YUMDLIST, ["primary", "other"])
self.assertEqual(h.getinfo(librepo.LRI_YUMDLIST), ["primary", "other"])
Expand Down Expand Up @@ -137,6 +145,14 @@ def test_handle_setget_attr(self):
h.destdir = ""
self.assertEqual(h.destdir, "")

self.assertEqual(h.useragent, None)
h.useragent = "librepo/0.0"
self.assertEqual(h.useragent, "librepo/0.0")
h.useragent = None
self.assertEqual(h.useragent, None)
h.useragent = ""
self.assertEqual(h.useragent, "")

self.assertEqual(h.yumdlist, None)
h.yumdlist = ["primary", "other"]
self.assertEqual(h.yumdlist, ["primary", "other"])
Expand Down
5 changes: 5 additions & 0 deletions tests/test_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ START_TEST(test_handle)
lr_handle_setopt(h, LRO_PROXY, "proxy");
lr_handle_setopt(h, LRO_PROXYUSERPWD, "proxyuser:pwd");
lr_handle_setopt(h, LRO_DESTDIR, "foodir");
lr_handle_setopt(h, LRO_USERAGENT, "librepo/0.0");
char *dlist[] = {"primary", "filelists", NULL};
lr_handle_setopt(h, LRO_YUMDLIST, dlist);
lr_handle_setopt(h, LRO_YUMBLIST, dlist);
Expand Down Expand Up @@ -75,6 +76,10 @@ START_TEST(test_handle_getinfo)
lr_handle_getinfo(h, LRI_REPOTYPE, &num);
fail_if(num != 0);

str = NULL;
lr_handle_getinfo(h, LRI_USERAGENT, &str);
fail_if(num != 0);

strlist = NULL;
lr_handle_getinfo(h, LRI_YUMDLIST, &strlist);
fail_if(strlist != NULL);
Expand Down

0 comments on commit 4955704

Please sign in to comment.