Skip to content

Commit

Permalink
added styling option for parent collection icon. Added display of cur…
Browse files Browse the repository at this point in the history
…rent user to the directory listings. Moved to html5 elements
  • Loading branch information
billyfish committed Sep 28, 2016
1 parent bd348ad commit 731d5d6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
16 changes: 16 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void *davrods_create_dir_config(apr_pool_t *p, char *dir) {
conf -> theme.ht_bottom_s = NULL;
conf -> theme.ht_collection_icon_s = NULL;
conf -> theme.ht_object_icon_s = NULL;
conf -> theme.ht_parent_icon_s = NULL;
conf -> theme.ht_show_metadata = 0;
}
return conf;
Expand Down Expand Up @@ -123,6 +124,7 @@ void *davrods_merge_dir_config(apr_pool_t *p, void *_parent, void *_child) {
DAVRODS_PROP_MERGE(theme.ht_bottom_s);
DAVRODS_PROP_MERGE(theme.ht_collection_icon_s);
DAVRODS_PROP_MERGE(theme.ht_object_icon_s);
DAVRODS_PROP_MERGE(theme.ht_parent_icon_s);
DAVRODS_PROP_MERGE(theme.ht_show_metadata);

assert(set_exposed_root(conf, exposed_root) >= 0);
Expand Down Expand Up @@ -355,6 +357,16 @@ static const char *cmd_davrods_html_object_icon (cmd_parms *cmd_p, void *config_
}



static const char *cmd_davrods_html_parent_icon (cmd_parms *cmd_p, void *config_p, const char *arg_p)
{
davrods_dir_conf_t *conf_p = (davrods_dir_conf_t*) config_p;

conf_p -> theme.ht_parent_icon_s = arg_p;

return NULL;
}

static const char *cmd_davrods_html_metadata (cmd_parms *cmd_p, void *config_p, const char *arg_p)
{
davrods_dir_conf_t *conf_p = (davrods_dir_conf_t*) config_p;
Expand Down Expand Up @@ -458,6 +470,10 @@ const command_rec davrods_directives[] = {
NULL, ACCESS_CONF, "Icon to use for data objects"
),

AP_INIT_TAKE1(
DAVRODS_CONFIG_PREFIX "HTMLParentIcon", cmd_davrods_html_parent_icon,
NULL, ACCESS_CONF, "Icon to use for parent link in the directory listings"
),

AP_INIT_TAKE1(
DAVRODS_CONFIG_PREFIX "HTMLMetadata", cmd_davrods_html_metadata,
Expand Down
2 changes: 2 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct html_theme

const char *ht_object_icon_s;

const char *ht_parent_icon_s;

int ht_show_metadata;
};

Expand Down
57 changes: 37 additions & 20 deletions repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,10 @@ static dav_error *deliver_directory(

static dav_error *deliver_directory_themed (const dav_resource *resource, ap_filter_t *output)
{
// Print a basic HTML directory listing.
struct dav_resource_private *davrods_resource_p = (struct dav_resource_private *) resource -> info;
// Print a basic HTML directory listing.
collInp_t coll_inp = {{ 0 }};
strcpy(coll_inp.collName, resource->info->rods_path);
strcpy(coll_inp.collName, davrods_resource_p ->rods_path);

collHandle_t coll_handle = { 0 };

Expand All @@ -1180,14 +1181,14 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil
);

if (status < 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_SUCCESS, resource->info->r,
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_SUCCESS, davrods_resource_p->r,
"rcOpenCollection failed: %d = %s", status, get_rods_error_msg(status));

return dav_new_error(resource->pool, HTTP_INTERNAL_SERVER_ERROR, 0, status,
"Could not open a collection");
}

davrods_dir_conf_t *conf_p = resource -> info -> conf;
davrods_dir_conf_t *conf_p = davrods_resource_p-> conf;
struct html_theme *theme_p = & (conf_p -> theme);

// Make brigade.
Expand All @@ -1197,8 +1198,8 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil

// Send start of HTML document.
apr_brigade_printf(bb, NULL, NULL, "<!DOCTYPE html>\n<html>\n<head><title>Index of %s on %s</title>\n",
ap_escape_html(pool, resource->info->relative_uri),
ap_escape_html(pool, resource->info->conf->rods_zone));
ap_escape_html(pool, davrods_resource_p->relative_uri),
ap_escape_html(pool, conf_p->rods_zone));


// WHISPER("head \"%s\"", theme_p -> ht_head_s);
Expand All @@ -1214,7 +1215,7 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil

if (apr_ret != APR_SUCCESS)
{
ap_log_rerror (APLOG_MARK, APLOG_ERR, APR_SUCCESS, resource->info->r,
ap_log_rerror (APLOG_MARK, APLOG_ERR, APR_SUCCESS, davrods_resource_p->r,
"Failed to add html to <head> section \"%s\"",
theme_p -> ht_head_s);

Expand All @@ -1236,20 +1237,36 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil

if (apr_ret != APR_SUCCESS)
{
ap_log_rerror (APLOG_MARK, APLOG_ERR, APR_SUCCESS, resource->info->r,
ap_log_rerror (APLOG_MARK, APLOG_ERR, APR_SUCCESS, davrods_resource_p->r,
"Failed to add html to top section \"%s\"",
theme_p -> ht_top_s);

} /* if (apr_ret != APR_SUCCESS) */
}


apr_brigade_printf (bb, NULL, NULL, "<h1>Index of %s on %s</h1>\n",
ap_escape_html(pool, resource->info->relative_uri),
ap_escape_html(pool, resource->info->conf->rods_zone));
apr_brigade_printf (bb, NULL, NULL, "<main>\n<h1>You are logged in as %s and browsing the index of %s on %s</h1>\n",
davrods_resource_p -> rods_conn -> clientUser.userName,
ap_escape_html(pool, davrods_resource_p->relative_uri),
ap_escape_html(pool, conf_p->rods_zone));

if (strcmp(resource->info->relative_uri, "/"))
apr_brigade_puts(bb, NULL, NULL, "<p><a href=\"..\">↖ Parent collection</a></p>\n");
if (strcmp(davrods_resource_p->relative_uri, "/"))
{
apr_brigade_puts (bb, NULL, NULL, "<p><a href=\"..\">");

if (theme_p -> ht_parent_icon_s)
{
apr_brigade_printf (bb, NULL, NULL, "<img src=\"%s\" />", ap_escape_html (pool, theme_p -> ht_parent_icon_s));
}
else
{
apr_brigade_puts (bb, NULL, NULL, "↖");
}

apr_brigade_puts (bb, NULL, NULL, " Parent collection</a></p>\n");


}

apr_brigade_puts(bb, NULL, NULL,
"<table class=\"listing\">\n<thead>\n<tr>");
Expand All @@ -1271,15 +1288,15 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil

// Actually print the directory listing, one table row at a time.
do {
status = rclReadCollection(resource->info->rods_conn, &coll_handle, &coll_entry);
status = rclReadCollection(davrods_resource_p->rods_conn, &coll_handle, &coll_entry);

if (status < 0) {
if (status == CAT_NO_ROWS_FOUND) {
// End of collection.
} else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_SUCCESS, resource->info->r,
ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_SUCCESS, davrods_resource_p->r,
"rcReadCollection failed for collection <%s> with error <%s>",
resource->info->rods_path, get_rods_error_msg(status));
davrods_resource_p->rods_path, get_rods_error_msg(status));

apr_brigade_destroy(bb);

Expand Down Expand Up @@ -1330,9 +1347,9 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil
// Fancy file size formatting.
apr_strfsize(coll_entry.dataSize, size_buf);
if (size_buf[0])
apr_brigade_printf(bb, NULL, NULL, "<td class=\"size\">%s</td>", size_buf);
apr_brigade_printf(bb, NULL, NULL, "<td class=\"size\">%sB</td>", size_buf);
else
apr_brigade_printf(bb, NULL, NULL, "<td class=\"size\">%lu</td>", coll_entry.dataSize);
apr_brigade_printf(bb, NULL, NULL, "<td class=\"size\">%luB</td>", coll_entry.dataSize);
} else {
apr_brigade_puts(bb, NULL, NULL, "<td class=\"size\"></td>");
}
Expand Down Expand Up @@ -1388,15 +1405,15 @@ static dav_error *deliver_directory_themed (const dav_resource *resource, ap_fil
} while (status >= 0);

// End HTML document.
apr_brigade_puts(bb, NULL, NULL, "</tbody>\n</table>\n");
apr_brigade_puts(bb, NULL, NULL, "</tbody>\n</table>\n</main>\n");

if (theme_p -> ht_bottom_s)
{
apr_status_t apr_ret = apr_brigade_puts (bb, NULL, NULL, theme_p -> ht_bottom_s);

if (apr_ret != APR_SUCCESS)
{
ap_log_rerror (APLOG_MARK, APLOG_ERR, APR_SUCCESS, resource->info->r,
ap_log_rerror (APLOG_MARK, APLOG_ERR, APR_SUCCESS, davrods_resource_p->r,
"Failed to add html to bottom section \"%s\"",
theme_p -> ht_bottom_s);

Expand Down

0 comments on commit 731d5d6

Please sign in to comment.