#include <regex.h>
#include "protocol.h"
+#include "gns_glue.h"
#define MAXEVENTS 64
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)
{
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];
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)
{
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 )
{
return 0;
}
+
+
if ( br->MHD_CURL_BUF_SIZE > max )
{
printf("buffer in mhd response too small!\n");
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;
--- /dev/null
+#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;
+}
--- /dev/null
+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);