static struct confline *parse_syslogng_items(struct cnfnode *cn_top, struct confline *cl, const char **pp) { struct cnfnode *cn; char buf[256], *q; const char *p = *pp; while(1){ q = buf; while(*p && (isalnum(*p) || (*p == '_') || (*p == '-'))) *q++ = *p++; *q = 0; append_node(cn_top, cn = create_cnfnode(buf)); cl = _skip_spaces(cl, &p); if(*p == '('){ p++; cl = _skip_spaces(cl, &p); q = buf; if((*p == '\"' || *p == '\'') && (p[-1] != '\\')){ char qc = *p; *q++ = *p++; while(*p && ((*p != qc) || (p[-1] == '\\'))&& q < buf+sizeof(buf)-1){ *q++ = *p; cl = next_char(cl, &p); } if(*p == qc) *q++ = *p++; }else{ while(*p && !isspace(*p) && *p != '(' && *p != ')' && q < buf+sizeof(buf)-1){ *q++ = *p; cl = next_char(cl, &p); } } *q = 0; cl = _skip_spaces(cl, &p); if(*p == ')') p++; cnfnode_setval(cn, buf); cl = _skip_spaces(cl, &p); } if(*p == ')'){ p++; break; } } *pp = p; return cl; }
static gboolean _parse_transport_info(SnmpTrapdHeaderParser *self) { if(!scan_expect_char(self->input, (gint *) self->input_len, '[')) return FALSE; _skip_spaces(self); const gchar *transport_info_start = *self->input; const gchar *transport_info_end = strchr(transport_info_start, '\n'); if (!transport_info_end) return FALSE; while(*transport_info_end != ']') { --transport_info_end; if(transport_info_end == transport_info_start) return FALSE; } gsize transport_info_len = transport_info_end - transport_info_start; snmptrapd_nv_context_add_name_value(self->nv_context, "transport_info", transport_info_start, transport_info_len); *self->input_len -= (transport_info_end + 1) - *self->input; *self->input = transport_info_end + 1; return TRUE; }
struct cnfnode *parse_syslogng(struct cnfmodule *cm, FILE *fptr) { struct cnfnode *cn_top, *cn_root; struct confline *cl, *cl_root; cl_root = read_conflines(fptr); cn_root = create_cnfnode("(root)"); for(cl = cl_root; cl;){ const char *p = cl->line; char buf[256]; cl = _skip_spaces(cl, &p); if(!*p) break; if(*p){ dup_next_word_b(&p, buf, sizeof(buf)-1); append_node(cn_root, cn_top = create_cnfnode(buf)); if((strcmp(buf, "options") == 0) || (strcmp(buf, "log") == 0)){ cl = parse_syslogng_options(cn_top, cl, p); }else if((strcmp(buf, "source") == 0) || (strcmp(buf, "destination") == 0)){ struct cnfnode *cn_top1; cl = _skip_spaces(cl, &p); dup_next_word_b(&p, buf, sizeof(buf)-1); append_node(cn_top, cn_top1 = create_cnfnode(buf)); cl = parse_syslogng_options(cn_top1, cl, p); }else if(strcmp(buf, "filter") == 0){ struct cnfnode *cn_top1; cl = _skip_spaces(cl, &p); dup_next_word_b(&p, buf, sizeof(buf)-1); append_node(cn_top, cn_top1 = create_cnfnode(buf)); cl = parse_syslogng_filter(cn_top1, cl, p); } if(cl) cl = cl->next; } } destroy_confline_list(cl_root); return cn_root; }
static struct confline *parse_syslogng_filter(struct cnfnode *cn_top, struct confline *cl, const char *p) { char buf[256], *q; cl = _skip_spaces(cl, &p); if(*p == '{'){ p++; cl = _skip_spaces(cl, &p); q = buf; while(*p && *p != ';' && q < buf+sizeof(buf)-1){ *q++ = *p; cl = next_char(cl, &p); } *q++ = *p; /* should be the ';' */ *q = 0; cnfnode_setval(cn_top, buf); cl = _skip_spaces(cl, &p); /* get to the end of the filter line; p == '}' */ } return cl; }
static gboolean _run_header_parser(SnmpTrapdHeaderParser *self, SnmpTrapdHeaderParserStep *parser_steps, gsize parser_steps_size) { SnmpTrapdHeaderParserStep parser_step; for (gsize step_index = 0; step_index < parser_steps_size; ++step_index) { _skip_spaces(self); parser_step = parser_steps[step_index]; if (!parser_step(self)) return FALSE; } return TRUE; }
static gboolean _parse_v1_uptime(SnmpTrapdHeaderParser *self) { if (!scan_expect_str(self->input, (gint *) self->input_len, "Uptime:")) return FALSE; _skip_spaces(self); const gchar *uptime_start = *self->input; const gchar *uptime_end = strchr(uptime_start, '\n'); if (!uptime_end) { _scroll_to_eom(self); snmptrapd_nv_context_add_name_value(self->nv_context, "uptime", uptime_start, *self->input - uptime_start); return TRUE; } snmptrapd_nv_context_add_name_value(self->nv_context, "uptime", uptime_start, uptime_end - uptime_start); *self->input_len -= uptime_end - *self->input; *self->input = uptime_end; return TRUE; }
static char *_validate_sig(char *sig) { /* this function first tries to force signature to conform and failing that returns NULL */ /* this stuff is very messy - I know! Needs *SERIOUS* work!!!! */ static char final_sig[1024]; memset( final_sig, 0, sizeof( final_sig) ); char *ptr = sig; char *f_sig_ptr = final_sig; /* skip spaces at start */ _skip_spaces( &ptr ); /* check for open bracket */ if( *ptr != '(' ) return NULL; *(f_sig_ptr++) = *(ptr++); /* skip spaces */ _skip_spaces( &ptr ); /* loop until closing bracket */ while( *ptr != ')' ) { /* truncate spaces to a single one between items */ _truncate_spaces( &ptr ); /* handle if '*' */ if( *ptr == '*' && *(ptr - 1) != ' ' ) *(f_sig_ptr++) = ' '; *(f_sig_ptr++) = *(ptr++); } /* skip trailing space before bracket */ if( *(f_sig_ptr - 1) == ' ' ) f_sig_ptr--; *(f_sig_ptr++) = *ptr; /* skip spaces */ _skip_spaces( &ptr ); ptr++; /* check for open bracket */ if( *ptr != '(' ) return NULL; *(f_sig_ptr++) = *(ptr++); /* loop until closing bracket */ while( *ptr != ')' ) { /* skip spaces after bracket */ if( *(ptr - 1) == '(' ) _skip_spaces( &ptr ); /* truncate spaces to a single one between items */ _truncate_spaces( &ptr ); /* make sure there is a space before '*' */ if( *ptr == '*' && *(ptr - 1) != ' ' ) *(f_sig_ptr++) = ' '; /* skip space after '*' */ if( *ptr == '*' && *(ptr + 1) == ' ' ) { ptr++; _skip_spaces( &ptr ); *(f_sig_ptr++) = '*'; continue; } /* skip space before comma */ if( *ptr == ' ' && *(ptr + 1) == ',' ) ptr++; /* make sure there is a space after comma */ if( *(ptr - 1) == ',' && *ptr != ' ' ) *(f_sig_ptr++) = ' '; *(f_sig_ptr++) = *(ptr++); } /* skip trailing space before bracket */ if( *(f_sig_ptr - 1) == ' ' ) f_sig_ptr--; *f_sig_ptr = *ptr; /* if there is no last bracket, add it if( *f_sig_ptr != ')' ) *(++f_sig_ptr) = ')';*/ //printf("c: %c ptr: %s\tfinal_sig: %s\n", *ptr, ptr, final_sig); return final_sig; }