Beispiel #1
0
static int
child(void)
{
	struct kreq	 r;
	const char 	*page = "index";
	struct kvalid	 valid = { NULL, "tag" };

	if (KCGI_OK != khttp_parse(&r, &valid, 1, &page, 1, 0))
		return(0);

	if (NULL == r.fieldmap[0]) {
		khttp_free(&r);
		return(0);
	} else if (BUFSZ != r.fieldmap[0]->valsz) {
		khttp_free(&r);
		return(0);
	}

	khttp_head(&r, kresps[KRESP_STATUS], 
		"%s", khttps[KHTTP_200]);
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
		"%s", kmimetypes[KMIME_TEXT_HTML]);
	khttp_body(&r);
	khttp_write(&r, r.fieldmap[0]->val, r.fieldmap[0]->valsz);
	khttp_free(&r);
	return(1);
}
Beispiel #2
0
static int
child(void)
{
	struct kreq	 r;
	const char 	*page[] = { "index", "test" };
	struct kfcgi	*fcgi;
	enum kcgi_err	 er;

	if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, page, 2, 0))
		return(0);

	while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
		if (1 != r.page) {
			khttp_free(&r);
			khttp_fcgi_free(fcgi);
			return(0);
		}
		khttp_head(&r, kresps[KRESP_STATUS], 
			"%s", khttps[KHTTP_200]);
		khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
			"%s", kmimetypes[KMIME_TEXT_HTML]);
		khttp_body(&r);
		khttp_free(&r);
	}

	khttp_fcgi_free(fcgi);
	return(KCGI_HUP == er ? 1 : 0);
}
Beispiel #3
0
int
main(int argc, char *argv[])
{
	struct kreq	 req;
	struct kfcgi	*fcgi;
	enum kcgi_err	 er;
	const char	*pname;
	int		 rc, c, debug;

	if ((pname = strrchr(argv[0], '/')) == NULL)
		pname = argv[0];
	else
		++pname;

	debug = 0;
	while (-1 != (c = getopt(argc, argv, "d:")))
		switch (c) {
		case ('d'):
			debug = atoi(optarg);
			break;
		default:
			return(EXIT_FAILURE);
		}

	if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, NULL, 0, 0))
		return(EXIT_FAILURE);

	for (rc = 0;;) {
		er = khttp_fcgi_parse(fcgi, &req);
		if (KCGI_HUP == er) {
			rc = 1;
			khttp_free(&req);
			break;
		} else if (KCGI_OK != er) {
			khttp_free(&req);
			break;
		}
		khttp_head(&req, kresps[KRESP_STATUS], 
			"%s", khttps[KHTTP_200]);
		khttp_head(&req, kresps[KRESP_CONTENT_TYPE], 
			"%s", kmimetypes[req.mime]);
		khttp_body(&req);
		khttp_puts(&req, "Hello, world!\n");
		khttp_free(&req);
		if (debug > 0 && 0 == --debug)
			break;
	}

	khttp_fcgi_free(fcgi);
	return(rc ? EXIT_SUCCESS : EXIT_FAILURE);
}
Beispiel #4
0
static int
child(void)
{
    struct kreq	 r;
    const char 	*page = "index";
    int		 rc;

    rc = 0;
    if (khttp_fcgi_test())
        return(0);
    if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
        return(0);
    if (KAUTH_DIGEST != r.rawauth.type)
        goto out;
    else if (0 == r.rawauth.authorised)
        goto out;
    else if (strcmp(r.rawauth.d.digest.user, "Mufasa"))
        goto out;
    else if (strcmp(r.rawauth.d.digest.realm, "*****@*****.**"))
        goto out;
    else if (strcmp(r.rawauth.d.digest.uri, "/dir/index.html"))
        goto out;
    else if (khttpdigest_validate(&r, "Circle Of Life") <= 0)
        goto out;

    khttp_head(&r, kresps[KRESP_STATUS],
               "%s", khttps[KHTTP_200]);
    khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
               "%s", kmimetypes[KMIME_TEXT_HTML]);
    khttp_body(&r);
    rc = 1;
