gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r21554 - gnunet/src/gns/gnocksy
Date: Sun, 20 May 2012 18:12:23 +0200

Author: schanzen
Date: 2012-05-20 18:12:23 +0200 (Sun, 20 May 2012)
New Revision: 21554

Added:
   gnunet/src/gns/gnocksy/gns_glue.c
   gnunet/src/gns/gnocksy/gns_glue.h
Modified:
   gnunet/src/gns/gnocksy/gnocksy.c
Log:
-add gns glue


Modified: gnunet/src/gns/gnocksy/gnocksy.c
===================================================================
--- gnunet/src/gns/gnocksy/gnocksy.c    2012-05-20 15:38:32 UTC (rev 21553)
+++ gnunet/src/gns/gnocksy/gnocksy.c    2012-05-20 16:12:23 UTC (rev 21554)
@@ -26,6 +26,7 @@
 #include <regex.h>
 
 #include "protocol.h"
+#include "gns_glue.h"
 
 #define MAXEVENTS 64
 
@@ -40,12 +41,6 @@
 static struct MHD_Daemon *mhd_daemon;
 static regex_t re_dotplus;
 
-void
-gns_glue_expand_and_shorten ( char* sorig, char* new )
-{
-  memcpy (new, "foo.bar.gnunet", strlen("foo.bar.gnunet"));
-}
-
 static size_t
 curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls)
 {
@@ -60,6 +55,7 @@
   char* plusptr;
   char* p;
   char new_host[256];
+  char to_exp[256];
   uint64_t bytes_copied = 0;
 
   char new_buf[CURL_MAX_WRITE_SIZE+1];
@@ -103,13 +99,17 @@
 
       if (m[1].rm_so != -1)
       {
-        hostptr = p+m[1].rm_eo;
+        hostptr = p+m[1].rm_so;
         if (DEBUG)
           printf ("Copying %d bytes.\n", (hostptr-p));
         memcpy (br->MHD_CURL_BUF+bytes_copied, p, (hostptr-p));
         bytes_copied += (hostptr-p);
         memset (new_host, 0, sizeof(new_host));
-        gns_glue_expand_and_shorten ( br->full_url,
+        memset (to_exp, 0, sizeof (to_exp));
+        memcpy (to_exp, hostptr, (m[1].rm_eo-m[1].rm_so));
+
+        gns_glue_expand_and_shorten ( to_exp,
+                                      br->host,
                                       new_host );
         if (DEBUG)
         {
@@ -366,7 +366,7 @@
     return MHD_CONTENT_READER_END_OF_STREAM;
   }
   pthread_mutex_unlock ( &br->m_done );
-
+  
   pthread_mutex_lock ( &br->m_buf );
   if ( br->MHD_CURL_BUF_STATUS == BUF_WAIT_FOR_CURL )
   {
@@ -375,6 +375,8 @@
     return 0;
   }
 
+
+
   if ( br->MHD_CURL_BUF_SIZE > max )
   {
     printf("buffer in mhd response too small!\n");
@@ -389,6 +391,7 @@
     memcpy ( buf, br->MHD_CURL_BUF, br->MHD_CURL_BUF_SIZE );
   }
   br->MHD_CURL_BUF_STATUS = BUF_WAIT_FOR_CURL;
+  curl_easy_pause (br->curl, CURLPAUSE_CONT);
   pthread_mutex_unlock ( &br->m_buf );
 
   return br->MHD_CURL_BUF_SIZE;

Added: gnunet/src/gns/gnocksy/gns_glue.c
===================================================================
--- gnunet/src/gns/gnocksy/gns_glue.c                           (rev 0)
+++ gnunet/src/gns/gnocksy/gns_glue.c   2012-05-20 16:12:23 UTC (rev 21554)
@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <string.h>
+
+int
+gns_glue_get_auth ( char* name, char* auth )
+{
+  char cmd[1024];
+  char line[1024];
+  FILE *p;
+
+  sprintf (cmd, "%s %s", "gnunet-gns -a", name);
+
+  p = popen(cmd, "r");
+
+  if (p != NULL)
+  {
+    while (fgets (line, sizeof(line), p) != NULL)
+    {
+      if (line[strlen(line)-1] == '\n')
+      {
+        line[strlen(line)-1] = '\0';
+        strcpy (auth, line);
+        return 0;
+      }
+    }
+
+  }
+
+  fclose (p);
+
+  return -1;
+}
+
+int
+gns_glue_shorten ( char* name, char* shortened )
+{
+  char cmd[1024];
+  char line[1024];
+  FILE *p;
+
+  sprintf (cmd, "%s %s", "gnunet-gns -r -s", name);
+
+  p = popen(cmd, "r");
+
+  if (p != NULL)
+  {
+    while (fgets (line, sizeof(line), p) != NULL)
+    {
+      if (line[strlen(line)-1] == '\n')
+      {
+        line[strlen(line)-1] = '\0';
+        strcpy (shortened, line);
+        return 0;
+      }
+    }
+
+  }
+
+  fclose (p);
+
+  return -1;
+}
+
+int
+gns_glue_expand_and_shorten( char* to_expand, char* host, char* shortened )
+{
+  char cmd[1024];
+  char line[1024];
+  FILE *p;
+  char sorig[256];
+  char expanded[256];
+
+  sprintf (shortened, "%s%s", to_expand, host); //TODO this is a mockup
+  return 0;
+
+  sprintf (cmd, "%s %s", "gnunet-gns -a", host);
+
+  p = popen(cmd, "r");
+
+  if (p != NULL)
+  {
+    while (fgets (line, sizeof(line), p) != NULL)
+    {
+      if (line[strlen(line)-1] == '\n')
+      {
+        line[strlen(line)-1] = '\0';
+        strcpy (sorig, line);
+        return 0;
+      }
+    }
+
+  }
+
+  fclose (p);
+
+  sprintf (expanded, "%s.%s", to_expand, sorig);
+  
+  sprintf (cmd, "%s %s", "gnunet-gns -r -s", expanded);
+ 
+  p = popen(cmd, "r");
+
+  if (p != NULL)
+  {
+    while (fgets (line, sizeof(line), p) != NULL)
+    {
+      if (line[strlen(line)-1] == '\n')
+      {
+        line[strlen(line)-1] = '\0';
+        strcpy (shortened, line);
+        return 0;
+      }
+    }
+
+  }
+
+  fclose (p);
+
+  return -1;
+}

Added: gnunet/src/gns/gnocksy/gns_glue.h
===================================================================
--- gnunet/src/gns/gnocksy/gns_glue.h                           (rev 0)
+++ gnunet/src/gns/gnocksy/gns_glue.h   2012-05-20 16:12:23 UTC (rev 21554)
@@ -0,0 +1,10 @@
+int
+gns_glue_get_auth ( char* name, char* auth );
+
+int
+gns_glue_shorten ( char* name, char* shortened);
+
+int
+gns_glue_expand_and_shorten (char* to_expand,
+                             char* host,
+                             char* shortened);




reply via email to

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