Paste
#82436: Untitled ASCII paste by 115.60.117.65
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SYMBOL_AT "&"
static char *buf = NULL;
static unsigned char ind;
char *tmp[256] = {NULL};
static void slucx_free(char *p)
{
free(p);
p = NULL;
}
void cgi_init(void)
{
buf = getenv("QUERY_STRING");
}
void cgi_html_head(void)
{
printf("Content-Type:text/html\n\n");
}
char *cgi_get(char *s)
{
char *p = NULL;
char *ret = NULL;
char *tmp_buf = NULL;
int len = 0;
len = strlen(s);
tmp_buf = strdup(buf);
p = strtok(tmp_buf, SYMBOL_AT);
while (p) {
if (!strncmp(p, s, len)) {
if ((tmp[ind] = (char *)malloc(strlen(p + len)))) {
strcpy(tmp[ind], p + len + 1);
ret = tmp[ind++];
}
break;
}
p = strtok(NULL, SYMBOL_AT);
}
slucx_free(tmp_buf);
return ret;
}
void cgi_quit(void)
{
unsigned char i;
slucx_free(buf);
for (i=0; i<ind; ++i)
slucx_free(tmp[i]);
}