aboutsummaryrefslogtreecommitdiff
path: root/src/hello/gnunet-hello.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hello/gnunet-hello.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hello/gnunet-hello.c')
-rw-r--r--src/hello/gnunet-hello.c179
1 files changed, 90 insertions, 89 deletions
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index 1b572b904..9f277de4a 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -29,7 +29,8 @@
29/** 29/**
30 * Closure for #add_to_buf(). 30 * Closure for #add_to_buf().
31 */ 31 */
32struct AddContext { 32struct AddContext
33{
33 /** 34 /**
34 * Where to add. 35 * Where to add.
35 */ 36 */
@@ -58,17 +59,17 @@ static int address_count;
58 * @return #GNUNET_OK keep iterating 59 * @return #GNUNET_OK keep iterating
59 */ 60 */
60static int 61static int
61add_to_buf(void *cls, 62add_to_buf (void *cls,
62 const struct GNUNET_HELLO_Address *address, 63 const struct GNUNET_HELLO_Address *address,
63 struct GNUNET_TIME_Absolute expiration) 64 struct GNUNET_TIME_Absolute expiration)
64{ 65{
65 struct AddContext *ac = cls; 66 struct AddContext *ac = cls;
66 size_t ret; 67 size_t ret;
67 68
68 ret = GNUNET_HELLO_add_address(address, 69 ret = GNUNET_HELLO_add_address (address,
69 GNUNET_TIME_UNIT_FOREVER_ABS, 70 GNUNET_TIME_UNIT_FOREVER_ABS,
70 ac->buf, 71 ac->buf,
71 ac->max); 72 ac->max);
72 ac->buf += ret; 73 ac->buf += ret;
73 ac->max -= ret; 74 ac->max -= ret;
74 ac->ret += ret; 75 ac->ret += ret;
@@ -86,7 +87,7 @@ add_to_buf(void *cls,
86 * @return number of bytes added, 0 to terminate 87 * @return number of bytes added, 0 to terminate
87 */ 88 */
88static ssize_t 89static ssize_t
89add_from_hello(void *cls, size_t max, void *buf) 90add_from_hello (void *cls, size_t max, void *buf)
90{ 91{
91 struct GNUNET_HELLO_Message **orig = cls; 92 struct GNUNET_HELLO_Message **orig = cls;
92 struct AddContext ac; 93 struct AddContext ac;
@@ -96,16 +97,16 @@ add_from_hello(void *cls, size_t max, void *buf)
96 ac.buf = buf; 97 ac.buf = buf;
97 ac.max = max; 98 ac.max = max;
98 ac.ret = 0; 99 ac.ret = 0;
99 GNUNET_assert( 100 GNUNET_assert (
100 NULL == 101 NULL ==
101 GNUNET_HELLO_iterate_addresses(*orig, GNUNET_NO, &add_to_buf, &ac)); 102 GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac));
102 *orig = NULL; 103 *orig = NULL;
103 return ac.ret; 104 return ac.ret;
104} 105}
105 106
106 107
107int 108int
108main(int argc, char *argv[]) 109main (int argc, char *argv[])
109{ 110{
110 struct GNUNET_DISK_FileHandle *fh; 111 struct GNUNET_DISK_FileHandle *fh;
111 struct GNUNET_HELLO_Message *orig; 112 struct GNUNET_HELLO_Message *orig;
@@ -115,98 +116,98 @@ main(int argc, char *argv[])
115 116
116 address_count = 0; 117 address_count = 0;
117 118
118 GNUNET_log_setup("gnunet-hello", "INFO", NULL); 119 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
119 if (argc != 2) 120 if (argc != 2)
120 { 121 {
121 fprintf(stderr, "%s", _("Call with name of HELLO file to modify.\n")); 122 fprintf (stderr, "%s", _ ("Call with name of HELLO file to modify.\n"));
122 return 1; 123 return 1;
123 } 124 }
124 if (GNUNET_OK != 125 if (GNUNET_OK !=
125 GNUNET_DISK_file_size(argv[1], &fsize, GNUNET_YES, GNUNET_YES)) 126 GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
126 { 127 {
127 fprintf(stderr, 128 fprintf (stderr,
128 _("Error accessing file `%s': %s\n"), 129 _ ("Error accessing file `%s': %s\n"),
129 argv[1], 130 argv[1],
130 strerror(errno)); 131 strerror (errno));
131 return 1; 132 return 1;
132 } 133 }
133 if (fsize > 65536) 134 if (fsize > 65536)
134 { 135 {
135 fprintf(stderr, _("File `%s' is too big to be a HELLO\n"), argv[1]); 136 fprintf (stderr, _ ("File `%s' is too big to be a HELLO\n"), argv[1]);
136 return 1; 137 return 1;
137 } 138 }
138 if (fsize < sizeof(struct GNUNET_MessageHeader)) 139 if (fsize < sizeof(struct GNUNET_MessageHeader))
139 { 140 {
140 fprintf(stderr, _("File `%s' is too small to be a HELLO\n"), argv[1]); 141 fprintf (stderr, _ ("File `%s' is too small to be a HELLO\n"), argv[1]);
141 return 1; 142 return 1;
142 } 143 }
143 fh = GNUNET_DISK_file_open(argv[1], 144 fh = GNUNET_DISK_file_open (argv[1],
144 GNUNET_DISK_OPEN_READ, 145 GNUNET_DISK_OPEN_READ,
145 GNUNET_DISK_PERM_USER_READ); 146 GNUNET_DISK_PERM_USER_READ);
146 if (NULL == fh) 147 if (NULL == fh)
147 { 148 {
148 fprintf(stderr, 149 fprintf (stderr,
149 _("Error opening file `%s': %s\n"), 150 _ ("Error opening file `%s': %s\n"),
150 argv[1], 151 argv[1],
151 strerror(errno)); 152 strerror (errno));
152 return 1; 153 return 1;
153 } 154 }
154 { 155 {
155 char buf[fsize] GNUNET_ALIGN; 156 char buf[fsize] GNUNET_ALIGN;
156 157
157 GNUNET_assert(fsize == GNUNET_DISK_file_read(fh, buf, fsize)); 158 GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize));
158 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 159 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
159 orig = (struct GNUNET_HELLO_Message *)buf; 160 orig = (struct GNUNET_HELLO_Message *) buf;
160 if ((fsize < GNUNET_HELLO_size(orig)) || 161 if ((fsize < GNUNET_HELLO_size (orig)) ||
161 (GNUNET_OK != GNUNET_HELLO_get_id(orig, &pid))) 162 (GNUNET_OK != GNUNET_HELLO_get_id (orig, &pid)))
162 { 163 {
163 fprintf(stderr, 164 fprintf (stderr,
164 _("Did not find well-formed HELLO in file `%s'\n"), 165 _ ("Did not find well-formed HELLO in file `%s'\n"),
165 argv[1]); 166 argv[1]);
166 return 1; 167 return 1;
167 } 168 }
168 { 169 {
169 char *pids; 170 char *pids;
170 171
171 pids = GNUNET_CRYPTO_eddsa_public_key_to_string(&pid.public_key); 172 pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key);
172 fprintf(stdout, "Processing HELLO for peer `%s'\n", pids); 173 fprintf (stdout, "Processing HELLO for peer `%s'\n", pids);
173 GNUNET_free(pids); 174 GNUNET_free (pids);
174 } 175 }
175 result = GNUNET_HELLO_create(&pid.public_key, 176 result = GNUNET_HELLO_create (&pid.public_key,
176 &add_from_hello, 177 &add_from_hello,
177 &orig, 178 &orig,
178 GNUNET_HELLO_is_friend_only(orig)); 179 GNUNET_HELLO_is_friend_only (orig));
179 GNUNET_assert(NULL != result); 180 GNUNET_assert (NULL != result);
180 fh = 181 fh =
181 GNUNET_DISK_file_open(argv[1], 182 GNUNET_DISK_file_open (argv[1],
182 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE, 183 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE,
183 GNUNET_DISK_PERM_USER_READ | 184 GNUNET_DISK_PERM_USER_READ
184 GNUNET_DISK_PERM_USER_WRITE); 185 | GNUNET_DISK_PERM_USER_WRITE);
185 if (NULL == fh) 186 if (NULL == fh)
186 { 187 {
187 fprintf(stderr, 188 fprintf (stderr,
188 _("Error opening file `%s': %s\n"), 189 _ ("Error opening file `%s': %s\n"),
189 argv[1], 190 argv[1],
190 strerror(errno)); 191 strerror (errno));
191 GNUNET_free(result); 192 GNUNET_free (result);
192 return 1; 193 return 1;
193 } 194 }
194 fsize = GNUNET_HELLO_size(result); 195 fsize = GNUNET_HELLO_size (result);
195 if (fsize != GNUNET_DISK_file_write(fh, result, fsize)) 196 if (fsize != GNUNET_DISK_file_write (fh, result, fsize))
196 { 197 {
197 fprintf(stderr, 198 fprintf (stderr,
198 _("Error writing HELLO to file `%s': %s\n"), 199 _ ("Error writing HELLO to file `%s': %s\n"),
199 argv[1], 200 argv[1],
200 strerror(errno)); 201 strerror (errno));
201 (void)GNUNET_DISK_file_close(fh); 202 (void) GNUNET_DISK_file_close (fh);
202 return 1; 203 return 1;
203 } 204 }
204 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 205 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
205 } 206 }
206 fprintf(stderr, 207 fprintf (stderr,
207 _("Modified %u addresses, wrote %u bytes\n"), 208 _ ("Modified %u addresses, wrote %u bytes\n"),
208 address_count, 209 address_count,
209 (unsigned int)fsize); 210 (unsigned int) fsize);
210 return 0; 211 return 0;
211} 212}
212 213