src/lib/cheapcgi.c 1.114
1.114 2009/04/01 06:56:42 galt
making post action URI query params available to cgi hash, and they take precedence over form vars
Index: src/lib/cheapcgi.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/cheapcgi.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -b -B -U 4 -r1.113 -r1.114
--- src/lib/cheapcgi.c 19 Mar 2009 21:41:00 -0000 1.113
+++ src/lib/cheapcgi.c 1 Apr 2009 06:56:42 -0000 1.114
@@ -77,24 +77,39 @@
{
return inputString;
}
-static void getQueryInput()
+static void getQueryInputExt(boolean abortOnErr)
/* Get query string from environment if they've used GET method. */
{
inputString = getenv("QUERY_STRING");
if (inputString == NULL)
+ {
+ if (abortOnErr)
errAbort("No QUERY_STRING in environment.");
+ inputString = cloneString("");
+ return;
+ }
inputString = cloneString(inputString);
}
+static void getQueryInput()
+/* Get query string from environment if they've used GET method. */
+{
+getQueryInputExt(TRUE);
+}
+
static void getPostInput()
-/* Get input from file if they've used POST method. */
+/* Get input from file if they've used POST method.
+ * Grab any GET QUERY_STRING input first. */
{
char *s;
long i;
int r;
+getQueryInputExt(FALSE);
+int getSize = strlen(inputString);
+
s = getenv("CONTENT_LENGTH");
if (s == NULL)
errAbort("No CONTENT_LENGTH in environment.");
if (sscanf(s, "%lu", &inputSize) != 1)
@@ -102,20 +117,28 @@
s = getenv("CONTENT_TYPE");
if (s != NULL && startsWith("multipart/form-data", s))
{
/* use MIME parse on input stream instead, can handle large uploads */
- inputString = ""; // must not be NULL so it knows it was set
+ /* inputString must not be NULL so it knows it was set */
return;
}
-inputString = needMem((size_t)inputSize+1);
+int len = getSize + inputSize;
+if (getSize > 0)
+ ++len;
+char *temp = needMem((size_t)len+1);
for (i=0; i<inputSize; ++i)
{
r = getc(stdin);
if (r == EOF)
errAbort("Short POST input.");
- inputString[i] = r;
+ temp[i] = r;
}
-inputString[inputSize] = 0;
+if (getSize > 0)
+ temp[i++] = '&';
+strncpy(temp+i, inputString, getSize);
+temp[len] = 0;
+freeMem(inputString);
+inputString = temp;
}
#define memmem(hay, haySize, needle, needleSize) \
memMatch(needle, needleSize, hay, haySize)
@@ -375,14 +398,11 @@
return s;
qs = getenv("QUERY_STRING");
if (qs == NULL)
return "POST";
-if (qs[0] == 0)
- {
- char *cl = getenv("CONTENT_LENGTH");
- if (cl != NULL && atoi(cl) > 0)
+char *cl = getenv("CONTENT_LENGTH");
+if (cl != NULL && atoi(cl) > 0)
return "POST";
- }
return "QUERY";
}
static void _cgiFindInput(char *method)
@@ -408,10 +428,14 @@
* into input, so please don't free input until you're done with
* the hash. Prints message aborts if there's an error.*/
{
char *namePt, *dataPt, *nextNamePt;
-struct hash *hash = newHash(6);
-struct cgiVar *list = NULL, *el;
+struct hash *hash = *retHash;
+struct cgiVar *list = *retList, *el;
+
+if (!hash)
+ hash = newHash(6);
+slReverse(&list);
namePt = input;
while (namePt != NULL && namePt[0] != 0)
{
@@ -526,13 +550,11 @@
if (s != NULL && startsWith("multipart/form-data", s))
{
cgiParseMultipart(&inputHash, &inputList);
}
-else
#endif /* GBROWSE */
- {
- cgiParseInputAbort(inputString, &inputHash, &inputList);
- }
+
+cgiParseInputAbort(inputString, &inputHash, &inputList);
/* now parse the cookies */
parseCookies(&cookieHash, &cookieList);