示例#1
0
static int
hc_prop(http_connection_t *hc, const char *remain, void *opaque,
        http_cmd_t method)
{
    htsbuf_queue_t out;
    rstr_t *r;
    int rval, i;
    prop_t *p;
    const char *action = http_arg_get_req(hc, "action");

    if(remain == NULL)
        return 404;

    p = prop_from_path(remain);

    if(p == NULL)
        return 404;

    htsbuf_queue_init(&out, 0);

    switch(method) {
    case HTTP_CMD_GET:

        if(action != NULL) {
            event_t *e = event_create_action_str(action);
            prop_send_ext_event(p, e);
            event_release(e);
            rval = HTTP_STATUS_OK;
            break;
        }

        r = prop_get_string(p, NULL);

        if(r == NULL) {

            char **childs = prop_get_name_of_childs(p);
            if(childs == NULL) {
                rval = HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE;
                break;
            }
            for(i = 0; childs[i] != NULL; i++) {
                htsbuf_qprintf(&out, "\t%s\n", childs[i]);
            }
        } else {
            htsbuf_append(&out, rstr_get(r), strlen(rstr_get(r)));
            htsbuf_append(&out, "\n", 1);
            rstr_release(r);
        }
        rval = http_send_reply(hc, 0, "text/ascii", NULL, NULL, 0, &out);
        break;

    default:
        rval = HTTP_STATUS_METHOD_NOT_ALLOWED;
        break;
    }

    prop_ref_dec(p);

    return rval;
}
示例#2
0
static int
hc_action(http_connection_t *hc, const char *remain, void *opaque,
	  http_cmd_t method)
{
  if(remain == NULL)
    return 404;

  event_to_ui(event_create_action_str(remain));
  return HTTP_STATUS_OK;
}