Check-in [8322e0fbb0]

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

Overview
Comment:Print all pages
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | scgi
Files: files | file ages | folders
SHA1:8322e0fbb00ecc4ea8e860fdc86c07c3d3cf8c0a
User & Date: bapt 2015-04-23 14:45:20
Context
2015-04-23
14:47
Redirect /post to / check-in: e75b1fb47d user: bapt tags: scgi
14:45
Print all pages check-in: 8322e0fbb0 user: bapt tags: scgi
14:22
Parge uri check-in: d872ddcfc0 user: bapt tags: scgi
Changes

Changes to web/cblogweb.c.

57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
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
183
...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
...
424
425
426
427
428
429
430

431
432
433
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
...
491
492
493
494
495
496
497

498
499
500
501

502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521



522






523
524
525
526
527
528
529
	bool feed;
	const char *timefmt;
	const char *tagname;
	int64_t start;
	int64_t end;
};

int
add_posts(ucl_object_t *out, sqlite3_stmt *stmt, sqlite3 *sqlite)
{
	char *filename = NULL;
	int icol;
	sqlite3_stmt *stmt2;
	ucl_object_t *posts, *post, *tags, *o;


	if (sqlite3_prepare_v2(sqlite,
	    "SELECT tag FROM tags, tags_posts, posts WHERE link=?1 AND posts.id=post_id and tag_id=tags.id;",
	    -1, &stmt2, NULL) != SQLITE_OK) {
		syslog(LOG_ERR, "%s", sqlite3_errmsg(sqlite));
		return 0;
	}

	posts = ucl_object_typed_new(UCL_ARRAY);
	while (sqlite3_step(stmt) == SQLITE_ROW) {

		sqlite3_reset(stmt2);
		post = ucl_object_typed_new(UCL_OBJECT);
		for (icol = 0; icol < sqlite3_column_count(stmt); icol++) {
			switch (sqlite3_column_type(stmt, icol)) {
			case SQLITE_TEXT:
				if (strcmp(sqlite3_column_name(stmt, icol), "filename") == 0) {
					filename = (char*)sqlite3_column_text(stmt, icol);
................................................................................
		ucl_object_insert_key(post, tags, "tags", 0, false);
		ucl_array_append(posts, post);
	}
	ucl_object_insert_key(out, posts, "Posts", 0, false);

	sqlite3_finalize(stmt2);

	return (0);
}

void
set_tags(ucl_object_t *out, sqlite3 *sqlite)
{
	sqlite3_stmt *stmt;
	ucl_object_t *array, *tag;
................................................................................
		ucl_array_append(array, tag);
	}
	ucl_object_insert_key(out, array, "Tags", 0, false);

	sqlite3_finalize(stmt);
}

int
build_post(ucl_object_t *conf, ucl_object_t *out, const char *postname, sqlite3 *sqlite)
{
	sqlite3_stmt *stmt;
	int ret=0;

	if (sqlite3_prepare_v2(sqlite,
		"SELECT link as filename, title, source, html, strftime(?2, datetime(date, 'unixepoch')) as date from posts "
		"WHERE link=?1 ;",
		-1, &stmt, NULL) != SQLITE_OK) {
		syslog(LOG_ERR, "%s", sqlite3_errmsg(sqlite));
		return 0;
	}

	sqlite3_bind_text(stmt, 1, postname, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 2, ucl_get_string(conf, "dateformat"),
	    -1, SQLITE_STATIC);

	ret = add_posts(out, stmt, sqlite);
	sqlite3_finalize(stmt);
//	get_comments(hdf, postname, sqlite);

	return ret;
}

void
build_index(struct kreq *r, ucl_object_t *conf, ucl_object_t *out,
    struct criteria *criteria, sqlite3 *sqlite)
{
	sqlite3_stmt *stmt, *stmtcnt;
................................................................................

void
cblog(ucl_object_t *conf)
{
	const char *reqpath, *tplpath;
	struct ucltpl_parser tpl;
	char cspath[MAXPATHLEN];
	int type, nb_posts;
	int yyyy, mm, dd;
	struct criteria criteria;
	char *date = NULL;
	sqlite3 *sqlite;
	int comment = CBLOG_COMMENT_NONE;
	struct kreq r;
	ucl_object_t *out;
................................................................................
	sqlite3_open(ucl_get_string(conf,"db_path"), &sqlite);
	if (criteria.timefmt == NULL)
		criteria.timefmt = ucl_get_string(conf, "dateformat");

	reqpath = r.path;
	switch (type) {
		case CBLOG_POST:

			reqpath++;
			while (reqpath[0] != '/')
				reqpath++;
			reqpath++;

			if (comment == CBLOG_COMMENT_POST) {
				//set_comment(&h, reqpath, hdf_get_value(out, "antispamres", NULL), sqlite);
				type = CBLOG_POST_REDIRECT;
				break;
			}
			nb_posts = build_post(conf, out, reqpath, sqlite);
			if (nb_posts == 0) {
				//hdf_set_valuef(out, "err_msg=Unknown post: %s", reqpath);

				type = CBLOG_ERR;
			}
			break;
		case CBLOG_TAG:
			reqpath++;
			while (reqpath[0] != '/')
				reqpath++;
................................................................................

			khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
			    "application/atom+xml");

			strlcat(cspath, "/atom.cs", MAXPATHLEN);
			break;
		case CBLOG_ERR:

			khttp_head(&r, kresps[KRESP_STATUS],
			    "%s", khttps[KHTTP_404]);
			break;
		case CBLOG_POST_REDIRECT:

			khttp_head(&r, kresps[KRESP_LOCATION], "%s", reqpath);
			khttp_head(&r, kresps[KRESP_STATUS],
			    "%s", khttps[KHTTP_302]);
			khttp_body(&r);
			break;
		default:
			khttp_head(&r, kresps[KRESP_CONTENT_TYPE], "%s ; charset=UTF-8",
			    kmimetypes[KMIME_TEXT_HTML]);
			if (type == CBLOG_POST)
				set_tags(out, sqlite);
			bzero(&tpl, sizeof(tpl));
			if (r.fieldmap[KEY_VIEWSOURCE] != NULL)
				ucl_object_insert_key(out, ucl_object_frombool(true), "viewsource", 0, false);
			tpl.udata = &r;
			tpl.data = out;
			tpl.addchar = &cblog_putc;
			tpl.addstr = &cblog_puts;
			snprintf(cspath, MAXPATHLEN, "%s/default.cs", tplpath);
			khttp_head(&r, kresps[KRESP_STATUS],
			    "%s", khttps[KHTTP_200]);



			khttp_body(&r);






			ucltpl_process_file(&tpl, cspath);
			break;
	}
	sqlite3_close(sqlite);
	khttp_free(&r);
	exit(0);
}







|






>





|




>







 







|







 







|



|






|










|







 







|







 







>

|








|
|
|
>







 







>




>



|






<


<
<
<
<



>
>
>
|
>
>
>
>
>
>
|
<
|




57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
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
183
184
185
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

518
519




520
521
522
523
524
525
526
527
528
529
530
531
532
533

534
535
536
537
538
	bool feed;
	const char *timefmt;
	const char *tagname;
	int64_t start;
	int64_t end;
};

bool
add_posts(ucl_object_t *out, sqlite3_stmt *stmt, sqlite3 *sqlite)
{
	char *filename = NULL;
	int icol;
	sqlite3_stmt *stmt2;
	ucl_object_t *posts, *post, *tags, *o;
	bool ret = false;

	if (sqlite3_prepare_v2(sqlite,
	    "SELECT tag FROM tags, tags_posts, posts WHERE link=?1 AND posts.id=post_id and tag_id=tags.id;",
	    -1, &stmt2, NULL) != SQLITE_OK) {
		syslog(LOG_ERR, "%s", sqlite3_errmsg(sqlite));
		return (ret);
	}

	posts = ucl_object_typed_new(UCL_ARRAY);
	while (sqlite3_step(stmt) == SQLITE_ROW) {
		ret = true;
		sqlite3_reset(stmt2);
		post = ucl_object_typed_new(UCL_OBJECT);
		for (icol = 0; icol < sqlite3_column_count(stmt); icol++) {
			switch (sqlite3_column_type(stmt, icol)) {
			case SQLITE_TEXT:
				if (strcmp(sqlite3_column_name(stmt, icol), "filename") == 0) {
					filename = (char*)sqlite3_column_text(stmt, icol);
................................................................................
		ucl_object_insert_key(post, tags, "tags", 0, false);
		ucl_array_append(posts, post);
	}
	ucl_object_insert_key(out, posts, "Posts", 0, false);

	sqlite3_finalize(stmt2);

	return (ret);
}

void
set_tags(ucl_object_t *out, sqlite3 *sqlite)
{
	sqlite3_stmt *stmt;
	ucl_object_t *array, *tag;
................................................................................
		ucl_array_append(array, tag);
	}
	ucl_object_insert_key(out, array, "Tags", 0, false);

	sqlite3_finalize(stmt);
}

bool
build_post(ucl_object_t *conf, ucl_object_t *out, const char *postname, sqlite3 *sqlite)
{
	sqlite3_stmt *stmt;
	bool ret = false;

	if (sqlite3_prepare_v2(sqlite,
		"SELECT link as filename, title, source, html, strftime(?2, datetime(date, 'unixepoch')) as date from posts "
		"WHERE link=?1 ;",
		-1, &stmt, NULL) != SQLITE_OK) {
		syslog(LOG_ERR, "%s", sqlite3_errmsg(sqlite));
		return (ret);
	}

	sqlite3_bind_text(stmt, 1, postname, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 2, ucl_get_string(conf, "dateformat"),
	    -1, SQLITE_STATIC);

	ret = add_posts(out, stmt, sqlite);
	sqlite3_finalize(stmt);
//	get_comments(hdf, postname, sqlite);

	return (ret);
}

void
build_index(struct kreq *r, ucl_object_t *conf, ucl_object_t *out,
    struct criteria *criteria, sqlite3 *sqlite)
{
	sqlite3_stmt *stmt, *stmtcnt;
................................................................................

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;
	char *date = NULL;
	sqlite3 *sqlite;
	int comment = CBLOG_COMMENT_NONE;
	struct kreq r;
	ucl_object_t *out;
................................................................................
	sqlite3_open(ucl_get_string(conf,"db_path"), &sqlite);
	if (criteria.timefmt == NULL)
		criteria.timefmt = ucl_get_string(conf, "dateformat");

	reqpath = r.path;
	switch (type) {
		case CBLOG_POST:
			warnx("ixi %d", type);
			reqpath++;
			while (*reqpath && reqpath[0] != '/')
				reqpath++;
			reqpath++;

			if (comment == CBLOG_COMMENT_POST) {
				//set_comment(&h, reqpath, hdf_get_value(out, "antispamres", NULL), sqlite);
				type = CBLOG_POST_REDIRECT;
				break;
			}
			if (!build_post(conf, out, reqpath, sqlite)) {
				char *err_msg;
				asprintf(&err_msg, "Unknown post: %s", reqpath);
				ucl_object_insert_key(out, ucl_object_fromstring(err_msg), "err_msg", 0, false);
				type = CBLOG_ERR;
			}
			break;
		case CBLOG_TAG:
			reqpath++;
			while (reqpath[0] != '/')
				reqpath++;
................................................................................

			khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
			    "application/atom+xml");

			strlcat(cspath, "/atom.cs", MAXPATHLEN);
			break;
		case CBLOG_ERR:
			snprintf(cspath, MAXPATHLEN, "%s/default.cs", tplpath);
			khttp_head(&r, kresps[KRESP_STATUS],
			    "%s", khttps[KHTTP_404]);
			break;
		case CBLOG_POST_REDIRECT:
			snprintf(cspath, MAXPATHLEN, "%s/default.cs", tplpath);
			khttp_head(&r, kresps[KRESP_LOCATION], "%s", reqpath);
			khttp_head(&r, kresps[KRESP_STATUS],
			    "%s", khttps[KHTTP_302]);
			set_tags(out, sqlite);
			break;
		default:
			khttp_head(&r, kresps[KRESP_CONTENT_TYPE], "%s ; charset=UTF-8",
			    kmimetypes[KMIME_TEXT_HTML]);
			if (type == CBLOG_POST)
				set_tags(out, sqlite);

			if (r.fieldmap[KEY_VIEWSOURCE] != NULL)
				ucl_object_insert_key(out, ucl_object_frombool(true), "viewsource", 0, false);




			snprintf(cspath, MAXPATHLEN, "%s/default.cs", tplpath);
			khttp_head(&r, kresps[KRESP_STATUS],
			    "%s", khttps[KHTTP_200]);
			break;
	}

	khttp_body(&r);
	warnx("%s", ucl_object_emit(out, UCL_EMIT_CONFIG));
	bzero(&tpl, sizeof(tpl));
	tpl.udata = &r;
	tpl.data = out;
	tpl.addchar = &cblog_putc;
	tpl.addstr = &cblog_puts;
	ucltpl_process_file(&tpl, cspath);


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