Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hamano committed Jan 5, 2012
1 parent 8686227 commit a4d75be
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 45 deletions.
36 changes: 36 additions & 0 deletions README
@@ -0,0 +1,36 @@
mod_diary - simple blog system for Apache HTTPD Server
======================================================

# Download

https://github.com/hamano/apache-mod-diary

# Build

% ./autogen.sh
% ./configure --with-apache=<APACHE_DIR> \
--with-discount=<DISCOUNT_BUILD_DIR> \
--with-clearsilver=<CLEARSILVER_DIR>
% make
# make install

## Dependencies

* discount
- http://www.pell.portland.or.us/~orc/Code/discount/
* ClearSilver

# Configration

httpd.conf

LoadModule diary_module modules/mod_diary.so
<Location />
SetHandler diary
DiaryData /path/to/diary
</Location>

# Author

Tsukasa Hamano <http://twitter.com/hamano>

121 changes: 76 additions & 45 deletions mod_diary.c
Expand Up @@ -6,7 +6,12 @@
** DSO file and install it into Apache's modules directory
** by running:
**
** $ apxs -c -i mod_diary.c
** % ./autogen.sh
** % ./configure --with-apache=<APACHE_DIR> \
** --with-discount=<DISCOUNT_BUILD_DIR> \
** --with-clearsilver=<CLEARSILVER_DIR>
** % make
** # make install
**
** Then activate it in Apache's httpd.conf file for instance
** for the URL /diary in as follows:
Expand All @@ -15,7 +20,7 @@
** LoadModule diary_module modules/mod_diary.so
** <Location /diary>
** SetHandler diary
** DiaryRoot /path/to/diary
** DiaryData /path/to/diary
** DiaryTitle Sample Diary
** </Location>
**
Expand Down Expand Up @@ -49,36 +54,42 @@
#include "apr_strings.h"

#include "mkdio.h"
#include "ClearSilver/ClearSilver.h"
#include "ClearSilver.h"

module AP_MODULE_DECLARE_DATA diary_module;

typedef struct {
apr_pool_t *pool;
int init;
const char *root;
const char *data;
const char *uri;
const char *title;
const char *index_hdf;
const char *theme;
const char *theme_index_cs;
const char *theme_article_cs;
} diary_conf;

#define P(s) ap_rputs(s, r)

static void diary_init(diary_conf *conf)
{
if(!conf->uri) {
conf->uri = "";
}

if(!conf->title){
if(!conf->title) {
conf->title = "My Diary";
}

if(!conf->theme){
if(!conf->theme) {
conf->theme = "default";
}

conf->theme_article_cs =
apr_pstrcat(conf->pool, conf->root, "/themes/", conf->theme,
"/article.cst", NULL);
conf->theme_index_cs =
apr_pstrcat(conf->pool, conf->data, "/themes/", conf->theme,
"/index.cst", NULL);

conf->index_hdf = apr_pstrcat(conf->pool, conf->data, "/index.hdf", NULL);

conf->init = 1;
}
Expand All @@ -89,9 +100,9 @@ static NEOERR *diary_cs_render_cb(void *ctx, char *s)
return STATUS_OK;
}

static int diary_render_entry(request_rec *r,
diary_conf *conf,
const char *filename)
static int diary_process_entry(request_rec *r,
diary_conf *conf,
const char *filename)
{
FILE *fp;
CSPARSE *cs;
Expand Down Expand Up @@ -129,13 +140,18 @@ static int diary_render_entry(request_rec *r,
}
date = mkd_doc_date(doc);

mkd_compile(doc, MKD_TOC|MKD_AUTOLINK);
mkd_compile(doc, MKD_TOC);
if ((size = mkd_document(doc, &p)) == EOF) {
return HTTP_INTERNAL_SERVER_ERROR;
}

hdf_init(&hdf);

hdf_read_file(hdf, conf->index_hdf);
//hdf_dump(hdf, NULL);
hdf_set_value(hdf, "diary.title", conf->title);

hdf_set_value(hdf, "entry.uri", r->uri);
hdf_set_value(hdf, "entry.title", title);
hdf_set_value(hdf, "entry.date", date);
hdf_set_value(hdf, "entry.article", p);
Expand All @@ -146,7 +162,7 @@ static int diary_render_entry(request_rec *r,
}

mkd_cleanup(doc);
cs_parse_file(cs, conf->theme_article_cs);
cs_parse_file(cs, conf->theme_index_cs);

r->content_type = "text/html";
cs_render(cs, r, diary_cs_render_cb);
Expand All @@ -170,58 +186,61 @@ static int diary_handler(request_rec *r)
if (r->header_only) {
return OK;
}
/*
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"diary_handler(): %s", r->filename);
*/
conf = (diary_conf *) ap_get_module_config(r->per_dir_config,
&diary_module);
if(!conf->init){
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "diary_init()");
diary_init(conf);
}
/*
printf("r->uri: %s\n", r->uri);
printf("r->filename: %s\n", r->filename);
printf("r->canonical_filename: %s\n", r->canonical_filename);
printf("r->path_info: %s\n", r->path_info);
printf("r->content_type: %s\n", r->content_type);
printf("conf->root: %s\n", conf->root);
printf("conf->data: %s\n", conf->data);
*/
if (!strcmp(r->path_info, "/")) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"diary_type_checker(): process index");
//ret = diary_process_index(r, conf);
return OK;
}else if(!strncmp(r->path_info, "/feed/", 6)){
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"diary_type_checker(): process feed");
return OK;
}

