예제 #1
0
static int
hc_utf8(http_connection_t *hc, const char *remain, void *opaque,
	http_cmd_t method)
{
  const char *str = http_arg_get_req(hc, "str");
  int c;
  event_t *e;

  if(str == NULL)
    return HTTP_STATUS_BAD_REQUEST;

  while((c = utf8_get(&str)) != 0) {
    switch(c) {
    case 8:
      e = event_create_action_multi(
				    (const action_type_t[]){
				      ACTION_BS, ACTION_NAV_BACK}, 2);
      break;

    default:
      e = event_create_int(EVENT_UNICODE, c);
      break;
    }
    event_to_ui(e);
  }
예제 #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;
    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;
}
예제 #3
0
static int
hc_open(http_connection_t *hc, const char *remain, void *opaque,
	http_cmd_t method)
{
  htsbuf_queue_t out;

  const char *url = http_arg_get_req(hc, "url");

  if(url != NULL) {
    event_dispatch(event_create_openurl(url, NULL, NULL, NULL, NULL, NULL));
    return http_redirect(hc, "/showtime/open");
  }

  htsbuf_queue_init(&out, 0);
  htsbuf_append(&out, openpage, strlen(openpage));
  return http_send_reply(hc, 0, "text/html", NULL, NULL, 0, &out);
}
예제 #4
0
static int
hc_root_old(http_connection_t *hc)
{
  htsbuf_queue_t out;

  const char *url = http_arg_get_req(hc, "url");

  if(url != NULL) {
    event_dispatch(event_create_openurl(url, NULL, NULL, NULL, NULL, NULL));
    return http_redirect(hc, "/");
  }

  htsbuf_queue_init(&out, 0);

  htsbuf_qprintf(&out, 
		 "<html><body>"
		 "<h2>%s</h2><p>Version %s"
		 , gconf.system_name,
		 htsversion_full);

  htsbuf_qprintf(&out, 
		 "<form name=\"input\" method=\"get\">"
		 "Open URL in Showtime: "
		 "<input type=\"text\" name=\"url\" style=\"width:500px\"/>"
		 "<input type=\"submit\" value=\"Open\" />"
		 "</form>");
  
  htsbuf_qprintf(&out, "<h3>Diagnostics</h3>"); 

  diag_html(hc, &out);

  htsbuf_qprintf(&out, "<p><a href=\"/showtime/translation\">Upload and test new translation (.lang) file</a></p>");

  htsbuf_qprintf(&out, "</body></html>");
		 
  return http_send_reply(hc, 0, "text/html", NULL, NULL, 0, &out);
}
예제 #5
0
static int
hc_image(http_connection_t *hc, const char *remain, void *opaque,
	http_cmd_t method)
{
  htsbuf_queue_t out;
  image_t *img;
  char errbuf[200];
  const char *content;
  image_meta_t im = {0};
  im.im_no_decoding = 1;
  rstr_t *url;
  const char *u = http_arg_get_req(hc, "url");
  
  if(u != NULL) {
    url = rstr_alloc(u);
    url_deescape(rstr_data(url));
  } else {
    if(remain == NULL) {
      return 404;
    }
    url = rstr_alloc(remain);
  }

  img = backend_imageloader(url, &im, NULL, errbuf, sizeof(errbuf), NULL,
                            NULL);
  rstr_release(url);
  if(img == NULL)
    return http_error(hc, 404, "Unable to load image %s : %s",
		      remain, errbuf);

  const image_component_t *ic = image_find_component(img, IMAGE_CODED);
  if(ic == NULL) {
    image_release(img);
    return http_error(hc, 404,
		      "Unable to load image %s : Original data not available",
		      remain);
  }
  const image_component_coded_t *icc = &ic->coded;

  htsbuf_queue_init(&out, 0);
  htsbuf_append(&out, buf_cstr(icc->icc_buf), buf_len(icc->icc_buf));

  switch(icc->icc_type) {
  case IMAGE_JPEG:
    content = "image/jpeg";
    break;
  case IMAGE_PNG:
    content = "image/png";
    break;
  case IMAGE_GIF:
    content = "image/gif";
    break;
  default:
    content = "image";
    break;
  }

  image_release(img);

  return http_send_reply(hc, 0, content, NULL, NULL, 0, &out);
}
예제 #6
0
파일: httpcontrol.c 프로젝트: djd2/showtime
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;
}