struct grecs_sockaddr * grecs_sockaddr_new(size_t s) { struct grecs_sockaddr *sp = grecs_malloc(sizeof(*sp)); sp->next = NULL; sp->sa = grecs_zalloc(s); sp->len = s; return sp; }
static struct grecs_value * parse_label(const char *str) { struct grecs_value *val = NULL; size_t i; struct wordsplit ws; size_t len = strlen (str); if (len > 1 && str[0] == '(' && str[len-1] == ')') { struct grecs_list *lst; ws.ws_delim = ","; if (wordsplit_len (str + 1, len - 2, &ws, WRDSF_DEFFLAGS|WRDSF_DELIM| WRDSF_WS)) { return NULL; } lst = grecs_value_list_create(); for (i = 0; i < ws.ws_wordc; i++) { struct grecs_value *p = grecs_zalloc(sizeof(*p)); p->type = GRECS_TYPE_STRING; p->v.string = ws.ws_wordv[i]; grecs_list_append(lst, p); } val = grecs_malloc(sizeof(*val)); val->type = GRECS_TYPE_LIST; val->v.list = lst; } else { if (wordsplit(str, &ws, WRDSF_DEFFLAGS)) return NULL; val = grecs_zalloc(sizeof(*val)); if (ws.ws_wordc == 1) { val->type = GRECS_TYPE_STRING; val->v.string = ws.ws_wordv[0]; } else { val->type = GRECS_TYPE_ARRAY; val->v.arg.c = ws.ws_wordc; val->v.arg.v = grecs_calloc(ws.ws_wordc, sizeof(val->v.arg.v[0])); for (i = 0; i < ws.ws_wordc; i++) { val->v.arg.v[i] = grecs_zalloc(sizeof(*val->v.arg.v[0])); val->v.arg.v[i]->type = GRECS_TYPE_STRING; val->v.arg.v[i]->v.string = ws.ws_wordv[i]; } } } ws.ws_wordc = 0; wordsplit_free(&ws); return val; }
void grecs_format_value(struct grecs_value *val, int flags, struct grecs_format_closure *clos) { int i; struct grecs_list_entry *ep; size_t clen; int need_quote; if (!val) return; switch (val->type) { case GRECS_TYPE_STRING: clen = wordsplit_c_quoted_length(val->v.string, flags & GRECS_NODE_FLAG_QUOTE_HEX, &need_quote); if (flags & GRECS_NODE_FLAG_QUOTE) need_quote = 1; else if (flags & GRECS_NODE_FLAG_NOQUOTE) need_quote = 0; if (need_quote) { char *cbuf = grecs_malloc(clen + 1); wordsplit_c_quote_copy(cbuf, val->v.string, flags & GRECS_NODE_FLAG_QUOTE_HEX); cbuf[clen] = 0; clos->fmtfun("\"", clos->data); clos->fmtfun(cbuf, clos->data); clos->fmtfun("\"", clos->data); grecs_free(cbuf); } else clos->fmtfun(val->v.string, clos->data); break; case GRECS_TYPE_LIST: clos->fmtfun("(", clos->data); for (ep = val->v.list->head; ep; ep = ep->next) { grecs_format_value(ep->data, flags, clos); if (ep->next) clos->fmtfun(", ", clos->data); } clos->fmtfun(")", clos->data); break; case GRECS_TYPE_ARRAY: for (i = 0; i < val->v.arg.c; i++) { if (i) clos->fmtfun(" ", clos->data); grecs_format_value(val->v.arg.v[i], flags, clos); } } }
static int parse_inet(struct grecs_sockaddr **ret, int family, const char *arg, const char *addrstr, struct grecs_sockaddr_hints *gh, grecs_locus_t const *locus) { int rc; struct addrinfo hints; struct addrinfo *res, *ap; const char *node = NULL; char *nodebuf = NULL; const char *service = NULL; struct grecs_sockaddr *head = NULL, *tail = NULL; char portbuf[64]; memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = SOCK_STREAM; if ((family == AF_INET6 || family == AF_UNSPEC) && addrstr[0] == '[') { char *p = strchr(addrstr + 1, ']'); if (p && p > addrstr + 1) { size_t len; addrstr++; len = p - addrstr; nodebuf = grecs_malloc(len + 1); memcpy(nodebuf, addrstr, len); nodebuf[len] = 0; node = nodebuf; service = p + 1; family = AF_INET6; } else service = strchr(addrstr, ':'); } else service = strrchr(addrstr, ':'); if (service && *service) { if (*service != ':') { grecs_error(locus, 0, _("%s: garbage near %s"), arg, service); return -1; } service++; } if (!node) { if (service) { size_t len = service - addrstr - 1; if (len == 0) node = NULL; else { nodebuf = grecs_malloc(len + 1); memcpy(nodebuf, addrstr, len); nodebuf[len] = 0; node = nodebuf; } } else { if (grecs_str_is_ipaddr(addrstr)) node = addrstr; else if (grecs_str_is_num(addrstr)) { service = addrstr; hints.ai_flags |= AI_NUMERICSERV; } } } if (!service || !*service) { if (!node && addrstr[0]) node = addrstr; if (gh->flags & GRECS_HINT_SERVICE) { service = gh->service; } else if (gh->flags & GRECS_HINT_PORT) { snprintf(portbuf, sizeof portbuf, "%hu", gh->port); service = portbuf; hints.ai_flags |= AI_NUMERICSERV; } else if (!(gh->flags & GRECS_AH_PASSIVE)) { grecs_error(locus, 0, _("service not specified: %s"), arg); return -1; } } if (!node) { if (gh->flags & GRECS_AH_PASSIVE) hints.ai_flags |= AI_PASSIVE; } rc = getaddrinfo(node, service, &hints, &res); free(nodebuf); switch (rc) { case 0: break; case EAI_SYSTEM: grecs_error(locus, 0, _("%s: cannot parse address: %s"), arg, strerror(errno)); break; case EAI_BADFLAGS: case EAI_SOCKTYPE: grecs_error(locus, 0, "%s:%d: internal error converting %s", __FILE__,__LINE__,arg); break; case EAI_MEMORY: grecs_alloc_die(); default: grecs_error(locus, 0, "%s: %s", arg, gai_strerror(rc)); return -1; } for (ap = res; ap; ap = ap->ai_next) { if (family == AF_UNSPEC || ap->ai_addr->sa_family == family) { struct grecs_sockaddr *sp = grecs_sockaddr_new(ap->ai_addrlen); memcpy(sp->sa, ap->ai_addr, ap->ai_addrlen); sp->len = ap->ai_addrlen; if (!head) head = sp; else tail->next = sp; tail = sp; } } freeaddrinfo(res); *ret = head; return 0; }
void get_options(int argc, char *argv[], struct dicod_conf_override *conf) { #line 176 { #line 176 int c; #line 176 #line 176 #ifdef HAVE_GETOPT_LONG #line 176 while ((c = getopt_long(argc, argv, "EtifsTx:I:D:hV", #line 176 long_options, NULL)) != EOF) #line 176 #else #line 176 while ((c = getopt(argc, argv, "EtifsTx:I:D:hV")) != EOF) #line 176 #endif #line 176 { #line 176 switch (c) #line 176 { #line 176 default: #line 176 exit(EX_USAGE); exit(EX_USAGE); #line 176 #line 38 "cmdline.opt" case 'E': #line 38 { #line 38 mode = MODE_PREPROC; #line 40 break; #line 40 } #line 44 "cmdline.opt" case 't': #line 44 { #line 44 config_lint_option = 1; #line 46 break; #line 46 } #line 50 "cmdline.opt" case 'i': #line 50 { #line 50 mode = MODE_INETD; #line 52 break; #line 52 } #line 58 "cmdline.opt" case OPTION_CONFIG: #line 58 { #line 58 config_file = optarg; #line 60 break; #line 60 } #line 64 "cmdline.opt" case 'f': #line 64 { #line 64 foreground = 1; #line 66 break; #line 66 } #line 70 "cmdline.opt" case OPTION_STDERR: #line 70 { #line 70 log_to_stderr = 1; #line 72 break; #line 72 } #line 76 "cmdline.opt" case OPTION_SYSLOG: #line 76 { #line 76 log_to_stderr = 0; #line 78 break; #line 78 } #line 82 "cmdline.opt" case 's': #line 82 { #line 82 single_process = 1; #line 84 break; #line 84 } #line 90 "cmdline.opt" case 'T': #line 90 { #line 90 conf->transcript = 1; #line 92 break; #line 92 } #line 96 "cmdline.opt" case OPTION_NO_TRANSCRIPT: #line 96 { #line 96 conf->transcript = 0; #line 98 break; #line 98 } #line 102 "cmdline.opt" case 'x': #line 102 { #line 102 debug_level_str = optarg; debug_level = atoi(optarg); #line 105 break; #line 105 } #line 109 "cmdline.opt" case OPTION_SOURCE_INFO: #line 109 { #line 109 debug_source_info = 1; #line 111 break; #line 111 } #line 115 "cmdline.opt" case OPTION_TRACE_GRAMMAR: #line 115 { #line 115 grecs_gram_trace(1); #line 117 break; #line 117 } #line 121 "cmdline.opt" case OPTION_TRACE_LEX: #line 121 { #line 121 grecs_lex_trace(1); #line 123 break; #line 123 } #line 129 "cmdline.opt" case OPTION_CONFIG_HELP: #line 129 { #line 129 config_help(); exit(0); #line 132 break; #line 132 } #line 138 "cmdline.opt" case OPTION_PREPROCESSOR: #line 138 { #line 138 grecs_preprocessor = optarg; #line 140 break; #line 140 } #line 144 "cmdline.opt" case OPTION_NO_PREPROCESSOR: #line 144 { #line 144 grecs_preprocessor = NULL; #line 146 break; #line 146 } #line 150 "cmdline.opt" case 'I': #line 150 { #line 150 grecs_preproc_add_include_dir(optarg); #line 152 break; #line 152 } #line 156 "cmdline.opt" case 'D': #line 156 { #line 156 char *p; if (!pp_cmd_acc) pp_cmd_acc = grecs_txtacc_create(); grecs_txtacc_grow(pp_cmd_acc, " \"-D", 4); for (p = optarg; *p; p++) { if (*p == '\\' || *p == '"') grecs_txtacc_grow_char(pp_cmd_acc, '\\'); grecs_txtacc_grow_char(pp_cmd_acc, *p); } grecs_txtacc_grow_char(pp_cmd_acc, '"'); #line 168 break; #line 168 } #line 171 "cmdline.opt" case 'h': #line 171 { #line 171 #line 171 print_help (); #line 171 exit (0); #line 171 #line 171 break; #line 171 } #line 171 "cmdline.opt" case OPTION_USAGE: #line 171 { #line 171 #line 171 print_usage (); #line 171 exit (0); #line 171 #line 171 break; #line 171 } #line 171 "cmdline.opt" case 'V': #line 171 { #line 171 #line 171 /* Give version */ #line 171 print_version(program_version, stdout); #line 171 exit (0); #line 171 #line 171 break; #line 171 } #line 176 "cmdline.opt" } #line 176 } #line 176 #line 176 if (optind < argc) { #line 176 fprintf(stderr, "%s: unexpected arguments\n", argv[0]); #line 176 exit(EX_USAGE); #line 176 } #line 176 #line 176 if (cmdline_tree) #line 176 { #line 176 struct grecs_node *rn = grecs_node_create(grecs_node_root, NULL); #line 176 rn->down = cmdline_tree; #line 176 cmdline_tree = rn; #line 176 } #line 176 } #line 176 if (pp_cmd_acc && grecs_preprocessor) { char *args, *cmd; grecs_txtacc_grow_char(pp_cmd_acc, 0); args = grecs_txtacc_finish(pp_cmd_acc, 0); cmd = grecs_malloc(strlen(grecs_preprocessor) + strlen(args) + 1); strcpy(cmd, grecs_preprocessor); strcat(cmd, args); grecs_preprocessor = cmd; } grecs_txtacc_free(pp_cmd_acc); }