aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-05-20 16:12:23 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-05-20 16:12:23 +0000
commitfd98a44c4a4b6b6661034ab1a0100939700df769 (patch)
tree3e0a2020b422fe38d98bed9d49c9a771dafef7e8 /src
parentd7acecb458a355ea7981bce91230733c373d85fb (diff)
downloadgnunet-fd98a44c4a4b6b6661034ab1a0100939700df769.tar.gz
gnunet-fd98a44c4a4b6b6661034ab1a0100939700df769.zip
-add gns glue
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnocksy/gnocksy.c21
-rw-r--r--src/gns/gnocksy/gns_glue.c119
-rw-r--r--src/gns/gnocksy/gns_glue.h10
3 files changed, 141 insertions, 9 deletions
diff --git a/src/gns/gnocksy/gnocksy.c b/src/gns/gnocksy/gnocksy.c
index faccfa6d2..49b7d72bd 100644
--- a/src/gns/gnocksy/gnocksy.c
+++ b/src/gns/gnocksy/gnocksy.c
@@ -26,6 +26,7 @@
26#include <regex.h> 26#include <regex.h>
27 27
28#include "protocol.h" 28#include "protocol.h"
29#include "gns_glue.h"
29 30
30#define MAXEVENTS 64 31#define MAXEVENTS 64
31 32
@@ -40,12 +41,6 @@
40static struct MHD_Daemon *mhd_daemon; 41static struct MHD_Daemon *mhd_daemon;
41static regex_t re_dotplus; 42static regex_t re_dotplus;
42 43
43void
44gns_glue_expand_and_shorten ( char* sorig, char* new )
45{
46 memcpy (new, "foo.bar.gnunet", strlen("foo.bar.gnunet"));
47}
48
49static size_t 44static size_t
50curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls) 45curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls)
51{ 46{
@@ -60,6 +55,7 @@ curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls)
60 char* plusptr; 55 char* plusptr;
61 char* p; 56 char* p;
62 char new_host[256]; 57 char new_host[256];
58 char to_exp[256];
63 uint64_t bytes_copied = 0; 59 uint64_t bytes_copied = 0;
64 60
65 char new_buf[CURL_MAX_WRITE_SIZE+1]; 61 char new_buf[CURL_MAX_WRITE_SIZE+1];
@@ -103,13 +99,17 @@ curl_write_data (void *buffer, size_t size, size_t nmemb, void* cls)
103 99
104 if (m[1].rm_so != -1) 100 if (m[1].rm_so != -1)
105 { 101 {
106 hostptr = p+m[1].rm_eo; 102 hostptr = p+m[1].rm_so;
107 if (DEBUG) 103 if (DEBUG)
108 printf ("Copying %d bytes.\n", (hostptr-p)); 104 printf ("Copying %d bytes.\n", (hostptr-p));
109 memcpy (br->MHD_CURL_BUF+bytes_copied, p, (hostptr-p)); 105 memcpy (br->MHD_CURL_BUF+bytes_copied, p, (hostptr-p));
110 bytes_copied += (hostptr-p); 106 bytes_copied += (hostptr-p);
111 memset (new_host, 0, sizeof(new_host)); 107 memset (new_host, 0, sizeof(new_host));
112 gns_glue_expand_and_shorten ( br->full_url, 108 memset (to_exp, 0, sizeof (to_exp));
109 memcpy (to_exp, hostptr, (m[1].rm_eo-m[1].rm_so));
110
111 gns_glue_expand_and_shorten ( to_exp,
112 br->host,
113 new_host ); 113 new_host );
114 if (DEBUG) 114 if (DEBUG)
115 { 115 {
@@ -366,7 +366,7 @@ mhd_content_cb (void* cls,
366 return MHD_CONTENT_READER_END_OF_STREAM; 366 return MHD_CONTENT_READER_END_OF_STREAM;
367 } 367 }
368 pthread_mutex_unlock ( &br->m_done ); 368 pthread_mutex_unlock ( &br->m_done );
369 369
370 pthread_mutex_lock ( &br->m_buf ); 370 pthread_mutex_lock ( &br->m_buf );
371 if ( br->MHD_CURL_BUF_STATUS == BUF_WAIT_FOR_CURL ) 371 if ( br->MHD_CURL_BUF_STATUS == BUF_WAIT_FOR_CURL )
372 { 372 {
@@ -375,6 +375,8 @@ mhd_content_cb (void* cls,
375 return 0; 375 return 0;
376 } 376 }
377 377
378
379
378 if ( br->MHD_CURL_BUF_SIZE > max ) 380 if ( br->MHD_CURL_BUF_SIZE > max )
379 { 381 {
380 printf("buffer in mhd response too small!\n"); 382 printf("buffer in mhd response too small!\n");
@@ -389,6 +391,7 @@ mhd_content_cb (void* cls,
389 memcpy ( buf, br->MHD_CURL_BUF, br->MHD_CURL_BUF_SIZE ); 391 memcpy ( buf, br->MHD_CURL_BUF, br->MHD_CURL_BUF_SIZE );
390 } 392 }
391 br->MHD_CURL_BUF_STATUS = BUF_WAIT_FOR_CURL; 393 br->MHD_CURL_BUF_STATUS = BUF_WAIT_FOR_CURL;
394 curl_easy_pause (br->curl, CURLPAUSE_CONT);
392 pthread_mutex_unlock ( &br->m_buf ); 395 pthread_mutex_unlock ( &br->m_buf );
393 396
394 return br->MHD_CURL_BUF_SIZE; 397 return br->MHD_CURL_BUF_SIZE;
diff --git a/src/gns/gnocksy/gns_glue.c b/src/gns/gnocksy/gns_glue.c
new file mode 100644
index 000000000..25a6d0e83
--- /dev/null
+++ b/src/gns/gnocksy/gns_glue.c
@@ -0,0 +1,119 @@
1#include <stdio.h>
2#include <string.h>
3
4int
5gns_glue_get_auth ( char* name, char* auth )
6{
7 char cmd[1024];
8 char line[1024];
9 FILE *p;
10
11 sprintf (cmd, "%s %s", "gnunet-gns -a", name);
12
13 p = popen(cmd, "r");
14
15 if (p != NULL)
16 {
17 while (fgets (line, sizeof(line), p) != NULL)
18 {
19 if (line[strlen(line)-1] == '\n')
20 {
21 line[strlen(line)-1] = '\0';
22 strcpy (auth, line);
23 return 0;
24 }
25 }
26
27 }
28
29 fclose (p);
30
31 return -1;
32}
33
34int
35gns_glue_shorten ( char* name, char* shortened )
36{
37 char cmd[1024];
38 char line[1024];
39 FILE *p;
40
41 sprintf (cmd, "%s %s", "gnunet-gns -r -s", name);
42
43 p = popen(cmd, "r");
44
45 if (p != NULL)
46 {
47 while (fgets (line, sizeof(line), p) != NULL)
48 {
49 if (line[strlen(line)-1] == '\n')
50 {
51 line[strlen(line)-1] = '\0';
52 strcpy (shortened, line);
53 return 0;
54 }
55 }
56
57 }
58
59 fclose (p);
60
61 return -1;
62}
63
64int
65gns_glue_expand_and_shorten( char* to_expand, char* host, char* shortened )
66{
67 char cmd[1024];
68 char line[1024];
69 FILE *p;
70 char sorig[256];
71 char expanded[256];
72
73 sprintf (shortened, "%s%s", to_expand, host); //TODO this is a mockup
74 return 0;
75
76 sprintf (cmd, "%s %s", "gnunet-gns -a", host);
77
78 p = popen(cmd, "r");
79
80 if (p != NULL)
81 {
82 while (fgets (line, sizeof(line), p) != NULL)
83 {
84 if (line[strlen(line)-1] == '\n')
85 {
86 line[strlen(line)-1] = '\0';
87 strcpy (sorig, line);
88 return 0;
89 }
90 }
91
92 }
93
94 fclose (p);
95
96 sprintf (expanded, "%s.%s", to_expand, sorig);
97
98 sprintf (cmd, "%s %s", "gnunet-gns -r -s", expanded);
99
100 p = popen(cmd, "r");
101
102 if (p != NULL)
103 {
104 while (fgets (line, sizeof(line), p) != NULL)
105 {
106 if (line[strlen(line)-1] == '\n')
107 {
108 line[strlen(line)-1] = '\0';
109 strcpy (shortened, line);
110 return 0;
111 }
112 }
113
114 }
115
116 fclose (p);
117
118 return -1;
119}
diff --git a/src/gns/gnocksy/gns_glue.h b/src/gns/gnocksy/gns_glue.h
new file mode 100644
index 000000000..403a1a973
--- /dev/null
+++ b/src/gns/gnocksy/gns_glue.h
@@ -0,0 +1,10 @@
1int
2gns_glue_get_auth ( char* name, char* auth );
3
4int
5gns_glue_shorten ( char* name, char* shortened);
6
7int
8gns_glue_expand_and_shorten (char* to_expand,
9 char* host,
10 char* shortened);