Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WEBUI JS: General config - split base/imgcache/sat>ip srv
  • Loading branch information
perexg committed Jun 26, 2015
1 parent a383bac commit 4aba948
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 224 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -209,7 +209,8 @@ SRCS-2 = \
src/api/api_caclient.c \
src/api/api_profile.c \
src/api/api_bouquet.c \
src/api/api_language.c
src/api/api_language.c \
src/api/api_satip.c

SRCS-2 += \
src/parsers/parsers.c \
Expand Down
1 change: 1 addition & 0 deletions src/api.c
Expand Up @@ -137,6 +137,7 @@ void api_init ( void )
api_caclient_init();
api_profile_init();
api_language_init();
api_satip_server_init();
}

void api_done ( void )
Expand Down
1 change: 1 addition & 0 deletions src/api.h
Expand Up @@ -77,6 +77,7 @@ void api_dvr_init ( void );
void api_caclient_init ( void );
void api_profile_init ( void );
void api_language_init ( void );
void api_satip_server_init ( void );

/*
* IDnode
Expand Down
74 changes: 74 additions & 0 deletions src/api/api_satip.c
@@ -0,0 +1,74 @@
/*
* API - SAT>IP Server related calls
*
* Copyright (C) 2015 Jaroslav Kysela
*
* 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; withm 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 <http://www.gnu.org/licenses/>.
*/

#include "tvheadend.h"
#include "channels.h"
#include "access.h"
#include "api.h"
#include "satip/server.h"

#if ENABLE_SATIP_SERVER

static int
api_satip_server_load
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_t *l;
pthread_mutex_lock(&global_lock);
*resp = htsmsg_create_map();
l = htsmsg_create_list();
htsmsg_add_msg(l, NULL, satip_server_get_config());
htsmsg_add_msg(*resp, "entries", l);
pthread_mutex_unlock(&global_lock);
return 0;
}

static int
api_satip_server_save
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
pthread_mutex_lock(&global_lock);
if (satip_server_set_config(args))
satip_server_save();
pthread_mutex_unlock(&global_lock);
*resp = htsmsg_create_map();
htsmsg_add_u32(*resp, "success", 1);
return 0;
}

void
api_satip_server_init ( void )
{
static api_hook_t ah[] = {
{ "satips/config/load", ACCESS_ADMIN, api_satip_server_load, NULL },
{ "satips/config/save", ACCESS_ADMIN, api_satip_server_save, NULL },
{ NULL },
};

api_register_all(ah);
}

#else /* ENABLE_SATIP_SERVER */

void
api_satip_server_init ( void )
{
}

#endif
32 changes: 30 additions & 2 deletions src/config.c
Expand Up @@ -1593,9 +1593,37 @@ void config_save ( void )
* Access / Update routines
* *************************************************************************/

htsmsg_t *config_get_all ( void )
htsmsg_t *config_get_all ( int satip )
{
return htsmsg_copy(config);
htsmsg_field_t *f;
htsmsg_t *r;
const char *s;
int64_t s64;
int m, b;

r = htsmsg_create_map();
HTSMSG_FOREACH(f, config) {
m = strncmp(f->hmf_name, "satip_", 6);
if (satip && m) continue;
if (!satip && !m) continue;
switch (f->hmf_type) {
case HMF_STR:
s = htsmsg_field_get_str(f);
if (s)
htsmsg_add_str(r, f->hmf_name, s);
break;
case HMF_S64:
if (!htsmsg_field_get_s64(f, &s64))
htsmsg_add_s64(r, f->hmf_name, s64);
break;
case HMF_BOOL:
if (!htsmsg_field_get_bool(f, &b))
htsmsg_add_bool(r, f->hmf_name, b);
break;
default: abort();
}
}
return r;
}

const char *
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Expand Up @@ -29,7 +29,7 @@ void config_init ( int backup );
void config_done ( void );
void config_save ( void );

htsmsg_t *config_get_all ( void );
htsmsg_t *config_get_all ( int satip );

