Skip to content

Commit fd934be

Browse files
committed
Resync
1 parent b69a133 commit fd934be

File tree

3 files changed

+298
-17
lines changed

3 files changed

+298
-17
lines changed

include/lists/string_list.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ bool string_split_noalloc(struct string_list *list,
104104
*/
105105
struct string_list *string_separate(char *str, const char *delim);
106106

107+
bool string_separate_noalloc(struct string_list *list,
108+
char *str, const char *delim);
109+
107110
bool string_list_deinitialize(struct string_list *list);
108111

109112
bool string_list_initialize(struct string_list *list);

lists/string_list.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,39 @@ struct string_list *string_separate(char *str, const char *delim)
411411
return NULL;
412412
}
413413

414+
bool string_separate_noalloc(
415+
struct string_list *list,
416+
char *str, const char *delim)
417+
{
418+
char *token = NULL;
419+
char **str_ptr = NULL;
420+
421+
/* Sanity check */
422+
if (!str || string_is_empty(delim) || !list)
423+
return false;
424+
425+
str_ptr = &str;
426+
token = string_tokenize(str_ptr, delim);
427+
428+
while (token)
429+
{
430+
union string_list_elem_attr attr;
431+
432+
attr.i = 0;
433+
434+
if (!string_list_append(list, token, attr))
435+
{
436+
free(token);
437+
return false;
438+
}
439+
440+
free(token);
441+
token = string_tokenize(str_ptr, delim);
442+
}
443+
444+
return true;
445+
}
446+
414447
/**
415448
* string_list_find_elem:
416449
* @list : pointer to string list

net/net_http.c

Lines changed: 262 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,277 @@ struct http_connection_t
9191
caller is responsible for deleting the destination buffer */
9292
void net_http_urlencode(char **dest, const char *source)
9393
{
94-
/* TODO/FIXME - static local globals */
95-
static char urlencode_lut[256];
96-
static bool urlencode_lut_inited = false;
94+
static const char urlencode_lut[256] =
95+
{
96+
0, /* 0 */
97+
0, /* 1 */
98+
0, /* 2 */
99+
0, /* 3 */
100+
0, /* 4 */
101+
0, /* 5 */
102+
0, /* 6 */
103+
0, /* 7 */
104+
0, /* 8 */
105+
0, /* 9 */
106+
0, /* 10 */
107+
0, /* 11 */
108+
0, /* 12 */
109+
0, /* 13 */
110+
0, /* 14 */
111+
0, /* 15 */
112+
0, /* 16 */
113+
0, /* 17 */
114+
0, /* 18 */
115+
0, /* 19 */
116+
0, /* 20 */
117+
0, /* 21 */
118+
0, /* 22 */
119+
0, /* 23 */
120+
0, /* 24 */
121+
0, /* 25 */
122+
0, /* 26 */
123+
0, /* 27 */
124+
0, /* 28 */
125+
0, /* 29 */
126+
0, /* 30 */
127+
0, /* 31 */
128+
0, /* 32 */
129+
0, /* 33 */
130+
0, /* 34 */
131+
0, /* 35 */
132+
0, /* 36 */
133+
0, /* 37 */
134+
0, /* 38 */
135+
0, /* 39 */
136+
0, /* 40 */
137+
0, /* 41 */
138+
'*', /* 42 */
139+
0, /* 43 */
140+
0, /* 44 */
141+
'-', /* 45 */
142+
'.', /* 46 */
143+
'/', /* 47 */
144+
'0', /* 48 */
145+
'1', /* 49 */
146+
'2', /* 50 */
147+
'3', /* 51 */
148+
'4', /* 52 */
149+
'5', /* 53 */
150+
'6', /* 54 */
151+
'7', /* 55 */
152+
'8', /* 56 */
153+
'9', /* 57 */
154+
0, /* 58 */
155+
0, /* 59 */
156+
0, /* 60 */
157+
0, /* 61 */
158+
0, /* 62 */
159+
0, /* 63 */
160+
0, /* 64 */
161+
'A', /* 65 */
162+
'B', /* 66 */
163+
'C', /* 67 */
164+
'D', /* 68 */
165+
'E', /* 69 */
166+
'F', /* 70 */
167+
'G', /* 71 */
168+
'H', /* 72 */
169+
'I', /* 73 */
170+
'J', /* 74 */
171+
'K', /* 75 */
172+
'L', /* 76 */
173+
'M', /* 77 */
174+
'N', /* 78 */
175+
'O', /* 79 */
176+
'P', /* 80 */
177+
'Q', /* 81 */
178+
'R', /* 82 */
179+
'S', /* 83 */
180+
'T', /* 84 */
181+
'U', /* 85 */
182+
'V', /* 86 */
183+
'W', /* 87 */
184+
'X', /* 88 */
185+
'Y', /* 89 */
186+
'Z', /* 90 */
187+
0, /* 91 */
188+
0, /* 92 */
189+
0, /* 93 */
190+
0, /* 94 */
191+
'_', /* 95 */
192+
0, /* 96 */
193+
'a', /* 97 */
194+
'b', /* 98 */
195+
'c', /* 99 */
196+
'd', /* 100 */
197+
'e', /* 101 */
198+
'f', /* 102 */
199+
'g', /* 103 */
200+
'h', /* 104 */
201+
'i', /* 105 */
202+
'j', /* 106 */
203+
'k', /* 107 */
204+
'l', /* 108 */
205+
'm', /* 109 */
206+
'n', /* 110 */
207+
'o', /* 111 */
208+
'p', /* 112 */
209+
'q', /* 113 */
210+
'r', /* 114 */
211+
's', /* 115 */
212+
't', /* 116 */
213+
'u', /* 117 */
214+
'v', /* 118 */
215+
'w', /* 119 */
216+
'x', /* 120 */
217+
'y', /* 121 */
218+
'z', /* 122 */
219+
0, /* 123 */
220+
0, /* 124 */
221+
0, /* 125 */
222+
0, /* 126 */
223+
0, /* 127 */
224+
0, /* 128 */
225+
0, /* 129 */
226+
0, /* 130 */
227+
0, /* 131 */
228+
0, /* 132 */
229+
0, /* 133 */
230+
0, /* 134 */
231+
0, /* 135 */
232+
0, /* 136 */
233+
0, /* 137 */
234+
0, /* 138 */
235+
0, /* 139 */
236+
0, /* 140 */
237+
0, /* 141 */
238+
0, /* 142 */
239+
0, /* 143 */
240+
0, /* 144 */
241+
0, /* 145 */
242+
0, /* 146 */
243+
0, /* 147 */
244+
0, /* 148 */
245+
0, /* 149 */
246+
0, /* 150 */
247+
0, /* 151 */
248+
0, /* 152 */
249+
0, /* 153 */
250+
0, /* 154 */
251+
0, /* 155 */
252+
0, /* 156 */
253+
0, /* 157 */
254+
0, /* 158 */
255+
0, /* 159 */
256+
0, /* 160 */
257+
0, /* 161 */
258+
0, /* 162 */
259+
0, /* 163 */
260+
0, /* 164 */
261+
0, /* 165 */
262+
0, /* 166 */
263+
0, /* 167 */
264+
0, /* 168 */
265+
0, /* 169 */
266+
0, /* 170 */
267+
0, /* 171 */
268+
0, /* 172 */
269+
0, /* 173 */
270+
0, /* 174 */
271+
0, /* 175 */
272+
0, /* 176 */
273+
0, /* 177 */
274+
0, /* 178 */
275+
0, /* 179 */
276+
0, /* 180 */
277+
0, /* 181 */
278+
0, /* 182 */
279+
0, /* 183 */
280+
0, /* 184 */
281+
0, /* 185 */
282+
0, /* 186 */
283+
0, /* 187 */
284+
0, /* 188 */
285+
0, /* 189 */
286+
0, /* 190 */
287+
0, /* 191 */
288+
0, /* 192 */
289+
0, /* 193 */
290+
0, /* 194 */
291+
0, /* 195 */
292+
0, /* 196 */
293+
0, /* 197 */
294+
0, /* 198 */
295+
0, /* 199 */
296+
0, /* 200 */
297+
0, /* 201 */
298+
0, /* 202 */
299+
0, /* 203 */
300+
0, /* 204 */
301+
0, /* 205 */
302+
0, /* 206 */
303+
0, /* 207 */
304+
0, /* 208 */
305+
0, /* 209 */
306+
0, /* 210 */
307+
0, /* 211 */
308+
0, /* 212 */
309+
0, /* 213 */
310+
0, /* 214 */
311+
0, /* 215 */
312+
0, /* 216 */
313+
0, /* 217 */
314+
0, /* 218 */
315+
0, /* 219 */
316+
0, /* 220 */
317+
0, /* 221 */
318+
0, /* 222 */
319+
0, /* 223 */
320+
0, /* 224 */
321+
0, /* 225 */
322+
0, /* 226 */
323+
0, /* 227 */
324+
0, /* 228 */
325+
0, /* 229 */
326+
0, /* 230 */
327+
0, /* 231 */
328+
0, /* 232 */
329+
0, /* 233 */
330+
0, /* 234 */
331+
0, /* 235 */
332+
0, /* 236 */
333+
0, /* 237 */
334+
0, /* 238 */
335+
0, /* 239 */
336+
0, /* 240 */
337+
0, /* 241 */
338+
0, /* 242 */
339+
0, /* 243 */
340+
0, /* 244 */
341+
0, /* 245 */
342+
0, /* 246 */
343+
0, /* 247 */
344+
0, /* 248 */
345+
0, /* 249 */
346+
0, /* 250 */
347+
0, /* 251 */
348+
0, /* 252 */
349+
0, /* 253 */
350+
0, /* 254 */
351+
0 /* 255 */
352+
};
97353

98-
char *enc = NULL;
99354
/* Assume every character will be encoded, so we need 3 times the space. */
100355
size_t len = strlen(source) * 3 + 1;
101356
size_t count = len;
102-
103-
if (!urlencode_lut_inited)
104-
{
105-
unsigned i;
106-
107-
for (i = 0; i < 256; i++)
108-
urlencode_lut[i] = isalnum(i) || i == '*' || i == '-' || i == '.' || i == '_' || i == '/' ? i : 0;
109-
urlencode_lut_inited = true;
110-
}
111-
112-
enc = (char*)calloc(1, len);
113-
*dest = enc;
357+
char *enc = (char*)calloc(1, len);
358+
*dest = enc;
114359

115360
for (; *source; source++)
116361
{
117362
int written = 0;
118363

119-
/* any non-ascii character will just be encoded without question */
364+
/* any non-ASCII character will just be encoded without question */
120365
if ((unsigned)*source < sizeof(urlencode_lut) && urlencode_lut[(unsigned)*source])
121366
written = snprintf(enc, count, "%c", urlencode_lut[(unsigned)*source]);
122367
else

0 commit comments

Comments
 (0)