| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include <stdio.h> |
| 2 |
|
|
#include <stdlib.h> |
| 3 |
|
|
#include <assert.h> |
| 4 |
|
|
#include <string.h> |
| 5 |
|
|
|
| 6 |
|
|
#include "proxy.h" |
| 7 |
|
|
|
| 8 |
|
|
void * |
| 9 |
|
|
malloc0 (size_t s); |
| 10 |
|
|
void |
| 11 |
|
|
print_proxies (char **proxies); |
| 12 |
|
|
|
| 13 |
|
|
void * |
| 14 |
|
✗ |
malloc0 (size_t s) |
| 15 |
|
|
{ |
| 16 |
|
✗ |
void *tmp = malloc (s); |
| 17 |
|
✗ |
if (!tmp) return NULL; |
| 18 |
|
✗ |
memset (tmp, '\0', s); |
| 19 |
|
✗ |
return tmp; |
| 20 |
|
|
} |
| 21 |
|
|
|
| 22 |
|
|
/** |
| 23 |
|
|
* Prints an array of proxies. Proxies are space separated. |
| 24 |
|
|
* @proxies an array containing the proxies returned by libproxy. |
| 25 |
|
|
*/ |
| 26 |
|
|
void |
| 27 |
|
✗ |
print_proxies (char **proxies) |
| 28 |
|
|
{ |
| 29 |
|
|
int j; |
| 30 |
|
|
|
| 31 |
|
✗ |
if (!proxies) { |
| 32 |
|
✗ |
printf ("\n"); |
| 33 |
|
✗ |
return; |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
✗ |
for (j = 0; proxies[j] ; j++) |
| 37 |
|
✗ |
printf ("%s%s", proxies[j], proxies[j + 1] ? " " : "\n"); |
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
int |
| 41 |
|
✗ |
main (int argc, |
| 42 |
|
|
char **argv) |
| 43 |
|
|
{ |
| 44 |
|
|
int i; |
| 45 |
|
|
char url[102400]; /* Should be plently long for most URLs */ |
| 46 |
|
|
char **proxies; |
| 47 |
|
|
|
| 48 |
|
|
/* Create the proxy factory object */ |
| 49 |
|
✗ |
pxProxyFactory *pf = px_proxy_factory_new (); |
| 50 |
|
✗ |
if (!pf) { |
| 51 |
|
✗ |
fprintf (stderr, "An unknown error occurred!\n"); |
| 52 |
|
✗ |
return 1; |
| 53 |
|
|
} |
| 54 |
|
|
/* User entered some arguments on startup. skip interactive */ |
| 55 |
|
✗ |
if (argc > 1) { |
| 56 |
|
✗ |
for (i = 1; i < argc ; i++) { |
| 57 |
|
|
/* |
| 58 |
|
|
* Get an array of proxies to use. These should be used |
| 59 |
|
|
* in the order returned. Only move on to the next proxy |
| 60 |
|
|
* if the first one fails (etc). |
| 61 |
|
|
*/ |
| 62 |
|
✗ |
proxies = px_proxy_factory_get_proxies (pf, argv[i]); |
| 63 |
|
✗ |
print_proxies (proxies); |
| 64 |
|
✗ |
px_proxy_factory_free_proxies (proxies); |
| 65 |
|
|
} |
| 66 |
|
|
} |
| 67 |
|
|
/* Interactive mode */ |
| 68 |
|
|
else { |
| 69 |
|
|
/* For each URL we read on STDIN, get the proxies to use */ |
| 70 |
|
✗ |
for (url[0] = '\0' ; fgets (url, 102400, stdin) != NULL ; ) { |
| 71 |
|
✗ |
if (url[strlen (url) - 1] == '\n') url[strlen (url) - 1] = '\0'; |
| 72 |
|
|
|
| 73 |
|
|
/* |
| 74 |
|
|
* Get an array of proxies to use. These should be used |
| 75 |
|
|
* in the order returned. Only move on to the next proxy |
| 76 |
|
|
* if the first one fails (etc). |
| 77 |
|
|
*/ |
| 78 |
|
✗ |
proxies = px_proxy_factory_get_proxies (pf, url); |
| 79 |
|
✗ |
print_proxies (proxies); |
| 80 |
|
✗ |
px_proxy_factory_free_proxies (proxies); |
| 81 |
|
|
} |
| 82 |
|
|
} |
| 83 |
|
|
/* Destroy the proxy factory object */ |
| 84 |
|
✗ |
px_proxy_factory_free (pf); |
| 85 |
|
✗ |
return 0; |
| 86 |
|
|
} |
| 87 |
|
|
|