You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Randy Terbush <ra...@zyzzyva.com> on 1996/04/18 22:18:44 UTC
Re: duh (was: palloc() not working as expected... )
It always helps to post a stupid question to help figure this
stuff out....
On this topic...
I'm working on a module project that is requiring me to pass
around quite a bit of form data. Have I re-invented a way of
parsing this attribute/value information, or could this bit
of code be included in a standard part of the server?
I did not see another way to do this and will need to use it
often.
> I'm working on the following bit of code that should parse
> the r->args string and return a linked list of attribute/value
> structures. I'm finding that if my attribute or value is
> greater than 8 char in length, it will overflow the storage in
> this structure. If I use malloc() instead of palloc() it works
> as expected.
typedef struct reqArgStruct {
char *attr;
char *value;
struct reqArgStruct *next;
} reqArgList;
reqArgList *reqArgListHead;
reqArgList *
reqParseArgs (request_rec *r)
{
int pos = 0;
int length = 0;
reqArgList *newArgList;
reqArgList *ArgListHead = NULL;
reqArgList *ArgListTail = NULL;
length = strlen (r->args);
while (pos != length)
{
int foundEq = 0;
int foundAmp = 0;
int start = pos;
int len = 0;
char *attr;
char *value;
while (pos != length)
{
if (r->args[pos] == '=')
{
foundEq = 1;
pos++;
break;
}
pos++;
len++;
}
if (!foundEq)
break;
attr = palloc(r->pool, len + 1);
strncpy (attr, &r->args[start], len);
attr[len] = '\0';
start = pos;
len = 0;
while (pos != length)
{
if (r->args[pos] == '&')
{
foundAmp = 1;
pos++;
break;
}
pos++;
len++;
}
value = palloc(r->pool, len + 1);
strncpy (value, &r->args[start], len);
value[len] = '\0';
(reqArgList *)newArgList = (reqArgList *)pcalloc (r->pool, sizeof (reqArgList));
newArgList->attr = pstrdup (r->pool, attr);
newArgList->value = pstrdup (r->pool, value);
newArgList->next = NULL;
if (ArgListTail == NULL)
{
ArgListHead = newArgList;
ArgListTail = newArgList;
}
else
{
ArgListTail->next = newArgList;
ArgListTail = newArgList;
}
if (!foundAmp)
break;
}
return (ArgListHead);
}
- ------- End of Unsent Draft
------- End of Forwarded Message