r->path_info = NULL;

ret = apr_stat(&r->finfo, r->filename, APR_FINFO_MIN, r->pool);
if(!ret){
return DECLINED;
}

filename = apr_pstrcat(r->pool, r->filename, ".md", NULL);
ret = apr_stat(&r->finfo, filename, APR_FINFO_MIN, r->pool);
if(ret){
return DECLINED;
if(!ret){
ret = diary_process_entry(r, conf, filename);
return OK;
}

ret = diary_render_entry(r, conf, filename);
return OK;
return DECLINED;
}

static int diary_type_checker(request_rec *r)
{
diary_conf *conf;

conf = (diary_conf *)ap_get_module_config(r->per_dir_config,
&diary_module);
if(conf->root == NULL) {
if(conf->data == NULL) {
return DECLINED;
}

if (!strcmp(r->path_info, "/")) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"diary_type_checker(): process index");
return OK;
}else if(!strncmp(r->path_info, "/feed/", 6)){
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"diary_type_checker(): process feed");
return OK;
}

r->filename = apr_pstrcat(r->pool, conf->root, r->path_info, NULL);
r->path_info = NULL;

r->filename = apr_pstrcat(r->pool, conf->data, r->path_info, NULL);
return DECLINED;
}

Expand All @@ -233,45 +252,57 @@ static void *diary_config(apr_pool_t *p, char *dummy)
return (void *)c;
}

static const char *set_diary_root(cmd_parms * cmd, void *conf,
static const char *set_diary_data(cmd_parms * cmd, void *conf,
const char *arg)
{
diary_conf *c = (diary_conf *) conf;
c->root = arg;
diary_conf *c = (diary_conf *)conf;
c->data = arg;
return NULL;
}

static const char *set_diary_title(cmd_parms * cmd, void *conf,
const char *arg)
{
diary_conf *c = (diary_conf *) conf;
diary_conf *c = (diary_conf *)conf;
c->title = arg;
return NULL;
}

static const char *set_diary_uri(cmd_parms * cmd, void *conf,
const char *arg)
{
diary_conf *c = (diary_conf *)conf;
c->uri = arg;
return NULL;
}

static const char *set_diary_theme(cmd_parms *cmd, void *conf,
const char *arg)
{
printf("set_diary_theme()\n");
diary_conf *c = (diary_conf *) conf;
diary_conf *c = (diary_conf *)conf;
c->theme = arg;
return NULL;
}

static const command_rec diary_cmds[] = {
AP_INIT_TAKE1("DiaryRoot", set_diary_root, NULL, OR_ALL,
"set DiaryRoot"),
AP_INIT_TAKE1("DiaryData", set_diary_data, NULL, OR_ALL,
"set DiaryData"),
AP_INIT_TAKE1("DiaryUri", set_diary_uri, NULL, OR_ALL,
"set DiaryUri"),
AP_INIT_TAKE1("DiaryTitle", set_diary_title, NULL, OR_ALL,
"set DiaryTitle"),
AP_INIT_TAKE1("DiaryTheme", set_diary_theme, NULL, OR_ALL,
"set DiaryTheme"),
{NULL}
};

static int diary_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
/*
static int diary_post_config(apr_pool_t *p, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
return 0;
}
*/

static void diary_register_hooks(apr_pool_t *p)
{
Expand Down

0 comments on commit a4d75be

Please sign in to comment.