MCPcopy Create free account
hub / github.com/RsyncProject/rsync / parse_nni_str

Function parse_nni_str

compat.c:283–331  ·  view source on GitHub ↗

Simplify the user-provided string so that it contains valid names without any duplicates. * It also sets the "saw" flags to a 1-relative count of which name was seen first. */

Source from the content-addressed store, hash-verified

281/* Simplify the user-provided string so that it contains valid names without any duplicates.
282 * It also sets the "saw" flags to a 1-relative count of which name was seen first. */
283static int parse_nni_str(struct name_num_obj *nno, const char *from, char *tobuf, int tobuf_len)
284{
285 char *to = tobuf, *tok = NULL;
286 int saw_tok = 0, cnt = 0;
287
288 while (1) {
289 int at_space = isSpace(from);
290 char ch = *from++;
291 if (ch == '&')
292 ch = '\0';
293 if (!ch || at_space) {
294 if (tok) {
295 struct name_num_item *nni = get_nni_by_name(nno, tok, to - tok);
296 if (nni && !nno->saw[nni->num]) {
297 nno->saw[nni->num] = ++cnt;
298 if (nni->main_nni) {
299 to = tok + strlcpy(tok, nni->main_nni->name, tobuf_len - (tok - tobuf));
300 if (to - tobuf >= tobuf_len) {
301 to = tok - 1;
302 break;
303 }
304 }
305 } else
306 to = tok - (tok != tobuf);
307 saw_tok = 1;
308 tok = NULL;
309 }
310 if (!ch)
311 break;
312 continue;
313 }
314 if (!tok) {
315 if (to != tobuf)
316 *to++ = ' ';
317 tok = to;
318 }
319 if (to - tobuf >= tobuf_len - 1) {
320 to = tok - (tok != tobuf);
321 break;
322 }
323 *to++ = ch;
324 }
325 *to = '\0';
326
327 if (saw_tok && to == tobuf)
328 return strlcpy(tobuf, "INVALID", MAX_NSTR_STRLEN);
329
330 return to - tobuf;
331}
332
333static int parse_negotiate_str(struct name_num_obj *nno, char *tmpbuf)
334{

Callers 2

validate_choice_vs_envFunction · 0.85
send_negotiate_strFunction · 0.85

Calls 3

isSpaceFunction · 0.85
get_nni_by_nameFunction · 0.85
strlcpyFunction · 0.85

Tested by

no test coverage detected