File: post.c

package info (click to toggle)
ppxp 0.99120923-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,812 kB
  • ctags: 3,704
  • sloc: ansic: 24,532; tcl: 3,992; makefile: 517; sh: 80
file content (52 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>

#include <xcio.h>

static void
PostExtract(unsigned char *dst, unsigned char *src, int max)
{
    int i=0;

    while (i < max && *src) {
	if (*src == '%') {
	    int dg;

	    src ++;
	    sscanf(src, "%2X", &dg);
	    src ++;
	    *dst = dg;
	} else if (*src == '+') *dst = ' ';
	else *dst = *src;
	dst ++;
	src ++;
	i ++;
    }
    *dst = '\0';
}

void
PostRead(unsigned char *src)
{
    int n, fd=HttpdFd();
    char *p, *label, *data;
    unsigned char dst[100];
    struct xcio_s xc;

    if ((p = strpbrk(src, "\r\n")) != NULL) *p = '\0';
    while ((p = index(src, '=')) != NULL) {
	*p = '\0';
	label = src;
	data = p + 1;
	if ((p = index(data, '&')) != NULL) *p = '\0';
	if (p) src = p + 1;
	PostExtract(dst, data, sizeof(dst));
	syslog(LOG_PPXP|LOG_DEBUG, dst);
	PPxPCommandv(fd, XCMD_SET, label, dst, NULL);
	while ((n = XcioRead(fd, &xc)) >= 0 && n != XCIO_RETURN);
    }
}