📄 commandconf.c
字号:
char* a=NULL; char* v=strdup(var); char* subst_begin=strstr(v,"@@{"); char* subst_end=strstr(subst_begin,"}"); char* tmp=(char*)malloc((subst_end-subst_begin)+1); tmp = strncpy(tmp,subst_begin+3,subst_end-subst_begin-3); tmp[subst_end-subst_begin-3]='\0'; conf_put_token(subst_end+1); if((a=get_variable_value(tmp))!=NULL){ conf_put_token(a); } else { error(230,_("Variable %s not defined\n"),tmp); /* * We can use nondefined variable */ } subst_begin[0]='\0'; conf_put_token(v); conf_put_token("\n"); free(v);}void do_define(char* name, char* value){ symba* s=NULL; list* l=NULL; if(!(l=list_find(name,conf->defsyms))){ s=(symba*)malloc(sizeof(symba)); s->name=name; s->value=value; conf->defsyms=list_append(conf->defsyms,(void*)s); } else { free(((symba*)l->data)->value); ((symba*)l->data)->value=NULL; ((symba*)l->data)->value=value; }}void do_undefine(char* name){ list*r=NULL; if((r=list_find(name,conf->defsyms))){ free(((symba*)r->data)->value); free((symba*)r->data); r->data=NULL; conf->defsyms=list_delete_item(r); }}int handle_endif(int doit,int allow_else){ if(doit){ int count=1; error(230,_("\nEating until @@endif\n")); do { int i = conflex(); switch (i) { case TIFDEF : { count++; break; } case TIFNDEF : { count++; break; } case TENDIF : { count--; break; } case TIFHOST : { count++; break; } case TIFNHOST : { count++; break; } case TELSE : { if (count==1) { /* * We have done enough */ if (allow_else) { return 0; } else { conferror("Ambigous else"); return -1; } } break; } case 0 : { conferror("@@endif or @@else expected"); return -1; count=0; } default : { /* * empty default */ } } } while (count!=0); conf_put_token("\n@@endif\n"); error(230,"\nEating done\n"); } return 0; }int do_ifxdef(int mode,char* name){ int doit; doit=mode; if((list_find(name,conf->defsyms))){ doit=1-doit; } return (handle_endif(doit,1));}int do_ifxhost(int mode,char* name){ int doit; char* s=NULL; doit=mode; s=(char*)malloc(sizeof(char)*MAXHOSTNAMELEN+1); if(gethostname(s,MAXHOSTNAMELEN)==-1){ error(0,_("Couldn't get hostname %s"),name); free(s); return -1; } if(strcmp(name,s)==0) { doit=1-doit; } free(s); return (handle_endif(doit,1));}list* append_rxlist(char* rx,int attr,list* rxlst){ extern long conf_lineno; /* defined & set in conf_lex.l */ rx_rule* r=NULL; r=(rx_rule*)malloc(sizeof(rx_rule)); r->rx=rx; r->attr=attr; r->conf_lineno = conf_lineno; update_db_out_order(r->attr); rxlst=list_append(rxlst,(void*)r); return rxlst;}void do_groupdef(char* group,int value){ list* r=NULL; symba* s=NULL; if((r=list_find(group,conf->groupsyms))){ ((symba*)r->data)->ival=value; return; } /* This is a new group */ s=(symba*)malloc(sizeof(symba)); s->name=group; s->ival=value; conf->groupsyms=list_append(conf->groupsyms,(void*)s);}int get_groupval(char* group){ list* r=NULL; if((r=list_find(group,conf->groupsyms))){ return (((symba*)r->data)->ival); } return -1;}void do_dbdef(int dbtype,char* val){ url_t* u=NULL; url_t** conf_db_url; switch(dbtype) { case DB_OLD: { conf_db_url=&(conf->db_in_url); break; } case DB_WRITE: { conf_db_url=&(conf->db_out_url); break; } case DB_NEW: { conf_db_url=&(conf->db_new_url); break; } default : { error(0,"Invalid call of do_dbdef\n"); return; } } if(*conf_db_url==NULL){ u=parse_url(val); /* FIXME Check the URL if you add support for databases that cannot be * both input and output urls */ switch (dbtype) { case DB_OLD: case DB_NEW:{ if(u==NULL||u->type==url_unknown||u->type==url_stdout ||u->type==url_stderr) { error(0,_("Unsupported input URL-type:%s\n"),val); } else { *conf_db_url=u; } break; } case DB_WRITE: { if(u==NULL||u->type==url_unknown||u->type==url_stdin){ error(0,_("Unsupported output URL-type:%s\n"),val); } else{ conf->db_out_url=u; error(200,_("Output database set to \"%s\" \"%s\"\n"),val,u->value); } break; } } } free(val);}void do_dbindef(char* val){ url_t* u=NULL; if(conf->db_in_url==NULL){ u=parse_url(val); /* FIXME Check the URL if you add support for databases that cannot be * both input and output urls */ if(u==NULL||u->type==url_unknown||u->type==url_stdout ||u->type==url_stderr) { error(0,_("Unsupported input URL-type:%s\n"),val); } else { conf->db_in_url=u; } } free(val);}void do_dboutdef(char* val){ url_t* u=NULL; error(200,_("Setting output database \"%s\"\n"),val); if(conf->db_out_url==NULL){ u=parse_url(val); /* FIXME Check the URL if you add support for databases that cannot be * both input and output urls */ if(u==NULL||u->type==url_unknown||u->type==url_stdin){ error(0,_("Unsupported output URL-type:%s\n"),val); } else{ conf->db_out_url=u; error(200,_("Output database set to \"%s\" \"%s\"\n"),val,u->value); } } else { error(200,_("Output database already set\n")); } free(val);}void do_repurldef(char* val){ url_t* u=NULL; u=parse_url(val); /* FIXME Check the URL if you add support for databases that cannot be * both input and output urls */ if(u==NULL||u->type==url_unknown||u->type==url_stdin){ error(0,_("Unsupported output URL-type:%s\n"),val); } else { error_init(u,0); } }void do_verbdef(char* val){ char* err=NULL; long a=0; a=strtol(val,&err,10); if(*err!='\0' || a>255 || a<0 || errno==ERANGE){ error(0, _("Illegal verbosity level:%s\n"),val); error(10,_("Using previous value:%i\n"),conf->verbose_level); return; } else { if(conf->verbose_level==-1){ conf->verbose_level=a; }else { error(210,_("Verbosity already defined to %i\n"),conf->verbose_level); } }}const char* aide_key_7=CONFHMACKEY_07;const char* db_key_7=DBHMACKEY_07;void* get_conf_key() { void* r; char* m=(char*)malloc(strlen(aide_key_1)+ strlen(aide_key_2)+ strlen(aide_key_3)+ strlen(aide_key_4)+ strlen(aide_key_5)+ strlen(aide_key_6)+ strlen(aide_key_7)+ strlen(aide_key_8)+ strlen(aide_key_9)+ strlen(aide_key_0)+1); m[0]=0; strcat(m,aide_key_0); strcat(m,aide_key_1); strcat(m,aide_key_2); strcat(m,aide_key_3); strcat(m,aide_key_4); strcat(m,aide_key_5); strcat(m,aide_key_6); strcat(m,aide_key_7); strcat(m,aide_key_8); strcat(m,aide_key_9); r=decode_base64(m,strlen(m)); memset(m,0,strlen(m)); free(m); return r;}size_t get_conf_key_len() { size_t len=0; char* m=(char*)malloc(strlen(aide_key_1)+ strlen(aide_key_2)+ strlen(aide_key_3)+ strlen(aide_key_4)+ strlen(aide_key_5)+ strlen(aide_key_6)+ strlen(aide_key_7)+ strlen(aide_key_8)+ strlen(aide_key_9)+ strlen(aide_key_0)+1); m[0]=0; strcat(m,aide_key_0); strcat(m,aide_key_1); strcat(m,aide_key_2); strcat(m,aide_key_3); strcat(m,aide_key_4); strcat(m,aide_key_5); strcat(m,aide_key_6); strcat(m,aide_key_7); strcat(m,aide_key_8); strcat(m,aide_key_9); len=length_base64(m,strlen(m)); memset(m,0,strlen(m)); free(m); return len;}void* get_db_key() { void* r; char* m=(char*)malloc(strlen(db_key_1)+ strlen(db_key_2)+ strlen(db_key_3)+ strlen(db_key_4)+ strlen(db_key_5)+ strlen(db_key_6)+ strlen(db_key_7)+ strlen(db_key_8)+ strlen(db_key_9)+ strlen(db_key_0)+1); m[0]=0; strcat(m,db_key_0); strcat(m,db_key_1); strcat(m,db_key_2); strcat(m,db_key_3); strcat(m,db_key_4); strcat(m,db_key_5); strcat(m,db_key_6); strcat(m,db_key_7); strcat(m,db_key_8); strcat(m,db_key_9); r=decode_base64(m,strlen(m)); memset(m,0,strlen(m)); free(m); return r;}size_t get_db_key_len() { size_t len=0; char* m=(char*)malloc(strlen(db_key_1)+ strlen(db_key_2)+ strlen(db_key_3)+ strlen(db_key_4)+ strlen(db_key_5)+ strlen(db_key_6)+ strlen(db_key_7)+ strlen(db_key_8)+ strlen(db_key_9)+ strlen(db_key_0)+1); m[0]=0; strcat(m,db_key_0); strcat(m,db_key_1); strcat(m,db_key_2); strcat(m,db_key_3); strcat(m,db_key_4); strcat(m,db_key_5); strcat(m,db_key_6); strcat(m,db_key_7); strcat(m,db_key_8); strcat(m,db_key_9); len=length_base64(m,strlen(m)); memset(m,0,strlen(m)); free(m); return len;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -