aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-05-18 13:44:01 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-05-18 13:44:01 +0000
commit74305a3c8fb32c9c824e1d1c98e304c72f551496 (patch)
treebb663d1e41b559ecc95c0a9846f3e8e65458558f
parent0bf007f176bf0270a0296bcef1b5628ad20ab86f (diff)
downloadgnunet-74305a3c8fb32c9c824e1d1c98e304c72f551496.tar.gz
gnunet-74305a3c8fb32c9c824e1d1c98e304c72f551496.zip
-add mhd to .gnunet requests
-rw-r--r--src/gns/gnocksy/gnocksy.c81
-rw-r--r--src/gns/gnocksy/protocol.h2
2 files changed, 82 insertions, 1 deletions
diff --git a/src/gns/gnocksy/gnocksy.c b/src/gns/gnocksy/gnocksy.c
index 3c5cb49eb..1ca686839 100644
--- a/src/gns/gnocksy/gnocksy.c
+++ b/src/gns/gnocksy/gnocksy.c
@@ -14,6 +14,7 @@
14#include <fcntl.h> 14#include <fcntl.h>
15#include <netdb.h> 15#include <netdb.h>
16#include <arpa/inet.h> 16#include <arpa/inet.h>
17#include <microhttpd.h>
17 18
18#include "protocol.h" 19#include "protocol.h"
19 20
@@ -162,6 +163,54 @@ connect_to_domain (struct hostent* phost, uint16_t srv_port)
162 return conn_fd; 163 return conn_fd;
163} 164}
164 165
166static struct MHD_Daemon *mhd_daemon;
167
168static int
169access_cb (void* cls,
170 const struct sockaddr *addr,
171 socklen_t addrlen)
172{
173 printf ("access cb called\n");
174 return MHD_YES;
175}
176
177static int
178accept_cb (void *cls,
179 struct MHD_Connection *con,
180 const char *url,
181 const char *meth,
182 const char *ver,
183 const char *upload_data,
184 size_t *upload_data_size,
185 void **con_cls)
186{
187 static int dummy;
188 const char* page = "<html><head><title>gnoxy</title>"\
189 "</head><body>gnoxy demo</body></html>";
190 struct MHD_Response *response;
191 int ret;
192
193 if (0 != strcmp (meth, "GET"))
194 return MHD_NO;
195 if (&dummy != *con_cls)
196 {
197 *con_cls = &dummy;
198 return MHD_YES;
199 }
200
201 if (0 != *upload_data_size)
202 return MHD_NO;
203
204 *con_cls = NULL;
205 response = MHD_create_response_from_data (strlen(page),
206 (void*) page,
207 MHD_NO,
208 MHD_NO);
209
210 ret = MHD_queue_response (con, MHD_HTTP_OK, response);
211 MHD_destroy_response (response);
212 return ret;
213}
165 214
166int main ( int argc, char *argv[] ) 215int main ( int argc, char *argv[] )
167{ 216{
@@ -191,6 +240,8 @@ int main ( int argc, char *argv[] )
191 uint16_t req_port; 240 uint16_t req_port;
192 int conn_fd; 241 int conn_fd;
193 struct hostent *phost; 242 struct hostent *phost;
243
244 mhd_daemon = NULL;
194 245
195 for (j = 0; j < MAXEVENTS; j++) 246 for (j = 0; j < MAXEVENTS; j++)
196 ev_states[j] = SOCKS5_INIT; 247 ev_states[j] = SOCKS5_INIT;
@@ -290,6 +341,8 @@ int main ( int argc, char *argv[] )
290 event.events = EPOLLIN | EPOLLET; 341 event.events = EPOLLIN | EPOLLET;
291 br = malloc (sizeof (struct socks5_bridge)); 342 br = malloc (sizeof (struct socks5_bridge));
292 br->fd = infd; 343 br->fd = infd;
344 br->addr = in_addr;
345 br->addr_len = in_len;
293 br->remote_end = NULL; 346 br->remote_end = NULL;
294 br->status = SOCKS5_INIT; 347 br->status = SOCKS5_INIT;
295 event.data.ptr = br; 348 event.data.ptr = br;
@@ -373,7 +426,33 @@ int main ( int argc, char *argv[] )
373 426
374 if ( -1 != is_tld (domain, ".gnunet") ) 427 if ( -1 != is_tld (domain, ".gnunet") )
375 { 428 {
376 printf("noting implemented for GNUnet %s\n", domain); 429 if (NULL == mhd_daemon)
430 {
431 mhd_daemon = MHD_start_daemon( MHD_USE_THREAD_PER_CONNECTION,
432 8080,
433 &access_cb, br,
434 &accept_cb, br,
435 MHD_OPTION_END);
436
437 }
438
439 printf ("trying to add to MHD\n");
440 if (MHD_YES != MHD_add_connection (mhd_daemon,
441 br->fd,
442 &br->addr,
443 br->addr_len))
444 {
445 printf ("Error adding %d to mhd\n", br->fd);
446 }
447
448 event.events = EPOLLIN | EPOLLET;
449 epoll_ctl (efd, EPOLL_CTL_DEL, br->fd, &event);
450 resp.version = 0x05;
451 resp.reply = 0x00;
452 resp.reserved = 0x00;
453 resp.addr_type = 0x01;
454 write (br->fd, &resp, 10);
455 break;
377 } 456 }
378 457
379 conn_fd = connect_to_domain (phost, req_port); 458 conn_fd = connect_to_domain (phost, req_port);
diff --git a/src/gns/gnocksy/protocol.h b/src/gns/gnocksy/protocol.h
index ea076ad1a..438a94ba2 100644
--- a/src/gns/gnocksy/protocol.h
+++ b/src/gns/gnocksy/protocol.h
@@ -43,6 +43,8 @@ struct socks5_bridge
43{ 43{
44 int fd; 44 int fd;
45 struct socks5_bridge* remote_end; 45 struct socks5_bridge* remote_end;
46 struct sockaddr addr;
47 socklen_t addr_len;
46 int status; 48 int status;
47}; 49};
48 50