aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnocksy/gns_glue.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnocksy/gns_glue.c')
-rw-r--r--src/gns/gnocksy/gns_glue.c119
1 files changed, 119 insertions, 0 deletions
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}