void escapeWrite(char *what, int length, MFILE *where) { int i=0; for(i=0;i<length;i++) switch(what[i]){ case '"' : mfputc('\\', where); mfputc('"', where); break; case '%' : mfputc('%', where); mfputc('%', where); break; default : mfputc(what[i], where); } }
int miscFReadLn(FILE *f, MFILE *mf) { int c, ret=mfGetLength(mf); if(feof(f)) return(-1); c=getc(f); while(c!=EOF && c!='\n') { mfputc(c, mf); c=getc(f); } if(c!=EOF) mfputc(c, mf); return(ret); }
void parseSLink(MFILE *mfout, const char *params) { Content *c; char *p=(char*)params, *comment, *cend; if(secakt==NULL) pexit("SLink: tried to insert, but no section found\n", params); if(*params!='\'') comment=(char*)strdup(""); else{ comment=(char*)(params+1); cend=strchr(comment, '\''); if(cend==NULL) pexit("SLink: comment not ended with ' - exiting\n", params); *cend=0; cend++; while(*cend==' ') cend++; p=cend; } c=listInsertContent(secakt->list, "", "***SCRIPT LINK***", comment); listInsertContent(c->sub, "s", "script", "Script Name"); mfprintf(mfout, "%%s?"); while((p=parseParam(mfout, c->sub, p, true))!=NULL) mfputc('&', mfout); }
/* this is REALLY a f**k ... why didnt they put the fname in a own line :( */ int parseMultiHead(char **name, char **fname, char **ctyp) { char *endchars; const char *contt="Content-Type: ", *line; const char *contd="Content-Disposition: form-data; name="; int i, ret=0; MFILE *mf=mfopen(), *mfname=mfopen(); free(*ctyp); (*ctyp)=strdup(""); /* read till empty line appears - end of header ... */ while((miscFReadLn(stdin, mf)>=0) && (line=mfGetData(mf)) && !(line[0]=='\n' || (line[0]!=0 && line[0]=='\r' && line[1]=='\n'))) { /* make sure, next lines starts at beginn of file again... */ mfSetLength(mf, 0); /* "Content-Type: what/ever" line */ if(!strncasecmp(line, contt, strlen(contt))) { free(*ctyp); (*ctyp)=miscStringDelCrLf((char*)strdup((char*)(line+strlen(contt)))); } /* "Content-Disposition: form-data; name="whatever"; filename="C:\f**k.txt"" - line */ if(!strncasecmp(line, contd, strlen(contd))) { i=strlen(contd); if(line[i]=='"') { endchars="\"\r\n\0"; i++; } else endchars=";\r\n\0"; /* parse name */ while(strchr(endchars, line[i])==NULL) mfputc(line[i++], mfname); *name=realloc(*name, mfGetLength(mfname)+1); strcpy(*name, mfGetData(mfname)); mfSetLength(mfname, 0); if(line[i]=='\"') i++; if(line[i]!=';') { ret=CgiKindValue; continue; } else ret=CgiKindFile; /* we have a filename= part here - parse filename */ while(line[i]!=0 && line[i]!='=') i++; i++; if(line[i]=='\"') { endchars="\"\r\n\0"; i++; } else endchars=";\r\n\0"; while(strchr(endchars, line[i])==NULL) mfputc(line[i++], mfname); if(mfGetLength(mfname)>0) { *fname=realloc(*fname, mfGetLength(mfname)+1); strcpy(*fname, mfGetData(mfname)); mfSetLength(mfname, 0); } else { *fname=realloc(*fname, 16); (*fname)[0]=0; } } } mfclose(mf); mfclose(mfname); return(ret); }