diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-05-18 14:36:12 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-05-18 14:36:12 +0000 |
commit | 7cde11ee3cae1e8116fae441f6d614aa7a707100 (patch) | |
tree | 5afcf11398547f9b00bcf5722a3788801ebd35a4 | |
parent | 74305a3c8fb32c9c824e1d1c98e304c72f551496 (diff) | |
download | gnunet-7cde11ee3cae1e8116fae441f6d614aa7a707100.tar.gz gnunet-7cde11ee3cae1e8116fae441f6d614aa7a707100.zip |
- added curl
-rw-r--r-- | src/gns/gnocksy/gnocksy.c | 63 | ||||
-rw-r--r-- | src/gns/gnocksy/protocol.h | 1 |
2 files changed, 53 insertions, 11 deletions
diff --git a/src/gns/gnocksy/gnocksy.c b/src/gns/gnocksy/gnocksy.c index 1ca686839..08e90b371 100644 --- a/src/gns/gnocksy/gnocksy.c +++ b/src/gns/gnocksy/gnocksy.c | |||
@@ -3,6 +3,13 @@ | |||
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | /** | ||
7 | * | ||
8 | * Note: Only supports addr type 3 (domain) for now. | ||
9 | * Chrome uses it automatically | ||
10 | * For FF: about:config -> network.proxy.socks_remote_dns true | ||
11 | */ | ||
12 | |||
6 | #include <stdlib.h> | 13 | #include <stdlib.h> |
7 | #include <string.h> | 14 | #include <string.h> |
8 | #include <unistd.h> | 15 | #include <unistd.h> |
@@ -15,6 +22,7 @@ | |||
15 | #include <netdb.h> | 22 | #include <netdb.h> |
16 | #include <arpa/inet.h> | 23 | #include <arpa/inet.h> |
17 | #include <microhttpd.h> | 24 | #include <microhttpd.h> |
25 | #include <curl/curl.h> | ||
18 | 26 | ||
19 | #include "protocol.h" | 27 | #include "protocol.h" |
20 | 28 | ||
@@ -22,6 +30,29 @@ | |||
22 | 30 | ||
23 | #define DEBUG 1 | 31 | #define DEBUG 1 |
24 | 32 | ||
33 | CURL *curl = NULL; | ||
34 | struct MHD_Daemon *mhd_daemon; | ||
35 | |||
36 | static size_t | ||
37 | curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls) | ||
38 | { | ||
39 | const char* page = buffer; | ||
40 | size_t bytes = size * nmemb; | ||
41 | struct MHD_Response *response; | ||
42 | struct MHD_Connection *con = cls; | ||
43 | int ret; | ||
44 | |||
45 | response = MHD_create_response_from_data (strlen(page), | ||
46 | (void*) page, | ||
47 | MHD_NO, | ||
48 | MHD_NO); | ||
49 | |||
50 | ret = MHD_queue_response (con, MHD_HTTP_OK, response); | ||
51 | MHD_destroy_response (response); | ||
52 | printf( "buffer %s\n", (char*)buffer ); | ||
53 | return bytes; | ||
54 | } | ||
55 | |||
25 | /* | 56 | /* |
26 | * Create an ipv4/6 tcp socket for a given port | 57 | * Create an ipv4/6 tcp socket for a given port |
27 | * | 58 | * |
@@ -163,8 +194,6 @@ connect_to_domain (struct hostent* phost, uint16_t srv_port) | |||
163 | return conn_fd; | 194 | return conn_fd; |
164 | } | 195 | } |
165 | 196 | ||
166 | static struct MHD_Daemon *mhd_daemon; | ||
167 | |||
168 | static int | 197 | static int |
169 | access_cb (void* cls, | 198 | access_cb (void* cls, |
170 | const struct sockaddr *addr, | 199 | const struct sockaddr *addr, |
@@ -188,7 +217,8 @@ accept_cb (void *cls, | |||
188 | const char* page = "<html><head><title>gnoxy</title>"\ | 217 | const char* page = "<html><head><title>gnoxy</title>"\ |
189 | "</head><body>gnoxy demo</body></html>"; | 218 | "</head><body>gnoxy demo</body></html>"; |
190 | struct MHD_Response *response; | 219 | struct MHD_Response *response; |
191 | int ret; | 220 | struct socks5_bridge *br = cls; |
221 | CURLcode ret; | ||
192 | 222 | ||
193 | if (0 != strcmp (meth, "GET")) | 223 | if (0 != strcmp (meth, "GET")) |
194 | return MHD_NO; | 224 | return MHD_NO; |
@@ -202,14 +232,23 @@ accept_cb (void *cls, | |||
202 | return MHD_NO; | 232 | return MHD_NO; |
203 | 233 | ||
204 | *con_cls = NULL; | 234 | *con_cls = NULL; |
205 | response = MHD_create_response_from_data (strlen(page), | ||
206 | (void*) page, | ||
207 | MHD_NO, | ||
208 | MHD_NO); | ||
209 | 235 | ||
210 | ret = MHD_queue_response (con, MHD_HTTP_OK, response); | 236 | if (curl) |
211 | MHD_destroy_response (response); | 237 | { |
212 | return ret; | 238 | printf ("url %s\n", br->host); |
239 | curl_easy_setopt (curl, CURLOPT_URL, br->host); | ||
240 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &curl_write_data); | ||
241 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, con); | ||
242 | ret = curl_easy_perform (curl); | ||
243 | if (ret == CURLE_OK) | ||
244 | { | ||
245 | printf("all good on the curl end\n"); | ||
246 | return MHD_YES; | ||
247 | } | ||
248 | printf("error on the curl end %s\n", curl_easy_strerror(ret)); | ||
249 | } | ||
250 | return MHD_NO; | ||
251 | |||
213 | } | 252 | } |
214 | 253 | ||
215 | int main ( int argc, char *argv[] ) | 254 | int main ( int argc, char *argv[] ) |
@@ -242,6 +281,7 @@ int main ( int argc, char *argv[] ) | |||
242 | struct hostent *phost; | 281 | struct hostent *phost; |
243 | 282 | ||
244 | mhd_daemon = NULL; | 283 | mhd_daemon = NULL; |
284 | curl = curl_easy_init(); | ||
245 | 285 | ||
246 | for (j = 0; j < MAXEVENTS; j++) | 286 | for (j = 0; j < MAXEVENTS; j++) |
247 | ev_states[j] = SOCKS5_INIT; | 287 | ev_states[j] = SOCKS5_INIT; |
@@ -426,6 +466,7 @@ int main ( int argc, char *argv[] ) | |||
426 | 466 | ||
427 | if ( -1 != is_tld (domain, ".gnunet") ) | 467 | if ( -1 != is_tld (domain, ".gnunet") ) |
428 | { | 468 | { |
469 | strcpy (br->host, domain); | ||
429 | if (NULL == mhd_daemon) | 470 | if (NULL == mhd_daemon) |
430 | { | 471 | { |
431 | mhd_daemon = MHD_start_daemon( MHD_USE_THREAD_PER_CONNECTION, | 472 | mhd_daemon = MHD_start_daemon( MHD_USE_THREAD_PER_CONNECTION, |
@@ -516,7 +557,7 @@ int main ( int argc, char *argv[] ) | |||
516 | } | 557 | } |
517 | 558 | ||
518 | free (events); | 559 | free (events); |
519 | 560 | MHD_stop_daemon (mhd_daemon); | |
520 | close (sfd); | 561 | close (sfd); |
521 | 562 | ||
522 | return EXIT_SUCCESS; | 563 | return EXIT_SUCCESS; |
diff --git a/src/gns/gnocksy/protocol.h b/src/gns/gnocksy/protocol.h index 438a94ba2..8b3b218d6 100644 --- a/src/gns/gnocksy/protocol.h +++ b/src/gns/gnocksy/protocol.h | |||
@@ -45,6 +45,7 @@ struct socks5_bridge | |||
45 | struct socks5_bridge* remote_end; | 45 | struct socks5_bridge* remote_end; |
46 | struct sockaddr addr; | 46 | struct sockaddr addr; |
47 | socklen_t addr_len; | 47 | socklen_t addr_len; |
48 | char host[256]; | ||
48 | int status; | 49 | int status; |
49 | }; | 50 | }; |
50 | 51 | ||