gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21547 - gnunet/src/gns/gnocksy


From: gnunet
Subject: [GNUnet-SVN] r21547 - gnunet/src/gns/gnocksy
Date: Fri, 18 May 2012 16:36:12 +0200

Author: schanzen
Date: 2012-05-18 16:36:12 +0200 (Fri, 18 May 2012)
New Revision: 21547

Modified:
   gnunet/src/gns/gnocksy/gnocksy.c
   gnunet/src/gns/gnocksy/protocol.h
Log:
- added curl


Modified: gnunet/src/gns/gnocksy/gnocksy.c
===================================================================
--- gnunet/src/gns/gnocksy/gnocksy.c    2012-05-18 13:44:01 UTC (rev 21546)
+++ gnunet/src/gns/gnocksy/gnocksy.c    2012-05-18 14:36:12 UTC (rev 21547)
@@ -3,6 +3,13 @@
  */
 
 #include <stdio.h>
+/**
+ *
+ * Note: Only supports addr type 3 (domain) for now.
+ * Chrome uses it automatically
+ * For FF: about:config -> network.proxy.socks_remote_dns true
+ */
+
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -15,6 +22,7 @@
 #include <netdb.h>
 #include <arpa/inet.h>
 #include <microhttpd.h>
+#include <curl/curl.h>
 
 #include "protocol.h"
 
@@ -22,6 +30,29 @@
 
 #define DEBUG 1
 
+CURL *curl = NULL;
+struct MHD_Daemon *mhd_daemon;
+
+static size_t
+curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls)
+{
+  const char* page = buffer;
+  size_t bytes = size * nmemb;
+  struct MHD_Response *response;
+  struct MHD_Connection *con = cls;
+  int ret;
+
+  response = MHD_create_response_from_data (strlen(page),
+                                            (void*) page,
+                                            MHD_NO,
+                                            MHD_NO);
+
+  ret = MHD_queue_response (con, MHD_HTTP_OK, response);
+  MHD_destroy_response (response);
+  printf( "buffer %s\n", (char*)buffer );
+  return bytes;
+}
+
 /* 
  * Create an ipv4/6 tcp socket for a given port
  *
@@ -163,8 +194,6 @@
   return conn_fd;
 }
 
-static struct MHD_Daemon *mhd_daemon;
-
 static int
 access_cb (void* cls,
            const struct sockaddr *addr,
@@ -188,7 +217,8 @@
   const char* page = "<html><head><title>gnoxy</title>"\
                       "</head><body>gnoxy demo</body></html>";
   struct MHD_Response *response;
-  int ret;
+  struct socks5_bridge *br = cls;
+  CURLcode ret;
 
   if (0 != strcmp (meth, "GET"))
     return MHD_NO;
@@ -202,14 +232,23 @@
     return MHD_NO;
 
   *con_cls = NULL;
-  response = MHD_create_response_from_data (strlen(page),
-                                            (void*) page,
-                                            MHD_NO,
-                                            MHD_NO);
 
-  ret = MHD_queue_response (con, MHD_HTTP_OK, response);
-  MHD_destroy_response (response);
-  return ret;
+  if (curl)
+  {
+    printf ("url %s\n", br->host);
+    curl_easy_setopt (curl, CURLOPT_URL, br->host);
+    curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &curl_write_data);
+    curl_easy_setopt (curl, CURLOPT_WRITEDATA, con);
+    ret = curl_easy_perform (curl);
+    if (ret == CURLE_OK)
+    {
+      printf("all good on the curl end\n");
+      return MHD_YES;
+    }
+    printf("error on the curl end %s\n", curl_easy_strerror(ret));
+  }
+  return MHD_NO;
+  
 }
 
 int main ( int argc, char *argv[] )
@@ -242,6 +281,7 @@
   struct hostent *phost;
 
   mhd_daemon = NULL;
+  curl = curl_easy_init();
   
   for (j = 0; j < MAXEVENTS; j++)
     ev_states[j] = SOCKS5_INIT;
@@ -426,6 +466,7 @@
 
               if ( -1 != is_tld (domain, ".gnunet") )
               {
+                strcpy (br->host, domain);
                 if (NULL == mhd_daemon)
                 {
                   mhd_daemon = MHD_start_daemon( MHD_USE_THREAD_PER_CONNECTION,
@@ -516,7 +557,7 @@
   }
 
   free (events);
-
+  MHD_stop_daemon (mhd_daemon);
   close (sfd);
 
   return EXIT_SUCCESS;

Modified: gnunet/src/gns/gnocksy/protocol.h
===================================================================
--- gnunet/src/gns/gnocksy/protocol.h   2012-05-18 13:44:01 UTC (rev 21546)
+++ gnunet/src/gns/gnocksy/protocol.h   2012-05-18 14:36:12 UTC (rev 21547)
@@ -45,6 +45,7 @@
   struct socks5_bridge* remote_end;
   struct sockaddr addr;
   socklen_t addr_len;
+  char host[256];
   int status;
 };
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]