int store_setting(struct p_parser *p, char *buf, int start, int end){ struct p_label *l; struct p_setting *s; int len; s = malloc(sizeof(struct p_setting)); if (s == NULL) return FAIL; s->values = NULL; s->vcount = 0; s->str = NULL; s->comments = NULL; s->comcount = 0; len = end - start; s->str = malloc(sizeof(char)*len+1); if(s->str == NULL){ free(s); return FAIL; } s->str = memcpy(s->str,buf+start,len); s->str[len] = '\0'; s->str = rm_whitespace(s->str); #ifdef DEBUG fprintf(stderr,"SETTING: {%s}\n",s->str); #endif l = p->labels[p->lcount-1]; l->settings = realloc(l->settings,sizeof(struct p_setting*)*(++l->scount)); l->settings[l->scount-1] = s; return OKAY; }
int store_value(struct p_parser *p, char *buf, int start, int end){ struct p_label *l; struct p_setting *s; struct p_value *v; int len; v = malloc(sizeof(struct p_value)); if (v == NULL) return FAIL; v->str = NULL; len = end - start; v->str = malloc(sizeof(char)*len+1); if(v->str == NULL){ free(v); return FAIL; } v->str = memcpy(v->str,buf+start,len); v->str[len] = '\0'; if (p->state == S_VALUE) v->str = rm_whitespace(v->str); #ifdef DEBUG fprintf(stderr,"VALUE: (%s)\n",v->str); #endif l = p->labels[p->lcount-1]; s = l->settings[l->scount-1]; s->values = realloc(s->values,sizeof(struct p_values*)*(++s->vcount)); s->values[s->vcount-1] = v; return OKAY; }
int store_label(struct p_parser *p, char *buf, int start, int end){ struct p_label *l; int len; l = malloc(sizeof(struct p_label)); if (l == NULL) return FAIL; l->settings = NULL; l->scount = 0; l->str = NULL; l->comments = NULL; l->comcount = 0; len = end - start; l->str = malloc(sizeof(char)*len+1); if (l->str == NULL){ free(l); return FAIL; } l->str = memcpy(l->str,buf+start,len); l->str[len] = '\0'; l->str = rm_whitespace(l->str); #ifdef DEBUG fprintf(stderr,"LABEL: [%s]\n",l->str); #endif p->labels = realloc(p->labels,sizeof(struct p_label*)*(++p->lcount)); p->labels[p->lcount-1] = l; return OKAY; }
void adjust_host(Config *cfg) { /* * Trim leading whitespace off the hostname if it's there. */ ltrim(cfg->host); /* See if host is of the form user@host */ takeout_username_from_host(cfg); /* * Trim a colon suffix off the hostname if it's there. In * order to protect IPv6 address literals against this * treatment, we do not do this if there's _more_ than one * colon. */ handle_host_colon(cfg->host); /* * Remove any remaining whitespace from the hostname. */ rm_whitespace(cfg->host); }