GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ along with this program; if not, write to the Free Software Foundation
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE 1
#include <cgi.h>
#include "aux.h"
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n);
+#endif
+
char *cgiHeaderString = NULL;
char *cgiType = NULL;
for (cp=name;*cp && *cp!=' ' && *cp!='\r' && *cp!='\n' && *cp!=':';cp++);
for (vp=value;*vp && *vp!='\r' && *vp!='\n';vp++);
+ if (cp-name == 0 || vp-value == 0)
+ return 0;
+
if (cgiHeaderString) {
- len = (strlen (cgiHeaderString) + cp-name + vp-value + 5) * sizeof (char);
+ len = (strlen (cgiHeaderString) + cp-name + vp-value + 4) * sizeof (char);
if ((pivot = (char *)realloc (cgiHeaderString,len)) == NULL)
return 0;
cgiHeaderString = pivot;
return 0;
pivot = cgiHeaderString;
}
+ memset(pivot+1, 0, (cp-name + vp-value + 4));
+
strncpy (pivot, name, cp-name);
strncat (pivot, ": ", 2);
strncat (pivot, value, vp-value);
if (res)
res->cookies = cgiReadCookies ();
else
- return NULL;
+ {
+ /* In some cases, we might have no other CGI results.
+ But we still have cookies! */
+ s_cookie **cookies;
+ cookies = cgiReadCookies();
+ if (cookies) {
+ /* We need to create a s_cgi structure. */
+ if ((res = (s_cgi *)malloc (sizeof (s_cgi))) == NULL)
+ return NULL;
+ res->vars = NULL;
+ res->cookies = cookies;
+ res->files = NULL;
+
+ } else {
+ return NULL;
+ }
+ }
if (!res->vars && !res->cookies && !res->files) {
free (res);
}
}
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n) {
+ char *fnval;
+
+ if ((fnval = (char *)malloc (n + 1)) == NULL)
+ return NULL;
+ strncpy(fnval, s, n);
+ fnval[n] = '\0';
+ return fnval;
+}
+#endif
+
/*
* Local variables:
* c-indent-level: 4