diff options
author | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-01-17 01:20:25 +0000 |
---|---|---|
committer | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-01-17 01:20:25 +0000 |
commit | c31a36b8b5aec57f7d37bbcdd6ac4363d33deedf (patch) | |
tree | cb1274a17711473fa63a95caa44d5afa9c59a02b /samples | |
parent | a69a51607bc9368420e1c852c0561c956eef6b45 (diff) | |
download | libproxy-c31a36b8b5aec57f7d37bbcdd6ac4363d33deedf.tar.gz |
move samlpes dir
git-svn-id: http://libproxy.googlecode.com/svn/trunk@463 c587cffe-e639-0410-9787-d7902ae8ed56
Diffstat (limited to 'samples')
-rw-r--r-- | samples/dotnet/Makefile | 8 | ||||
-rw-r--r-- | samples/dotnet/proxy.cs | 38 | ||||
-rw-r--r-- | samples/libcurl/Makefile | 9 | ||||
-rw-r--r-- | samples/libcurl/curlget.c | 111 |
4 files changed, 166 insertions, 0 deletions
diff --git a/samples/dotnet/Makefile b/samples/dotnet/Makefile new file mode 100644 index 0000000..587f83b --- /dev/null +++ b/samples/dotnet/Makefile @@ -0,0 +1,8 @@ + +all: proxy.exe + +proxy.exe: proxy.cs + gmcs -pkg:libproxy-sharp-1.0 proxy.cs + +clean: + rm proxy.exe diff --git a/samples/dotnet/proxy.cs b/samples/dotnet/proxy.cs new file mode 100644 index 0000000..a8ce5e4 --- /dev/null +++ b/samples/dotnet/proxy.cs @@ -0,0 +1,38 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2009 Dominique Leuenberger <dominique@leuenberger.net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ******************************************************************************/ + +using System; +using libproxy; + +public class proxy { + public static int Main (string[] args) + { + if (args.Length > 0) { + ProxyFactory pf = new ProxyFactory(); + string[] Proxies = pf.GetProxies(args[0]); + Console.WriteLine(Proxies[0]); + pf = null; + return 0; + } else { + Console.WriteLine("Please start the program with one parameter"); + Console.WriteLine("Example: proxy.exe http://libproxy.googlecode.com/"); + return 1; + } + } +} diff --git a/samples/libcurl/Makefile b/samples/libcurl/Makefile new file mode 100644 index 0000000..35b4597 --- /dev/null +++ b/samples/libcurl/Makefile @@ -0,0 +1,9 @@ + + +all: curlget + +curlget: curlget.c + gcc curlget.c -o curlget -Wall -lcurl -std=c99 $(shell pkg-config --libs libproxy-1.0) + +clean: + rm curlget diff --git a/samples/libcurl/curlget.c b/samples/libcurl/curlget.c new file mode 100644 index 0000000..a0a1c2d --- /dev/null +++ b/samples/libcurl/curlget.c @@ -0,0 +1,111 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com> + * Copyright (C) 2008 Dominique Leuenberger <dominique-libproxy@leuenberger.net> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ******************************************************************************/ + +#include "proxy.h" +#include "curl/curl.h" +#include <string.h> +#include <stdlib.h> + +int main(int argc, char * argv[]) { + pxProxyFactory *pf = NULL; + CURL *curl = NULL; + CURLcode result = 1; + + /* Check if we have a parameter passed, otherwise bail out... I need one */ + if (argc < 2) + { + printf("libcurl / libproxy example implementation\n"); + printf("=========================================\n"); + printf("The program has to be started with one parameter\n"); + printf("Defining the URL that should be downloaded\n\n"); + printf("Example: %s http://code.google.com/p/libproxy/\n", argv[0]); + return -1; + } + + /* Initializing curl... has to happen exactly once in the program */ + if (curl_global_init( CURL_GLOBAL_ALL )) return -4; + + /* Create pxProxyFactory object */ + if (!(pf = px_proxy_factory_new())) + { + printf("Unable to create pxProxyFactory object!\n"); + curl_global_cleanup(); + return -2; + } + + /* Create curl handle */ + if (!(curl = curl_easy_init())) + { + printf("Unable to get libcurl handle!\n"); + px_proxy_factory_free(pf); + curl_global_cleanup(); + return -3; + } + + /* Get the array of proxies to try */ + char **proxies = px_proxy_factory_get_proxies(pf, argv[1]); + + /* Set the URL into the curl handle */ + curl_easy_setopt(curl, CURLOPT_URL, argv[1]); + + /* Try to fetch our url using each proxy */ + for (int i=0 ; proxies[i] ; i++) + { + if (result != 0) + { + /* Setup our proxy's config into curl */ + curl_easy_setopt(curl, CURLOPT_PROXY, proxies[i]); + + /* HTTP Proxy */ + if (!strncmp("http", proxies[i], 4)) + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); + + /* SOCKS Proxy, is this correct??? */ + /* What about SOCKS 4A, 5 and 5_HOSTNAME??? */ + else if (!strncmp("socks", proxies[i], 4)) + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + + /* Attempt to fetch the page */ + result = curl_easy_perform(curl); + } + + /* Free the proxy */ + free(proxies[i]); + + /* If we reached the end of the proxies array and still did not + succeed to conntect, let's inform the user that we failed. */ + if (proxies[i+1] == NULL && result != 0) + printf ("The requested URL (%s) could not be retrieved using the current setup\n", argv[1]); + + } + + /* Free the (now empty) proxy array */ + free(proxies); + + /* Free the curl and libproxy handles */ + px_proxy_factory_free(pf); + curl_easy_cleanup(curl); + + /* Cleanup the libcurl library */ + curl_global_cleanup(); + return 0; + +} + |