int decodeconfig(struct XMLDBtable *ptr,struct XMLDBtable *tree,void *data) { int i; struct config *config; struct XMLDBelement *e; config=(struct config *)data; for (i=0;i<ptr->num;i++) { e=ptr->element[i]; if (strcmp(e->name,"ok")==0) { if (config->ok !=NULL) free(config->ok); config->ok=getDBstring(e->data); } else if (strcmp(e->name,"fail")==0) { if (config->fail !=NULL) free(config->fail); config->fail=getDBstring(e->data); } else if (strcmp(e->name,"path")==0) { if (config->path !=NULL) free(config->path); config->path=getDBstring(e->data); } else if (strcmp(e->name,"query")==0) { if (config->query !=NULL) free(config->query); config->query=getDBstring(e->data); } else if (strcmp(e->name,"mail")==0) { if (config->mail !=NULL) free(config->mail); config->mail=getDBstring(e->data); } else if (strcmp(e->name,"mailc")==0) { if (config->mailc !=NULL) free(config->mailc); config->mailc=getDBstring(e->data); } else if (strcmp(e->name,"store")==0) { if (config->store !=NULL) free(config->store); config->store=getDBstring(e->data); } else if (strcmp(e->name,"top")==0) { if (config->top !=NULL) free(config->top); config->top=getDBstring(e->data); } else if (strcmp(e->name,"display")==0) { if (config->display.name !=NULL) free(config->display.name); config->display.name=getDBstring(e->data); } else if (strcmp(e->name,"section")==0) { XMLdocGetConfigSection(e->data,"section","section", decodesection,config); } else if (strcmp(e->name,"tree")==0) { XMLdocGetConfigSection(e->data,"tree","tree",decodetree,config); } else if (strcmp(e->name,"post")==0) { XMLdocGetConfigSection(e->data,"post","post/entry",decodepost,config); } else if (strcmp(e->name,"script")==0) { XMLdocGetConfigSection(e->data,"script","script",decodesfname,config); } else if (strcmp(e->name,"map")==0) { XMLdocGetConfigSection(e->data,"map","map/entry",decodemap,config); } } return 0; }
int xmldocbuild(struct XMLDBtable *ptr,struct XMLDBtable *tree,void *data) { int i,j; struct xmldoc *xmldoc; struct XMLDBelement *e; char zero[1]={0}; char *symbol[]={"\"","\\","<",">","&",0}; char *entity[]={""","'","<",">","&",0}; struct Entitydata *entptr; entptr=EntityMake(); if (entptr==NULL) return -1; EntityAddEntityStringArray(entptr,entity); EntityAddSymbolStringArray(entptr,symbol); xmldoc=(struct xmldoc *)data; for (i=0;i<ptr->num;i++) { e=ptr->element[i]; if (strcmp(e->name,"tree")==0) { XMLdocGetConfigSection(e->data,"tree","tree",decodetree,xmldoc); } else if (strcmp(e->name,"match")==0) { XMLdocGetConfigSection(e->data,"match","match",decodematch,xmldoc); } else if (strcmp(e->name,"script")==0) { if (xmldoc->sc.buf !=NULL) XMLDBFreeBuffer(xmldoc->sc.buf); xmldoc->sc.type=0; for (j=0;j<e->atnum;j++) { if ((e->atval[j] !=NULL) && (strcmp(e->atval[j],"file")==0)) xmldoc->sc.type=1; } if (xmldoc->sc.type==1) { xmldoc->sc.buf=XMLDBCopyBuffer(e->data); XMLDBAddBuffer(xmldoc->sc.buf,zero,1); } else xmldoc->sc.buf=EntityDecodeBuffer(entptr,e->data); if (xmldoc->sc.buf==NULL) break; } else if (strcmp(e->name,"map")==0) { XMLdocGetConfigSection(e->data,"map","map/entry",decodemap,xmldoc); } else if (strcmp(e->name,"external")==0) { int xtp=0; for (j=0;j<e->atnum;j++) { if ((e->atval[j] !=NULL) && (strcmp(e->atval[j],"file")==0)) xtp=1; } if (xtp==0) XMLdocGetConfigSection(e->data,"external","external/entry", decodeexternal,xmldoc); else { char *fname=NULL; FILE *fp; fname=getDBstring(e->data); if (fname==NULL) break; fp=fopen(fname,"r"); if (fp !=NULL) { loadexternal(fp,xmldoc); fclose(fp); } } } else if (strcmp(e->name,"xmldoc")==0) { int xtp=0; if (xmldoc->doc !=NULL) XMLdocFree(xmldoc->doc); xmldoc->doc=XMLdocMake(); for (j=0;j<e->atnum;j++) { if ((e->atval[j] !=NULL) && (strcmp(e->atval[j],"file")==0)) xtp=1; } if (xtp==0) XMLdocGetConfigSection(e->data,"xmldoc","xmldoc",XMLdocBuild, xmldoc->doc); else { char *fname=NULL; FILE *fp; fname=getDBstring(e->data); if (fname==NULL) break; fp=fopen(fname,"r"); if (fp !=NULL) { loadXMLdoc(fp,xmldoc->doc); fclose(fp); } } } } free(entptr); return 0; }