Exemple #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;
}
Exemple #2
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 = NULL;
  char *req = (char *)http_arg_get_req(hc, "requests");
  char *request;
  char *saved;

  if(req == NULL)
    return 404;

  htsbuf_queue_init(&out, 0);

  switch(method) {
  case HTTP_CMD_POST:
    for (request = strtok_r(req, ",", &saved);
         request;
         request = strtok_r(NULL, ",", &saved))
    {
      p = prop_from_path(request);
      if (p == NULL) {
        htsbuf_qprintf(&out, "error:404");
      }
      else {
        r = prop_get_string(p, NULL);

        if(r == NULL) {

          char **childs = prop_get_name_of_childs(p);
          if(childs == NULL) {
            htsbuf_qprintf(&out, "error:404");
          }
          else {
            htsbuf_qprintf(&out, "dir");
            for(i = 0; childs[i] != NULL; i++) {
	      htsbuf_qprintf(&out, "%c%s", i ? ',' : ':', childs[i]);
            }
          }
        } else {
          htsbuf_qprintf(&out, "value:");
          htsbuf_append(&out, rstr_get(r), strlen(rstr_get(r)));
          rstr_release(r);
        }
      }
      htsbuf_append(&out, "\n", 1);
    }
    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;
}