TAILQ_FOREACH(ra, args, link) {
if (strcmp(ra->key, "Session") == 0)
sess = 1;
- htsbuf_qprintf(&hdrs, "%s: %s\r\n", ra->key, ra->val);
+ htsbuf_qprintf(&hdrs, "%s: %s\r\n", ra->key, ra->val ?: "");
}
}
if(hc->hc_session && !sess)
htsbuf_append(&hq, "?", 1);
first = 0;
htsbuf_append_and_escape_url(&hq, ra->key);
- htsbuf_append(&hq, "=", 1);
- htsbuf_append_and_escape_url(&hq, ra->val);
+ if (ra->val) {
+ htsbuf_append(&hq, "=", 1);
+ htsbuf_append_and_escape_url(&hq, ra->val);
+ }
}
loc = htsbuf_to_string(&hq);
htsbuf_queue_flush(&hq);
proto = http_arg_get(&hc->hc_args, "X-Forwarded-Proto");
snprintf(buf, sizeof(buf), "%s://%s%s",
- proto ?: "http", host, tvheadend_webroot ?: "");
+ proto ?: "http", host ?: "localhost", tvheadend_webroot ?: "");
return strdup(buf);
}
http_arg_get_remove(struct http_arg_list *list, const char *name)
{
static char __thread buf[128];
+ int empty;
http_arg_t *ra;
TAILQ_FOREACH(ra, list, link)
if(!strcasecmp(ra->key, name)) {
TAILQ_REMOVE(list, ra, link);
- strncpy(buf, ra->val, sizeof(buf)-1);
- buf[sizeof(buf)-1] = '\0';
+ empty = ra->val == NULL;
+ if (!empty) {
+ strncpy(buf, ra->val, sizeof(buf)-1);
+ buf[sizeof(buf)-1] = '\0';
+ }
free(ra->key);
free(ra->val);
free(ra);
- return buf;
+ return !empty ? buf : NULL;
}
buf[0] = '\0';
return buf;
ra = malloc(sizeof(http_arg_t));
TAILQ_INSERT_TAIL(list, ra, link);
ra->key = strdup(key);
- ra->val = strdup(val);
+ ra->val = val ? strdup(val) : NULL;
}
/*
args++;
while(args) {
k = args;
- if((args = strchr(args, '=')) == NULL)
- break;
- *args++ = 0;
+ if((args = strchr(args, '=')) != NULL) {
+ *args++ = 0;
+ } else {
+ args = k;
+ }
+
v = args;
args = strchr(args, '&');
-
if(args != NULL)
*args++ = 0;
+ else if(v == k) {
+ if (*k == '\0')
+ break;
+ v = NULL;
+ }
http_deescape(k);
- http_deescape(v);
+ if (v)
+ http_deescape(v);
// printf("%s = %s\n", k, v);
http_arg_set(list, k, v);
}
{ "dvbcb", DVB_SYS_DVBC_ANNEX_B }
};
const char *s = http_arg_get_remove(&hc->hc_req_args, "msys");
- return s[0] ? str2val(s, tab) : DVB_SYS_NONE;
+ return s && s[0] ? str2val(s, tab) : DVB_SYS_NONE;
}
static inline int
{ "r", DVB_POLARISATION_CIRCULAR_RIGHT },
};
const char *s = http_arg_get_remove(&hc->hc_req_args, "pol");
- return s[0] ? str2val(s, tab) : -1;
+ return s && s[0] ? str2val(s, tab) : -1;
}
static int
fec_to_tvh(http_connection_t *hc)
{
- switch (atoi(http_arg_get_remove(&hc->hc_req_args, "fec"))) {
+ switch (atoi(http_arg_get_remove(&hc->hc_req_args, "fec") ?: "0")) {
case 0: return DVB_FEC_AUTO;
case 12: return DVB_FEC_1_2;
case 13: return DVB_FEC_1_3;
static int
bw_to_tvh(http_connection_t *hc)
{
- int bw = atof(http_arg_get_remove(&hc->hc_req_args, "bw")) * 1000;
+ int bw = atof(http_arg_get_remove(&hc->hc_req_args, "bw") ?: "0") * 1000;
switch (bw) {
case 0: return DVB_BANDWIDTH_AUTO;
case DVB_BANDWIDTH_1_712_MHZ:
static int
rolloff_to_tvh(http_connection_t *hc)
{
- int ro = atof(http_arg_get_remove(&hc->hc_req_args, "ro")) * 1000;
+ int ro = atof(http_arg_get_remove(&hc->hc_req_args, "ro") ?: "0") * 1000;
switch (ro) {
case 0:
return DVB_ROLLOFF_35;
pilot_to_tvh(http_connection_t *hc)
{
const char *s = http_arg_get_remove(&hc->hc_req_args, "plts");
- if (strcmp(s, "on") == 0)
+ if (s && strcmp(s, "on") == 0)
return DVB_PILOT_ON;
- if (strcmp(s, "off") == 0)
+ if (s && strcmp(s, "off") == 0)
return DVB_PILOT_OFF;
- if (s[0] == '\0' || strcmp(s, "auto") == 0)
+ if (s == NULL || s[0] == '\0' || strcmp(s, "auto") == 0)
return DVB_PILOT_AUTO;
return DVB_ROLLOFF_NONE;
}
{ "32k", DVB_TRANSMISSION_MODE_32K },
};
const char *s = http_arg_get_remove(&hc->hc_req_args, "tmode");
- if (s[0]) {
+ if (s && s[0]) {
int v = str2val(s, tab);
return v >= 0 ? v : DVB_TRANSMISSION_MODE_NONE;
}
{ "8vsb", DVB_MOD_VSB_8 },
};
const char *s = http_arg_get_remove(&hc->hc_req_args, "mtype");
- if (s[0]) {
+ if (s && s[0]) {
int v = str2val(s, tab);
return v >= 0 ? v : DVB_MOD_NONE;
}
static int
gi_to_tvh(http_connection_t *hc)
{
- switch (atoi(http_arg_get_remove(&hc->hc_req_args, "gi"))) {
+ switch (atoi(http_arg_get_remove(&hc->hc_req_args, "gi") ?: "0")) {
case 0: return DVB_GUARD_INTERVAL_AUTO;
case 14: return DVB_GUARD_INTERVAL_1_4;
case 18: return DVB_GUARD_INTERVAL_1_8;
has_args = !TAILQ_EMPTY(&hc->hc_req_args);
- fe = atoi(http_arg_get_remove(&hc->hc_req_args, "fe"));
+ fe = atoi(http_arg_get_remove(&hc->hc_req_args, "fe") ?: 0);
s = http_arg_get_remove(&hc->hc_req_args, "addpids");
if (parse_pids(s, &addpids)) goto end;
s = http_arg_get_remove(&hc->hc_req_args, "delpids");
if (msys == DVB_SYS_DVBS || msys == DVB_SYS_DVBS2) {
- src = atoi(http_arg_get_remove(&hc->hc_req_args, "src"));
+ src = atoi(http_arg_get_remove(&hc->hc_req_args, "src") ?: "0");
if (src < 1) goto end;
pol = pol_to_tvh(hc);
if (pol < 0) goto end;
- sr = atof(http_arg_get_remove(&hc->hc_req_args, "sr")) * 1000;
+ sr = atof(http_arg_get_remove(&hc->hc_req_args, "sr") ?: "0") * 1000;
if (sr < 1000) goto end;
fec = fec_to_tvh(hc);
if (fec == DVB_FEC_NONE) goto end;
fec = fec_to_tvh(hc);
if (fec == DVB_FEC_NONE) goto end;
s = http_arg_get_remove(&hc->hc_req_args, "plp");
- if (s[0]) {
+ if (s && s[0]) {
plp = atoi(s);
if (plp < 0 || plp > 255) goto end;
} else {
plp = DVB_NO_STREAM_ID_FILTER;
}
- t2id = atoi(http_arg_get_remove(&hc->hc_req_args, "t2id"));
+ t2id = atoi(http_arg_get_remove(&hc->hc_req_args, "t2id") ?: "0");
if (t2id < 0 || t2id > 65535) goto end;
- sm = atoi(http_arg_get_remove(&hc->hc_req_args, "sm"));
+ sm = atoi(http_arg_get_remove(&hc->hc_req_args, "sm") ?: "0");
if (sm < 0 || sm > 1) goto end;
if (!TAILQ_EMPTY(&hc->hc_req_args)) goto eargs;
freq *= 1000;
if (freq < 0) goto end;
- c2tft = atoi(http_arg_get_remove(&hc->hc_req_args, "c2tft"));
+ c2tft = atoi(http_arg_get_remove(&hc->hc_req_args, "c2tft") ?: "0");
if (c2tft < 0 || c2tft > 2) goto end;
bw = bw_to_tvh(hc);
if (bw == DVB_BANDWIDTH_NONE) goto end;
- sr = atof(http_arg_get_remove(&hc->hc_req_args, "sr")) * 1000;
+ sr = atof(http_arg_get_remove(&hc->hc_req_args, "sr") ?: "0") * 1000;
if (sr < 1000) goto end;
- ds = atoi(http_arg_get_remove(&hc->hc_req_args, "ds"));
+ ds = atoi(http_arg_get_remove(&hc->hc_req_args, "ds") ?: "0");
if (ds < 0 || ds > 255) goto end;
s = http_arg_get_remove(&hc->hc_req_args, "plp");
- if (s[0]) {
+ if (s && s[0]) {
plp = atoi(http_arg_get_remove(&hc->hc_req_args, "plp"));
if (plp < 0 || plp > 255) goto end;
} else {
plp = DVB_NO_STREAM_ID_FILTER;
}
- specinv = atoi(http_arg_get_remove(&hc->hc_req_args, "specinv"));
+ specinv = atoi(http_arg_get_remove(&hc->hc_req_args, "specinv") ?: "0");
if (specinv < 0 || specinv > 1) goto end;
fec = fec_to_tvh(hc);
if (fec == DVB_FEC_NONE) goto end;