void searchInput(const char *flastok, const char *fhit)
{
	MFILE *mfbuf=mfopen();
	const char *input, *ta, *hit, *select, *end, *test;

	hit=flastok;
	do{
		input=strstr(hit, "<input");
		ta=strstr(hit, "<textarea");
		select=strstr(hit, "<select");
		hit=(char*)0x8FFFFFFF;
		if(input!=NULL && input<hit) hit=input;
		if(ta!=NULL && ta<hit) hit=ta;
		if(select!=NULL && select < hit) hit=select;
		if(hit!=(char*)0x8FFFFFFF && hit<fhit){
			end=strchr(hit, '>');
			test=strchr(hit+1, '<');
			if(test!=NULL && test<end) end=strchr(end+1, '>');
			mfSetLength(mfbuf, 0);
			mfwrite((void*)hit+1, 1, end-hit-1, mfbuf);
			printf("Input: %s\n", mfGetData(mfbuf));
			parseInput(mfGetData(mfbuf));
			hit++;
		}
	}while(hit!=(char*)0x8FFFFFFF && hit<fhit);

	mfclose(mfbuf);
}
MFILE *fileRead(char *fname)
{
	MFILE *mfin=mfopen(), *mfout=mfopen(), *mfbuf=mfopen();
	FILE *f=fopen(fname, "r");
	const char *flastok, *fhit, *fend;
	if(f==NULL) pexit("Cannot read input file ", fname);
	
	mfFileToMFile(f, mfin);
	fclose(f);
	
	flastok=fhit=fend=mfGetData(mfin);
	while((fhit=strstr(flastok, "<!--#"))!=NULL){
		searchInput(flastok, fhit);
	
		fend=strstr(fhit, "-->");
		if(fend==NULL) pexit("Parse error - '-->' expected - exiting\n", fhit);
		if(commdepth==0)
			escapeWrite((void*)flastok, fhit-flastok, mfout);
		flastok=(const char*)(fend+3);
		mfSetLength(mfbuf, 0);

		mfwrite((void*)(fhit+5), 1, fend-(fhit+5), mfbuf);
		parseMeta(mfout, mfGetData(mfbuf));
	}
	searchInput(flastok, (char*)0x8FFFFFFF);
	escapeWrite((void*)flastok, strlen(flastok), mfout);
	mfprintf(mfout, "\";\n");
	
	mfclose(mfin);
	return(mfout);
}
示例#3
0
int parseMultiPart(char *boundary)
{
    int bound_len=strlen(boundary), type, startat, finish=false;
    char *name=NULL, *ctyp=NULL, *fname=NULL;
    MFILE *mf=mfopen();

    while((startat=miscFReadLn(stdin, mf))!=-1) {

        if(strncmp(boundary, mfGetDataAt(mf, startat), bound_len))
            continue;

        /* new part found - insert old part and init new one...
         * no insert at FIRST header ...
         * at end of multipart ??? "--boundary--" line ? */
        if(!strncmp("--", mfGetDataAt(mf, mfGetLength(mf)-4), 2))
            finish=true;

        mfSetLength(mf, startat);

        if(name!=NULL) {
            /* strip memfile, since one more <cr><lf> or only <lf> at end */
            mf->used--;
            if(*(char*)((int)mf->data+mf->used-1) == '\r') mf->used--;

            if(type==CgiKindFile) {
                listAddData(type, name, fname, ctyp, mf);
                mf=mfopen();
            } else
                listAddData(type, name, mfGetData(mf), ctyp, NULL);
        }

        if(finish==true) return(true);

        type=parseMultiHead(&name, &fname, &ctyp);

        mfSetLength(mf, 0);
    }

    mfclose(mf);
    free(name);
    free(fname);
    free(ctyp);
    return true;
}
示例#4
0
/* 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);
}