diff --git a/Makefile b/Makefile index 7cb65df1..341167b7 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,6 @@ SRCS = src/version.c \ src/utils.c \ src/wrappers.c \ src/access.c \ - src/dtable.c \ src/tcp.c \ src/udp.c \ src/url.c \ diff --git a/src/channels.c b/src/channels.c index cdca4ef5..084f9c5d 100644 --- a/src/channels.c +++ b/src/channels.c @@ -34,7 +34,7 @@ #include "epg.h" #include "epggrab.h" #include "channels.h" -#include "dtable.h" +#include "access.h" #include "notify.h" #include "dvr/dvr.h" #include "htsp_server.h" diff --git a/src/dtable.c b/src/dtable.c deleted file mode 100644 index f63e75f1..00000000 --- a/src/dtable.c +++ /dev/null @@ -1,243 +0,0 @@ -/** - * Dtable (dyanmic, data, etc) table - * Copyright (C) 2008 Andreas Öman - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "settings.h" - -#include "tvheadend.h" -#include "dtable.h" -#include "notify.h" - -static LIST_HEAD(, dtable) dtables; - -/** - * - */ -void -dtable_store_changed(const dtable_t *dt) -{ - htsmsg_t *m = htsmsg_create_map(); - - htsmsg_add_u32(m, "reload", 1); - notify_by_msg(dt->dt_tablename, m); -} - -/** - * - */ -dtable_t * -dtable_create(const dtable_class_t *dtc, const char *name, void *opaque) -{ - dtable_t *dt = calloc(1, sizeof(dtable_t)); - - dt->dt_opaque = opaque; - dt->dt_tablename = strdup(name); - dt->dt_dtc = dtc; - - LIST_INSERT_HEAD(&dtables, dt, dt_link); - return dt; -} - -/** - * - */ -void -dtable_delete(const char *name) -{ - dtable_t *dt = dtable_find(name); - - if (dt) { - pthread_mutex_lock(&global_lock); - LIST_REMOVE(dt, dt_link); - pthread_mutex_unlock(&global_lock); - free(dt->dt_tablename); - free(dt); - } -} - -/** - * - */ -int -dtable_load(dtable_t *dt) -{ - htsmsg_t *l, *c, *m; - htsmsg_field_t *f; - const char *id; - - int records = 0; - - if((l = hts_settings_load("%s", dt->dt_tablename)) != NULL) { - HTSMSG_FOREACH(f, l) { - if((c = htsmsg_get_map_by_field(f)) == NULL) - continue; - - if((id = htsmsg_get_str(c, "id")) == NULL) - continue; - - m = dt->dt_dtc->dtc_record_update(dt->dt_opaque, id, c, 1); - if(m != NULL) { - records++; - htsmsg_destroy(m); - } - } - htsmsg_destroy(l); - } - return records; -} - - -/** - * - */ -dtable_t * -dtable_find(const char *name) -{ - dtable_t *dt; - LIST_FOREACH(dt, &dtables, dt_link) - if(!strcmp(dt->dt_tablename, name)) - break; - return dt; -} - - -/** - * - */ -int -dtable_record_update_by_array(dtable_t *dt, htsmsg_t *msg) -{ - htsmsg_t *c, *update; - htsmsg_field_t *f; - const char *id; - int changed = 0; - - TAILQ_FOREACH(f, &msg->hm_fields, hmf_link) { - if((c = htsmsg_get_map_by_field(f)) == NULL) - continue; - if((id = htsmsg_get_str(c, "id")) == NULL) - continue; - - if((update = dt->dt_dtc->dtc_record_update(dt->dt_opaque, id, c, 0)) - != NULL) { - /* Data changed */ - changed = 1; - hts_settings_save(update, "%s/%s", dt->dt_tablename, id); - htsmsg_destroy(update); - } - } - if(changed) - dtable_store_changed(dt); - return 0; -} - - -/** - * - */ -void -dtable_record_delete(dtable_t *dt, const char *id) -{ - dt->dt_dtc->dtc_record_delete(dt->dt_opaque, id); - hts_settings_remove("%s/%s", dt->dt_tablename, id); - dtable_store_changed(dt); -} - - -/** - * - */ -int -dtable_record_delete_by_array(dtable_t *dt, htsmsg_t *msg) -{ - htsmsg_field_t *f; - const char *id; - int changed = 0; - - TAILQ_FOREACH(f, &msg->hm_fields, hmf_link) { - if((id = htsmsg_field_get_string(f)) != NULL) { - changed = 1; - dtable_record_delete(dt, id); - } - } - if(changed) - dtable_store_changed(dt); - return 0; -} - - -/** - * - */ -htsmsg_t * -dtable_record_create(dtable_t *dt) -{ - htsmsg_t *r; - const char *id; - - if((r = dt->dt_dtc->dtc_record_create(dt->dt_opaque)) == NULL) - return NULL; - - if((id = htsmsg_get_str(r, "id")) == NULL) { - htsmsg_destroy(r); - return NULL; - } - - hts_settings_save(r, "%s/%s", dt->dt_tablename, id); - return r; -} - - -/** - * - */ -htsmsg_t * -dtable_record_get_all(dtable_t *dt) -{ - return dt->dt_dtc->dtc_record_get_all(dt->dt_opaque); -} - - -/** - * - */ -void -dtable_record_store(dtable_t *dt, const char *id, htsmsg_t *r) -{ - hts_settings_save(r, "%s/%s", dt->dt_tablename, id); -} - - -/** - * - */ -void -dtable_record_erase(dtable_t *dt, const char *id) -{ - hts_settings_remove("%s/%s", dt->dt_tablename, id); -} diff --git a/src/dtable.h b/src/dtable.h deleted file mode 100644 index 033ccec2..00000000 --- a/src/dtable.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Dtable (dyanmic, data, etc) table - * Copyright (C) 2008 Andreas Öman - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef DTABLE_H__ -#define DTABLE_H__ - -#include "htsmsg.h" - -#include "access.h" - -typedef struct dtable_class { - const char *dtc_name; - - htsmsg_t *(*dtc_record_get_all)(void *opaque); - - htsmsg_t *(*dtc_record_get)(void *opaque, const char *id); - - htsmsg_t *(*dtc_record_create)(void *opaque); - - htsmsg_t *(*dtc_record_update)(void *opaque, const char *id, - htsmsg_t *values, int maycreate); - - int (*dtc_record_delete)(void *opaque, const char *id); - - int dtc_read_access; - int dtc_write_access; - - pthread_mutex_t *dtc_mutex; - -} dtable_class_t; - - -typedef struct dtable { - LIST_ENTRY(dtable) dt_link; - - void *dt_opaque; - char *dt_tablename; - - const dtable_class_t *dt_dtc; - -} dtable_t; - -dtable_t *dtable_create(const dtable_class_t *dtc, const char *name, - void *opaque); - -void dtable_delete(const char *name); - -int dtable_load(dtable_t *dt); - -dtable_t *dtable_find(const char *name); - -int dtable_record_update_by_array(dtable_t *dt, htsmsg_t *msg); - -void dtable_record_delete(dtable_t *dt, const char *id); - -int dtable_record_delete_by_array(dtable_t *dt, htsmsg_t *msg); - -htsmsg_t *dtable_record_create(dtable_t *dt); - -htsmsg_t *dtable_record_get_all(dtable_t *dt); - -void dtable_record_store(dtable_t *dt, const char *id, htsmsg_t *r); - -void dtable_record_erase(dtable_t *dt, const char *id); - -void dtable_store_changed(const dtable_t *dt); - -#endif /* DTABLE_H__ */ diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index c7f299ab..56183f2b 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -31,7 +31,6 @@ #include "tvheadend.h" #include "settings.h" #include "dvr.h" -#include "dtable.h" #include "epg.h" #include "htsp_server.h" diff --git a/src/dvr/dvr_timerec.c b/src/dvr/dvr_timerec.c index d9d487d7..e2f0d020 100644 --- a/src/dvr/dvr_timerec.c +++ b/src/dvr/dvr_timerec.c @@ -31,7 +31,6 @@ #include "tvheadend.h" #include "settings.h" #include "dvr.h" -#include "dtable.h" #include "epg.h" static int dvr_timerec_in_init = 0; diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 8917e460..ce4e4385 100755 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -34,7 +34,6 @@ #include "http.h" #include "webui.h" #include "access.h" -#include "dtable.h" #include "channels.h" #include "dvr/dvr.h" @@ -275,86 +274,6 @@ page_about(http_connection_t *hc, const char *remain, void *opaque) return 0; } -/** - * - */ -static int -extjs_tablemgr(http_connection_t *hc, const char *remain, void *opaque) -{ - htsbuf_queue_t *hq = &hc->hc_reply; - dtable_t *dt; - htsmsg_t *out = NULL, *in, *array; - - const char *tablename = http_arg_get(&hc->hc_req_args, "table"); - const char *op = http_arg_get(&hc->hc_req_args, "op"); - const char *entries = http_arg_get(&hc->hc_req_args, "entries"); - - if(op == NULL) - return 400; - - if(tablename == NULL || (dt = dtable_find(tablename)) == NULL) - return 404; - - if(http_access_verify(hc, dt->dt_dtc->dtc_read_access)) - return HTTP_STATUS_UNAUTHORIZED; - - in = entries != NULL ? htsmsg_json_deserialize(entries) : NULL; - - pthread_mutex_lock(dt->dt_dtc->dtc_mutex); - - if(!strcmp(op, "create")) { - if(http_access_verify(hc, dt->dt_dtc->dtc_write_access)) - goto noaccess; - - out = dtable_record_create(dt); - - } else if(!strcmp(op, "get")) { - array = dtable_record_get_all(dt); - - out = htsmsg_create_map(); - htsmsg_add_msg(out, "entries", array); - - } else if(!strcmp(op, "update")) { - if(http_access_verify(hc, dt->dt_dtc->dtc_write_access)) - goto noaccess; - - if(in == NULL) - goto bad; - - dtable_record_update_by_array(dt, in); - - } else if(!strcmp(op, "delete")) { - if(http_access_verify(hc, dt->dt_dtc->dtc_write_access)) - goto noaccess; - - if(in == NULL) - goto bad; - - dtable_record_delete_by_array(dt, in); - - } else { - bad: - pthread_mutex_unlock(dt->dt_dtc->dtc_mutex); - return HTTP_STATUS_BAD_REQUEST; - - noaccess: - pthread_mutex_unlock(dt->dt_dtc->dtc_mutex); - return HTTP_STATUS_BAD_REQUEST; - } - - pthread_mutex_unlock(dt->dt_dtc->dtc_mutex); - - if(in != NULL) - htsmsg_destroy(in); - - if(out == NULL) - out = htsmsg_create_map(); - htsmsg_json_serialize(out, hq, 0); - htsmsg_destroy(out); - http_output_content(hc, "text/x-json; charset=UTF-8"); - return 0; -} - /** * */ @@ -810,7 +729,6 @@ extjs_start(void) http_path_add("/extjs.html", NULL, extjs_root, ACCESS_WEB_INTERFACE); http_path_add("/tv.html", NULL, extjs_livetv, ACCESS_WEB_INTERFACE); http_path_add("/capabilities", NULL, extjs_capabilities, ACCESS_WEB_INTERFACE); - http_path_add("/tablemgr", NULL, extjs_tablemgr, ACCESS_WEB_INTERFACE); http_path_add("/epggrab", NULL, extjs_epggrab, ACCESS_WEB_INTERFACE); http_path_add("/config", NULL, extjs_config, ACCESS_WEB_INTERFACE); http_path_add("/languages", NULL, extjs_languages, ACCESS_WEB_INTERFACE);