out:
    khttp_free(&r);
    return(rc);
}
Beispiel #5
0
static int
child(void)
{
	struct kreq	 r;
	const char 	*page = "index";
	size_t		 i, found1, found2;

	if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
		return(0);

	found1 = found2 = 0;
	for (i = 0; i < r.reqsz; i++) {
		if (0 == strcmp(r.reqs[i].key, "Testing")) 
			found1 += 0 == strcmp(r.reqs[i].val, "123");
		else if (0 == strcmp(r.reqs[i].key, "Testing-Test")) 
			found2 += 0 == strcmp(r.reqs[i].val, "321");
	}

	if (1 != found1 || 1 != found2) 
		return(0);

	khttp_head(&r, kresps[KRESP_STATUS], 
		"%s", khttps[KHTTP_200]);
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
		"%s", kmimetypes[KMIME_TEXT_HTML]);
	khttp_body(&r);
	khttp_free(&r);
	return(1);
}
Beispiel #6
0
static int
child(void)
{
	struct kreq	 r;
	const char 	*page = "index";
	struct kvalid	 valid = { NULL, "tag" };
	size_t		 i;
	struct kfcgi	*fcgi;
	enum kcgi_err	 er;

	if (KCGI_OK != khttp_fcgi_init(&fcgi, &valid, 1, &page, 1, 0))
		return(0);

	while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
		if (NULL == r.fieldmap[0]) {
			khttp_free(&r);
			khttp_fcgi_free(fcgi);
			return(0);
		} else if (1024 * 1024 != r.fieldmap[0]->valsz) {
			khttp_free(&r);
			khttp_fcgi_free(fcgi);
			return(0);
		}

		for (i = 0; i < 1024 * 1024; i++)
			if (r.fieldmap[0]->val[i] != (i % 10) + 65) {
				khttp_free(&r);
				khttp_fcgi_free(fcgi);
				return(0);
			}

		khttp_head(&r, kresps[KRESP_STATUS], 
			"%s", khttps[KHTTP_200]);
		khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
			"%s", kmimetypes[KMIME_TEXT_HTML]);
		khttp_body(&r);
		khttp_write(&r, r.fieldmap[0]->val, r.fieldmap[0]->valsz);
		khttp_free(&r);
	}

	khttp_free(&r);
	khttp_fcgi_free(fcgi);
	return(KCGI_HUP == er ? 1 : 0);
}
static int
child(void)
{
	struct kreq	 r;
	struct kvalid	 key = { kvalid_abort, "foo" };
	const char 	*page[] = { "index" };

	if (KCGI_OK != khttp_parse(&r, &key, 1, page, 1, 0))
		return(1);
	khttp_free(&r);
	return(0);
}
Beispiel #8
0
static int
child(void)
{
	struct kreq	 r;
	const char 	*page = "index";
	struct kfcgi	*fcgi;
	enum kcgi_err	 er;
	size_t		 i;
	struct stat	 st;

	if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, &page, 1, 0))
		return(0);

	while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
		khttp_head(&r, kresps[KRESP_STATUS], 
			"%s", khttps[KHTTP_200]);
		khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
			"%s", kmimetypes[KMIME_TEXT_HTML]);
		khttp_body(&r);
		for (i = 0; i < r.fieldsz; i++) {
			if (strcmp(r.fields[i].key, "picture"))
				continue;
			if (NULL == r.fields[i].file)
				return(0);
			if (-1 == stat(r.fields[i].file, &st)) {
				perror(r.fields[i].file);
				return(0);
			} else if ((size_t)st.st_size != r.fields[i].valsz) 
				return(0);
		}
		khttp_free(&r);
	}

	khttp_free(&r);
	khttp_fcgi_free(fcgi);
	return(KCGI_HUP == er ? 1 : 0);
}
static int
child(void)
{
    struct kreq	 r;
    const char 	*page = "index";
    struct kfcgi	*fcgi;
    struct kvalid	 key = { kvalid_abort, "foo" };
    enum kcgi_err	 er;

    if ( ! khttp_fcgi_test())
        return(0);
    if (KCGI_OK != khttp_fcgi_init(&fcgi, &key, 1, &page, 1, 0))
        return(0);
    er = khttp_fcgi_parse(fcgi, &r);
    khttp_free(&r);
    khttp_fcgi_free(fcgi);
    return(KCGI_HUP == er ? 1 : 0);
}
Beispiel #10
0
static int
child(void)
{
	struct kreq	 r;
	const char 	*page = "index";

	if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
		return(0);

	khttp_head(&r, kresps[KRESP_STATUS], 
		"%s", khttps[KHTTP_200]);
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
		"%s", kmimetypes[KMIME_TEXT_HTML]);
	if ( ! khttp_body(&r))
		return(0);
	khttp_puts(&r, "1234567890");
	khttp_free(&r);
	return(1);
}