token_t* build_token_list(script_t* scriptbuf, token_t* tokenlist) { char* start; char* end; char* curpos; char* endpos; token_t* curtoken; token_t* firsttoken; curtoken = tokenlist; firsttoken = tokenlist; curpos = scriptbuf->buf + scriptbuf->curpos; endpos = scriptbuf->buf + scriptbuf->size; while(curpos < endpos) { start = strstr(curpos, open_tag); end = strstr(curpos, close_tag); if(start && !end) { die_with_message(scriptbuf, start, g_err_msg[E_NO_END_MARKER], open_tag[1]); } if((start > end) || (!start && end)) { die_with_message(scriptbuf, end, g_err_msg[E_END_BEFORE_BEGIN], open_tag[1], open_tag[1]); } if(start && (strstr(start + 1, open_tag) && (strstr (start + 1, open_tag) < end))) die_with_message(scriptbuf, start, g_err_msg[E_NO_END_MARKER], open_tag[1]); if(end) { curtoken = push_token_on_list(curtoken, scriptbuf, curpos, start - curpos); if(firsttoken == NULL) { firsttoken = curtoken; } curtoken = push_token_on_list(curtoken, scriptbuf, start, end - start); if(firsttoken == NULL) { firsttoken = curtoken; } curpos = end + 2; } else { curtoken = push_token_on_list(curtoken, scriptbuf, curpos, endpos - curpos); if(firsttoken == NULL) { firsttoken = curtoken; } curpos = endpos; } } return firsttoken; }
void mime_var_open_target (mime_var_t * obj) { char *tmpname; token_t *curtoken; curtoken = global.uploadlist; int ok; /* if upload_limit is zero, we die right here */ if (global.uploadkb == 0) { empty_stdin (); die_with_message (NULL, NULL, "File uploads are not allowed."); } ok = -1; tmpname = xmalloc (strlen (global.uploaddir) + 8); strcpy (tmpname, global.uploaddir); strcat (tmpname, "/XXXXXX"); obj->fh = mkstemp (tmpname); if (obj->fh == -1) { ok = 0; } /* reuse the name as a fifo if we have a handler. We do this * because tempnam uses TEMPDIR if defined, among other bugs */ if ((ok) && global.uploadhandler) { /* I have a handler */ close (obj->fh); unlink (tmpname); if (mkfifo (tmpname, 0600)) ok = 0; /* you must open the fifo for reading before writing * on non linux systems */ if (ok) { mime_exec (obj, tmpname); obj->fh = open (tmpname, O_WRONLY); } if (obj->fh == -1) ok = 0; } else { buffer_add (&(obj->value), tmpname, strlen (tmpname)); } if (!ok) { empty_stdin (); die_with_message (NULL, NULL, g_err_msg[E_FILE_OPEN_FAIL], tmpname); } curtoken = push_token_on_list (curtoken, NULL, tmpname, strlen (tmpname) + 1); if (global.uploadlist == NULL) { global.uploadlist = curtoken; } }