Check-in [1172ad4943]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Convert to kfcgi
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | capsisum
Files: files | file ages | folders
SHA1:1172ad4943d4a14524ab44012bb483f2efae63b8
User & Date: bapt 2015-11-19 14:16:13
Context
2015-11-19
14:16
Convert to kfcgi Leaf check-in: 1172ad4943 user: bapt tags: capsisum
13:30
Create new branch named "capsisum" check-in: 21f16f1aeb user: bapt tags: capsisum
Changes

Changes to web/cblogweb.c.

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
...
561
562
563
564
565
566
567
568
569













{
	struct kreq *r = (struct kreq *)udata;

	khttp_puts(r, s);
}

void
cblog(ucl_object_t *conf)
{
	const char *reqpath, *tplpath;
	struct ucltpl_parser tpl;
	char cspath[MAXPATHLEN];
	int type;
	int yyyy, mm, dd;
	struct criteria criteria;
................................................................................
	int comment = CBLOG_COMMENT_NONE;
	struct kreq r;
	ucl_object_t *out;
	ucl_object_t *map;

	/* read the configuration file */

	if (KCGI_OK != khttp_parse(&r, keys, KEY__MAX, pages, PAGE__MAX,
	    PAGE_DEFAULT))
		return;

	if (KMETHOD_OPTIONS == r.method) {
		khttp_head(&r, kresps[KRESP_STATUS],
		    "%s", khttps[KHTTP_200]);
		khttp_head(&r, kresps[KRESP_ALLOW],
		    "OPTIONS HEAD GET POST");
................................................................................
	tpl.data = out;
	tpl.addchar = &cblog_putc;
	tpl.addstr = &cblog_puts;
	ucltpl_process_file(&tpl, cspath);

	sqlite3_close(sqlite);
	khttp_free(&r);
	exit(0);
}




















|







 







|
<







 







<

>
>
>
>
>
>
>
>
>
>
>
>
>
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
...
560
561
562
563
564
565
566

567
568
569
570
571
572
573
574
575
576
577
578
579
580
{
	struct kreq *r = (struct kreq *)udata;

	khttp_puts(r, s);
}

void
cblog_process(ucl_object_t *conf, struct kfcgi *fcgi)
{
	const char *reqpath, *tplpath;
	struct ucltpl_parser tpl;
	char cspath[MAXPATHLEN];
	int type;
	int yyyy, mm, dd;
	struct criteria criteria;
................................................................................
	int comment = CBLOG_COMMENT_NONE;
	struct kreq r;
	ucl_object_t *out;
	ucl_object_t *map;

	/* read the configuration file */

	if (KCGI_OK != khttp_fcgi_parse(fcgi, &r))

		return;

	if (KMETHOD_OPTIONS == r.method) {
		khttp_head(&r, kresps[KRESP_STATUS],
		    "%s", khttps[KHTTP_200]);
		khttp_head(&r, kresps[KRESP_ALLOW],
		    "OPTIONS HEAD GET POST");
................................................................................
	tpl.data = out;
	tpl.addchar = &cblog_putc;
	tpl.addstr = &cblog_puts;
	ucltpl_process_file(&tpl, cspath);

	sqlite3_close(sqlite);
	khttp_free(&r);

}

void
cblog(ucl_object_t *conf)
{
	struct kfcgi *fcgi;

	if (KCGI_OK != khttp_fcgi_init(&fcgi,keys, KEY__MAX, pages, PAGE__MAX,
	    PAGE_DEFAULT))
		err(EXIT_FAILURE, "khttp_fcgi_init");

	for (;;)
		cblog_process(conf, fcgi);
}

Changes to web/main.c.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
226
227
228
229
230
231
232
233




234
235
236
237
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <poll.h>

#include "cblogweb.h"


#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif

ucl_object_t *conf = NULL;
int fd;
const char *unix_sock_path = NULL;

static void
client_process(int cfd)
{
	size_t hdr = 0;
	char *tofree, *header;
	size_t next;
	char c;

	if (cfd < 0)
		err(EXIT_FAILURE, "accept()");

	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	if (STDIN_FILENO != dup2(cfd, STDIN_FILENO))
		err(EXIT_FAILURE, "fork()");
	if (STDOUT_FILENO != dup2(cfd, STDOUT_FILENO))
		err(EXIT_FAILURE, "fork()");

	/* Parsing scgi header */
	while ((c = fgetc(stdin)) != EOF && isdigit((char)c))
		hdr = hdr * 10 + (char)c - '0';
	if (hdr < 16)
		err(EXIT_FAILURE, "malformed scgi header");
	if ((header = calloc(hdr, sizeof(char *))) == NULL)
		err(EXIT_FAILURE, "calloc");
	tofree = header;
	if (fread(header, 1, hdr, stdin) < hdr)
		err(EXIT_FAILURE, "malformed scgi header");
	while (header - tofree < hdr) {
		next = strlen(header) + 1;
		setenv(header, header + next, 1);
		header += next;
		header += strlen(header) + 1;
	}
	free(tofree);
	fgetc(stdin); /* Read next ',' */
	setenv("GATEWAY_INTERFACE", "CGI/1.1", 1);
	cblog(conf);
}

static void
close_socket(int dummy)
{
	if (fd != -1)
		close(fd);

	if (unix_sock_path)
................................................................................
	if (!check_conf(o))
		return;

	ucl_object_unref(conf);
	conf = o;
}

static void
serve(void) {
	struct pollfd pfd;
	int clfd;

	memset(&pfd, 0, sizeof(pfd));
	pfd.fd = fd;
	pfd.events = POLLIN|POLLERR;

	for (;;) {
		pfd.revents = 0;
		if (poll(&pfd, 1, -1) < 0) {
			if (errno == EAGAIN || errno == EINTR)
				continue;
			err(EXIT_FAILURE, "An error occured");
		}
		if (! (pfd.revents & POLLIN))
			continue;

		clfd = accept(pfd.fd, NULL, NULL);
		if (fork() == 0) {
			client_process(clfd);
			/* Not reached */
		}
		close(clfd);
	}
}

int
main(int argc, char **argv, char **envp)
{
	struct sockaddr_un un;
	const ucl_object_t *o;
	struct ucl_parser *p;

................................................................................
		if (strcmp(argv[1], "-d") == 0)
			daemon(0,0);
		else
			err(EXIT_FAILURE, "unknown option: %s", argv[1]);
	} else if (argc > 2)
		err(EXIT_FAILURE, "Too many options");

	serve();





	close_socket(EXIT_SUCCESS);
	return (0); /* NOT REACHED */
}







>









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|
>
>
>
>




8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24








































25
26
27
28
29
30
31
...
102
103
104
105
106
107
108




























109
110
111
112
113
114
115
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <poll.h>

#include "cblogweb.h"
#include <kcgi.h>

#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif

ucl_object_t *conf = NULL;
int fd;
const char *unix_sock_path = NULL;









































static void
close_socket(int dummy)
{
	if (fd != -1)
		close(fd);

	if (unix_sock_path)
................................................................................
	if (!check_conf(o))
		return;

	ucl_object_unref(conf);
	conf = o;
}





























int
main(int argc, char **argv, char **envp)
{
	struct sockaddr_un un;
	const ucl_object_t *o;
	struct ucl_parser *p;

................................................................................
		if (strcmp(argv[1], "-d") == 0)
			daemon(0,0);
		else
			err(EXIT_FAILURE, "unknown option: %s", argv[1]);
	} else if (argc > 2)
		err(EXIT_FAILURE, "Too many options");

	close(STDIN_FILENO);
	if (-1 == dup2(fd, STDIN_FILENO))
		err(EXIT_FAILURE, "dup2");
	close(fd);
	cblog(conf);

	close_socket(EXIT_SUCCESS);
	return (0); /* NOT REACHED */
}