const char *config_get_str ( const char *fld );
int config_set_str ( const char *fld, const char *val );
Expand Down
38 changes: 37 additions & 1 deletion src/satip/server.c
Expand Up @@ -529,10 +529,11 @@ static void satip_server_info(const char *prefix, int descramble, int muxcnf)
/*
*
*/
void satip_server_config_changed(void)
void satip_server_save(void)
{
int descramble, muxcnf;

config_save();
if (!satip_server_rtsp_port_locked) {
satips_rtsp_port(0);
if (satip_server_rtsp_port > 0) {
Expand All @@ -553,6 +554,41 @@ void satip_server_config_changed(void)
}
}

htsmsg_t *satip_server_get_config(void)
{
return config_get_all(1);
}

static int satip_server_set_int(htsmsg_t *conf, const char *name)
{
const char *str;
if ((str = htsmsg_get_str(conf, name)))
return config_set_int(name, atoi(str));
return 0;
}

int satip_server_set_config(htsmsg_t *conf)
{
static const char *names[] = {
"satip_rtsp",
"satip_weight",
"satip_descramble",
"satip_muxcnf",
"satip_dvbs",
"satip_dvbs2",
"satip_dvbt",
"satip_dvbt2",
"satip_dvbc",
"satip_dvbc2",
"satip_atsc",
"satip_dvbcb",
NULL
};
int i, save = 0;
for (i = 0; i < ARRAY_SIZE(names); i++)
save |= satip_server_set_int(conf, names[i]);
return save;
}
/*
* Initialization
*/
Expand Down
4 changes: 3 additions & 1 deletion src/satip/server.h
Expand Up @@ -58,7 +58,9 @@ int satip_server_http_page(http_connection_t *hc,

int satip_server_match_uuid(const char *uuid);

void satip_server_config_changed(void);
void satip_server_save(void);
htsmsg_t *satip_server_get_config(void);
int satip_server_set_config(htsmsg_t *conf);

void satip_server_init(int rtsp_port);
void satip_server_register(void);
Expand Down
32 changes: 3 additions & 29 deletions src/webui/extjs.c
Expand Up @@ -467,7 +467,7 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)

/* Misc */
pthread_mutex_lock(&global_lock);
m = config_get_all();
m = config_get_all(0);
if (!m) {
pthread_mutex_unlock(&global_lock);
return HTTP_STATUS_BAD_REQUEST;
Expand All @@ -484,7 +484,7 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)

/* Save settings */
} else if (!strcmp(op, "saveSettings") ) {
int save = 0, ssave = 0;
int save = 0;

/* Misc settings */
pthread_mutex_lock(&global_lock);
Expand All @@ -500,34 +500,8 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque)
save |= config_set_chicon_path(str);
if ((str = http_arg_get(&hc->hc_req_args, "piconpath")))
save |= config_set_picon_path(str);
if ((str = http_arg_get(&hc->hc_req_args, "satip_rtsp")))
ssave |= config_set_int("satip_rtsp", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_weight")))
ssave |= config_set_int("satip_weight", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_descramble")))
ssave |= config_set_int("satip_descramble", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_muxcnf")))
ssave |= config_set_int("satip_muxcnf", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbs")))
ssave |= config_set_int("satip_dvbs", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbs2")))
ssave |= config_set_int("satip_dvbs2", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbt")))
ssave |= config_set_int("satip_dvbt", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbt2")))
ssave |= config_set_int("satip_dvbt2", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbc")))
ssave |= config_set_int("satip_dvbc", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbc2")))
ssave |= config_set_int("satip_dvbc2", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_atsc")))
ssave |= config_set_int("satip_atsc", atoi(str));
if ((str = http_arg_get(&hc->hc_req_args, "satip_dvbcb")))
ssave |= config_set_int("satip_dvbcb", atoi(str));
if (save | ssave)
if (save)
config_save();
if (ssave)
satip_server_config_changed();

/* Time */
str = http_arg_get(&hc->hc_req_args, "tvhtime_update_enabled");
Expand Down

0 comments on commit 4aba948

Please sign in to comment.