struct XMLDBbuffer *ApplyModifier(struct XMLDBbuffer *mod,char *name, struct XMLDBbuffer *txt) { struct XMLDBbuffer *dst; struct XMLDBbuffer *nxml; char *vraw,*vurl,*vhtml; char *nraw,*nurl,*nhtml; struct Entitydata *ent=NULL; ent=EntityMake(); vraw=XMLToRaw(txt); vurl=XMLToURL(txt); vhtml=XMLToHTML(txt); nraw=name; nurl=CGIMakeURLString(name,strlen(name)); nhtml=RawToHTML(name,strlen(name)); nxml=RawToXML(name,strlen(name)); EntityAddEntityString(ent,"&vraw;"); EntityAddSymbolString(ent,vraw); EntityAddEntityString(ent,"&nraw;"); EntityAddSymbolString(ent,nraw); EntityAddEntityString(ent,"&vurl;"); EntityAddSymbolString(ent,vurl); EntityAddEntityString(ent,"&nurl;"); EntityAddSymbolString(ent,nurl); EntityAddEntityString(ent,"&vhtml;"); EntityAddSymbolString(ent,vhtml); EntityAddEntityString(ent,"&nhtml;"); EntityAddSymbolString(ent,nhtml); EntityAddEntityString(ent,"&vxml;"); EntityAddSymbol(ent,txt); EntityAddEntityString(ent,"&nxml;"); EntityAddSymbol(ent,nxml); dst=EntityDecodeBuffer(ent,mod); free(vraw); free(vurl); free(vhtml); free(nurl); free(nhtml); XMLDBFreeBuffer(nxml); free(ent); return dst; }
int XMLdocRenderElement(struct TagDBdata *tag,struct TagDBtable *tagdb, struct XMLdocelement *x,struct XMLDBelement *e) { int i,j,s=0; struct XMLdocmod *m=NULL; struct XMLDBbuffer *action=NULL; struct XMLDBbuffer *data=NULL; char *path=NULL; int xtp=0; int atp=0; path=x->path; action=x->action; xtp=x->type.xml; atp=x->type.action; TagDBSetTable(tag,tagdb); if (x->tagdb !=NULL) TagDBSetTable(tag,x->tagdb); if (e !=NULL) data=e->data; else { data=x->defval; xtp=x->type.defval; } if (e !=NULL) { /* decide if we need a modifier */ for (i=0;i<e->atnum;i++) { for (j=0;j<x->mod.num;j++) { m=x->mod.ptr[j]; if (strcmp(e->atval[i],m->name)==0) break; } if (j<x->mod.num) { /* we have a matching attribute */ if (m->action !=NULL) action=m->action; if (m->tagdb !=NULL) TagDBSetTable(tag,m->tagdb); if (m->path !=NULL) path=m->path; atp=m->type.action; xtp=m->type.xml; } } } /* we are now in a position to render this element */ if (action==NULL) { /* no action - render as text */ if (xtp==0) { /* data is text */ s=TagDBDecode(data->buf,data->sze,tag); s=TagDBDecode(NULL,0,tag); } else { struct XMLdocfile file; file.fname=NULL; if (data !=NULL) file.fname=getDBstring(data); file.path=path; file.text=TagDBDecode; file.data=tag; file.type=xtp-1; s= XMLdocRenderFile(&file); if (file.fname !=NULL) free(file.fname); } } else { /* use an entity decoder to handle the action */ struct Entitydata *ent; ent=EntityMake(); if (ent==NULL) return -1; s=EntityAddEntityString(ent,"<"); s=EntityAddEntityString(ent,">"); s=EntityAddSymbolString(ent,"<"); s=EntityAddSymbolString(ent,">"); if (xtp==0) { s=EntityAddEntityString(ent,"&xml;"); if (s==0) s=EntityAddSymbol(ent,data); } else { struct XMLdocfile file; file.fname=NULL; if (data !=NULL) file.fname=getDBstring(data); file.path=path; file.text=TagDBDecode; file.data=tag; file.type=xtp-1; s=EntityAddEntityString(ent,"&filename;"); if (s==0) s=EntityAddEntityString(ent,"&file;"); if (s==0) s=EntityAddSymbol(ent,e->data); if (s==0) s=EntitySetDecodeTrap(ent,XMLdocFileTrap,&file); } EntitySetText(ent,TagDBDecode,tag); if (atp==0) { s=EntityDecode(action->buf,action->sze,ent); if (s==0) s=EntityDecode(NULL,0,ent); } else { FILE *fp; char *afname=NULL; char lbuf[256]; afname=getDBstring(action); if (afname !=NULL) { fp=fopen(afname,"r"); if (fp !=NULL) { while ((s==0) && (fgets(lbuf,255,fp) !=NULL)) { s=EntityDecode(lbuf,strlen(lbuf),ent); if (s !=0) break; } if (s==0) s=EntityDecode(NULL,0,ent); fclose(fp); } free(afname); } } EntityFree(ent); } return 0; }