コード例 #1
0
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);
}
コード例 #2
0
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
ファイル: ecgi.c プロジェクト: datalogistics/dlt-lors
int cgiSaveDebugData(char *fname, char *fopenmode)
{
    FILE *f;
    CgiElement *runner=c->list;
    CgiValue *vrunner;
    int count=0, subcount, i=0, envcount=0;
    DefCheck(false);
    if((f=fopen(fname, fopenmode))==NULL) return(false);

    /* get count */
    while(runner->next!=NULL) {
        count++;
        runner=runner->next;
    }
    runner=c->list;
    fwrite(&count, 1, 4, f);

    /* save internal list */
    while(runner->next!=NULL) {
        fwrite(&runner->type, 1, 4, f);
        miscWriteData(f, runner->name, -1);
        miscWriteData(f, runner->ctyp, -1);
        if(runner->mf!=NULL)
            miscWriteData(f, mfGetData(runner->mf), mfGetLength(runner->mf));
        else
            miscWriteData(f, NULL, 0);

        /* get value count */
        vrunner=runner->values;
        subcount=0;
        while(vrunner->next!=NULL) {
            subcount++;
            vrunner=vrunner->next;
        }
        vrunner=runner->values;
        fwrite(&subcount, 1, 4, f);

        /* save values */
        while(vrunner->next!=NULL) {
            miscWriteData(f, vrunner->value, -1);
            vrunner=vrunner->next;
        }

        runner=runner->next;
    }

    /* get environment count */
    while(environ[i++]!=NULL) envcount++;
    fwrite(&envcount, 1, 4, f);

    /* save environment */
    i=0;
    while(environ[i]!=NULL)
        miscWriteData(f, environ[i++], -1);

    fclose(f);
    return(true);
}
コード例 #4
0
ファイル: ecgi.c プロジェクト: datalogistics/dlt-lors
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;
}
コード例 #5
0
ファイル: ecgi.c プロジェクト: datalogistics/dlt-lors
/* 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);
}
コード例 #6
0
ファイル: ecgi.c プロジェクト: datalogistics/dlt-lors
/* only for debugging */
void listDump()
{
    CgiElement *erunner=c->list;
    CgiValue *vrunner;

    printf("Dumping List:\n");
    while(erunner->next!=NULL) {
        printf("-----------------------------------\nEntry - Name: %20s CTyp: %20s\nValues:", erunner->name, erunner->ctyp);
        vrunner=erunner->values;
        while(vrunner->next!=NULL) {
            printf("%20s ", vrunner->value);
            vrunner=vrunner->next;
        }
        printf("\n");

        if(erunner->type==CgiKindFileEmpty)
            printf("Empty File!\n");
        if(erunner->type==CgiKindFile)
            printf("Dumping File (Size: %d):\n************************\n%s\n************************\n", mfGetLength(erunner->mf), mfGetData(erunner->mf));

        erunner=erunner->next;
    }
}