From: Jaroslav Kysela Date: Sat, 21 Nov 2015 19:47:09 +0000 (+0100) Subject: use htsbuf_append_str() instead htsbuf_qprintf() where possible X-Git-Tag: v4.2.1~1494 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cd6dc6dec04fbf21ad95e9e080e3df9800d6c3c3;p=thirdparty%2Ftvheadend.git use htsbuf_append_str() instead htsbuf_qprintf() where possible --- diff --git a/src/config.c b/src/config.c index c15d25f83..97f934ee8 100644 --- a/src/config.c +++ b/src/config.c @@ -1469,7 +1469,7 @@ dobackup(const char *oldver) char *s; htsbuf_queue_init(&q, 0); for (arg = argv; *arg; arg++) { - htsbuf_append(&q, *arg, strlen(*arg)); + htsbuf_append_str(&q, *arg); if (arg[1]) htsbuf_append(&q, " ", 1); } diff --git a/src/htsbuf.c b/src/htsbuf.c index 70e2df716..a67583f40 100644 --- a/src/htsbuf.c +++ b/src/htsbuf.c @@ -368,7 +368,7 @@ htsbuf_append_and_escape_xml(htsbuf_queue_t *hq, const char *s) if(esc != NULL) { htsbuf_append(hq, s, c - s - 1); - htsbuf_append(hq, esc, strlen(esc)); + htsbuf_append_str(hq, esc); s = c; } @@ -416,7 +416,7 @@ htsbuf_append_and_escape_url(htsbuf_queue_t *hq, const char *s) if(esc != NULL) { htsbuf_append(hq, s, c - s - 1); - htsbuf_append(hq, esc, strlen(esc)); + htsbuf_append_str(hq, esc); s = c; } diff --git a/src/htsmsg_json.c b/src/htsmsg_json.c index 1e796c128..17b0644f0 100644 --- a/src/htsmsg_json.c +++ b/src/htsmsg_json.c @@ -72,17 +72,17 @@ htsmsg_json_write(htsmsg_t *msg, htsbuf_queue_t *hq, int isarray, case HMF_BOOL: s = f->hmf_bool ? "true" : "false"; - htsbuf_append(hq, s, strlen(s)); + htsbuf_append_str(hq, s); break; case HMF_S64: snprintf(buf, sizeof(buf), "%" PRId64, f->hmf_s64); - htsbuf_append(hq, buf, strlen(buf)); + htsbuf_append_str(hq, buf); break; case HMF_DBL: my_double2str(buf, sizeof(buf), f->hmf_dbl); - htsbuf_append(hq, buf, strlen(buf)); + htsbuf_append_str(hq, buf); break; default: diff --git a/src/http.c b/src/http.c index d6d9c6a07..3122bb7e8 100644 --- a/src/http.c +++ b/src/http.c @@ -236,17 +236,17 @@ http_send_header(http_connection_t *hc, int rc, const char *content, http_ver2str(hc->hc_version), rc, http_rc2str(rc)); if (hc->hc_version != RTSP_VERSION_1_0){ - htsbuf_qprintf(&hdrs, "Server: HTS/tvheadend\r\n"); + htsbuf_append_str(&hdrs, "Server: HTS/tvheadend\r\n"); if (config.cors_origin && config.cors_origin[0]) { htsbuf_qprintf(&hdrs, "Access-Control-Allow-Origin: %s\r\n", config.cors_origin); - htsbuf_qprintf(&hdrs, "Access-Control-Allow-Methods: POST, GET, OPTIONS\r\n"); - htsbuf_qprintf(&hdrs, "Access-Control-Allow-Headers: x-requested-with\r\n"); + htsbuf_append_str(&hdrs, "Access-Control-Allow-Methods: POST, GET, OPTIONS\r\n"); + htsbuf_append_str(&hdrs, "Access-Control-Allow-Headers: x-requested-with\r\n"); } } if(maxage == 0) { if (hc->hc_version != RTSP_VERSION_1_0) - htsbuf_qprintf(&hdrs, "Cache-Control: no-cache\r\n"); + htsbuf_append_str(&hdrs, "Cache-Control: no-cache\r\n"); } else if (maxage > 0) { time(&t); @@ -270,11 +270,11 @@ http_send_header(http_connection_t *hc, int rc, const char *content, } if(rc == HTTP_STATUS_UNAUTHORIZED) - htsbuf_qprintf(&hdrs, "WWW-Authenticate: Basic realm=\"tvheadend\"\r\n"); + htsbuf_append_str(&hdrs, "WWW-Authenticate: Basic realm=\"tvheadend\"\r\n"); if (hc->hc_logout_cookie == 1) { - htsbuf_qprintf(&hdrs, "Set-Cookie: logout=1; Path=\"/logout\"\r\n"); + htsbuf_append_str(&hdrs, "Set-Cookie: logout=1; Path=\"/logout\"\r\n"); } else if (hc->hc_logout_cookie == 2) { - htsbuf_qprintf(&hdrs, "Set-Cookie: logout=0; Path=\"/logout'\"; expires=Thu, 01 Jan 1970 00:00:00 GMT\r\n"); + htsbuf_append_str(&hdrs, "Set-Cookie: logout=0; Path=\"/logout'\"; expires=Thu, 01 Jan 1970 00:00:00 GMT\r\n"); } if (hc->hc_version != RTSP_VERSION_1_0) @@ -293,7 +293,7 @@ http_send_header(http_connection_t *hc, int rc, const char *content, if(contentlen > 0) htsbuf_qprintf(&hdrs, "Content-Length: %"PRId64"\r\n", contentlen); else if(contentlen == INT64_MIN) - htsbuf_qprintf(&hdrs, "Content-Length: 0\r\n"); + htsbuf_append_str(&hdrs, "Content-Length: 0\r\n"); if(range) { htsbuf_qprintf(&hdrs, "Accept-Ranges: %s\r\n", "bytes"); @@ -319,7 +319,7 @@ http_send_header(http_connection_t *hc, int rc, const char *content, if(hc->hc_session && !sess) htsbuf_qprintf(&hdrs, "Session: %s\r\n", hc->hc_session); - htsbuf_qprintf(&hdrs, "\r\n"); + htsbuf_append_str(&hdrs, "\r\n"); tcp_write_queue(hc->hc_fd, &hdrs); } @@ -422,7 +422,7 @@ http_error(http_connection_t *hc, int error) htsbuf_qprintf(&hc->hc_reply, "

Default Login

", tvheadend_webroot ? tvheadend_webroot : ""); - htsbuf_qprintf(&hc->hc_reply, "\r\n"); + htsbuf_append_str(&hc->hc_reply, "\r\n"); http_send_reply(hc, error, "text/html", NULL, NULL, 0); } else { @@ -468,8 +468,8 @@ http_redirect(http_connection_t *hc, const char *location, int first = 1; htsbuf_queue_init(&hq, 0); if (!external && tvheadend_webroot && location[0] == '/') - htsbuf_append(&hq, tvheadend_webroot, strlen(tvheadend_webroot)); - htsbuf_append(&hq, location, strlen(location)); + htsbuf_append_str(&hq, tvheadend_webroot); + htsbuf_append_str(&hq, location); TAILQ_FOREACH(ra, req_args, link) { if (!first) htsbuf_append(&hq, "&", 1); diff --git a/src/httpc.c b/src/httpc.c index ed1eabec9..fcd727004 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -589,14 +589,14 @@ error: free(wcmd); return -EINVAL; } - htsbuf_append(&q, s, strlen(s)); + htsbuf_append_str(&q, s); htsbuf_append(&q, " ", 1); if (path == NULL || path[0] == '\0') path = "/"; - htsbuf_append(&q, path, strlen(path)); + htsbuf_append_str(&q, path); if (query && query[0] != '\0') { htsbuf_append(&q, "?", 1); - htsbuf_append(&q, query, strlen(query)); + htsbuf_append_str(&q, query); } htsbuf_append(&q, " ", 1); s = http_ver2str(hc->hc_version); @@ -604,14 +604,14 @@ error: htsbuf_queue_flush(&q); goto error; } - htsbuf_append(&q, s, strlen(s)); + htsbuf_append_str(&q, s); htsbuf_append(&q, "\r\n", 2); if (header) { TAILQ_FOREACH(h, header, link) { - htsbuf_append(&q, h->key, strlen(h->key)); + htsbuf_append_str(&q, h->key); htsbuf_append(&q, ": ", 2); - htsbuf_append(&q, h->val, strlen(h->val)); + htsbuf_append_str(&q, h->val); htsbuf_append(&q, "\r\n", 2); if (strcasecmp(h->key, "Connection") == 0 && strcasecmp(h->val, "close") == 0) diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index 9450bf53d..8a90ff2f5 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -1138,7 +1138,7 @@ rtsp_describe_header(session_t *rs, htsbuf_queue_t *q) unsigned long mono = getmonoclock(); int dvbt, dvbc; - htsbuf_qprintf(q, "v=0\r\n"); + htsbuf_append_str(q, "v=0\r\n"); htsbuf_qprintf(q, "o=- %lu %lu IN %s %s\r\n", rs ? (unsigned long)rs->nsession : mono - 123, mono, @@ -1161,7 +1161,7 @@ rtsp_describe_header(session_t *rs, htsbuf_queue_t *q) htsbuf_append(q, "\r\n", 1); pthread_mutex_unlock(&global_lock); - htsbuf_qprintf(q, "t=0 0\r\n"); + htsbuf_append_str(q, "t=0 0\r\n"); } static void @@ -1170,19 +1170,19 @@ rtsp_describe_session(session_t *rs, htsbuf_queue_t *q) char buf[4096]; htsbuf_qprintf(q, "a=control:stream=%d\r\n", rs->stream); - htsbuf_qprintf(q, "a=tool:tvheadend\r\n"); - htsbuf_qprintf(q, "m=video 0 RTP/AVP 33\r\n"); + htsbuf_append_str(q, "a=tool:tvheadend\r\n"); + htsbuf_append_str(q, "m=video 0 RTP/AVP 33\r\n"); if (strchr(rtsp_ip, ':')) - htsbuf_qprintf(q, "c=IN IP6 ::0\r\n"); + htsbuf_append_str(q, "c=IN IP6 ::0\r\n"); else - htsbuf_qprintf(q, "c=IN IP4 0.0.0.0\r\n"); + htsbuf_append_str(q, "c=IN IP4 0.0.0.0\r\n"); if (rs->state == STATE_PLAY) { satip_rtp_status((void *)(intptr_t)rs->stream, buf, sizeof(buf)); htsbuf_qprintf(q, "a=fmtp:33 %s\r\n", buf); - htsbuf_qprintf(q, "a=sendonly\r\n"); + htsbuf_append_str(q, "a=sendonly\r\n"); } else { - htsbuf_qprintf(q, "a=fmtp:33\r\n"); - htsbuf_qprintf(q, "a=inactive\r\n"); + htsbuf_append_str(q, "a=fmtp:33\r\n"); + htsbuf_append_str(q, "a=inactive\r\n"); } } diff --git a/src/satip/server.c b/src/satip/server.c index e4456a81f..3f7e63d7d 100644 --- a/src/satip/server.c +++ b/src/satip/server.c @@ -263,7 +263,7 @@ CONFIGID.UPNP.ORG: 0\r\n\ usn2, (long)satip_server_bootid); htsbuf_queue_init(&q, 0); - htsbuf_append(&q, buf, strlen(buf)); + htsbuf_append_str(&q, buf); upnp_send(&q, NULL, attempt * 11, 1); htsbuf_queue_flush(&q); } @@ -321,7 +321,7 @@ DEVICEID.SES.COM: %d\r\n\r\n" satip_server_deviceid); htsbuf_queue_init(&q, 0); - htsbuf_append(&q, buf, strlen(buf)); + htsbuf_append_str(&q, buf); upnp_send(&q, NULL, attempt * 11, 1); htsbuf_queue_flush(&q); } @@ -361,7 +361,7 @@ CONFIGID.UPNP.ORG: 0\r\n" satip_server_conf.satip_uuid, (long)satip_server_bootid); htsbuf_queue_init(&q, 0); - htsbuf_append(&q, buf, strlen(buf)); + htsbuf_append_str(&q, buf); if (deviceid) htsbuf_qprintf(&q, "DEVICEID.SES.COM: %s", deviceid); htsbuf_append(&q, "\r\n", 2); diff --git a/src/webui/extjs.c b/src/webui/extjs.c index a9efc7f4a..c34f9fe75 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -44,13 +44,13 @@ static void extjs_load(htsbuf_queue_t *hq, const char *script, ...) { va_list ap; - htsbuf_qprintf(hq, "\n"); + htsbuf_append_str(hq, "\">\n"); } /** @@ -61,13 +61,13 @@ extjs_lcss(htsbuf_queue_t *hq, const char *css, ...) { va_list ap; - htsbuf_qprintf(hq, "\n"); + htsbuf_append_str(hq, "\"/>\n"); } /** @@ -78,13 +78,13 @@ extjs_exec(htsbuf_queue_t *hq, const char *fmt, ...) { va_list ap; - htsbuf_qprintf(hq, "\n"); + htsbuf_append_str(hq, "\n\n"); } /** @@ -95,10 +95,10 @@ extjs_root(http_connection_t *hc, const char *remain, void *opaque) { htsbuf_queue_t *hq = &hc->hc_reply; - htsbuf_qprintf(hq, "\n"); - htsbuf_qprintf(hq, "\n"); + htsbuf_append_str(hq, "\n"); + htsbuf_append_str(hq, "\n"); - htsbuf_qprintf(hq, "\n"); + htsbuf_append_str(hq, "\n"); if (tvheadend_webui_debug) { @@ -116,7 +116,7 @@ Ext.onReady(tvheadend.app.init, tvheadend.app);\ "); - htsbuf_qprintf(hq, + htsbuf_append_str(hq, "\n" - "%s\n" + ""); + htsbuf_append_str(hq, config.server_name); + htsbuf_append_str(hq, + "\n" "\n" "\n" "
\n" - "\n", - config.server_name); + "\n"); http_output_html(hc); return 0; @@ -153,10 +155,12 @@ extjs_livetv(http_connection_t *hc, const char *remain, void *opaque) { htsbuf_queue_t *hq = &hc->hc_reply; - htsbuf_qprintf(hq, "\n"); - htsbuf_qprintf(hq, "\n"); - htsbuf_qprintf(hq, "\n"); - htsbuf_qprintf(hq, "%s\n", config.server_name); + htsbuf_append_str(hq, "\n"); + htsbuf_append_str(hq, "\n"); + htsbuf_append_str(hq, "\n"); + htsbuf_append_str(hq, ""); + htsbuf_append_str(hq, config.server_name); + htsbuf_append_str(hq, "\n"); if (tvheadend_webui_debug) { @@ -170,9 +174,9 @@ extjs_livetv(http_connection_t *hc, const char *remain, void *opaque) extjs_exec(hq, "Ext.onReady(tv.app.init, tv.app);"); - htsbuf_qprintf(hq, "\n"); - htsbuf_qprintf(hq, "\n"); - htsbuf_qprintf(hq, "\n"); + htsbuf_append_str(hq, "\n"); + htsbuf_append_str(hq, "\n"); + htsbuf_append_str(hq, "\n"); http_output_html(hc); diff --git a/src/webui/webui.c b/src/webui/webui.c index 3aa922523..f9630b096 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -470,7 +470,7 @@ http_m3u_playlist_add(htsbuf_queue_t *hq, const char *hostpath, const char *svcname, const char *logo, const char *epgid, access_t *access) { - htsbuf_qprintf(hq, "#EXTINF:-1"); + htsbuf_append_str(hq, "#EXTINF:-1"); if (logo) { if (strncmp(logo, "imagecache/", 11) == 0) htsbuf_qprintf(hq, " logo=\"%s/%s\"", hostpath, logo); @@ -492,7 +492,7 @@ http_e2_playlist_add(htsbuf_queue_t *hq, const char *hostpath, const char *url_remain, const char *profile, const char *svcname) { - htsbuf_qprintf(hq, "#SERVICE 1:0:0:0:0:0:0:0:0:0:"); + htsbuf_append_str(hq, "#SERVICE 1:0:0:0:0:0:0:0:0:0:"); htsbuf_append_and_escape_url(hq, hostpath); htsbuf_append_and_escape_url(hq, url_remain); htsbuf_qprintf(hq, "&profile=%s:%s\n", profile, svcname); @@ -524,7 +524,7 @@ http_satip_m3u_playlist_add(htsbuf_queue_t *hq, const char *hostpath, name = channel_get_name(ch); logo = channel_get_icon(ch); snprintf(buf, sizeof(buf), "/stream/channelid/%d", channel_get_id(ch)); - htsbuf_qprintf(hq, "#EXTINF:-1"); + htsbuf_append_str(hq, "#EXTINF:-1"); if (logo) { if (strncmp(logo, "imagecache/", 11) == 0) htsbuf_qprintf(hq, " logo=%s/%s", hostpath, logo); @@ -559,7 +559,7 @@ http_channel_playlist(http_connection_t *hc, int pltype, channel_t *channel) if (pltype == PLAYLIST_M3U) { - htsbuf_qprintf(hq, "#EXTM3U\n"); + htsbuf_append_str(hq, "#EXTM3U\n"); http_m3u_playlist_add(hq, hostpath, buf, profile, name, channel_get_icon(channel), channel_get_suuid(channel), @@ -625,7 +625,7 @@ http_tag_playlist(http_connection_t *hc, int pltype, channel_tag_t *tag) qsort(chlist, count, sizeof(channel_t *), http_channel_playlist_cmp); if (pltype == PLAYLIST_M3U) - htsbuf_qprintf(hq, "#EXTM3U\n"); + htsbuf_append_str(hq, "#EXTM3U\n"); else if (pltype == PLAYLIST_E2) htsbuf_qprintf(hq, "#NAME %s\n", tag->ct_name); for (idx = 0; idx < count; idx++) { @@ -714,7 +714,7 @@ http_tag_list_playlist(http_connection_t *hc, int pltype) chlist = NULL; } - htsbuf_qprintf(hq, pltype == PLAYLIST_E2 ? "#NAME Tvheadend Channels\n" : "#EXTM3U\n"); + htsbuf_append_str(hq, pltype == PLAYLIST_E2 ? "#NAME Tvheadend Channels\n" : "#EXTM3U\n"); for (idx = 0; idx < count; idx++) { ct = ctlist[idx]; @@ -790,7 +790,7 @@ http_channel_list_playlist(http_connection_t *hc, int pltype) qsort(chlist, count, sizeof(channel_t *), http_channel_playlist_cmp); - htsbuf_qprintf(hq, pltype == PLAYLIST_E2 ? "#NAME Tvheadend Channels\n" : "#EXTM3U\n"); + htsbuf_append_str(hq, pltype == PLAYLIST_E2 ? "#NAME Tvheadend Channels\n" : "#EXTM3U\n"); for (idx = 0; idx < count; idx++) { ch = chlist[idx]; @@ -843,7 +843,7 @@ http_dvr_list_playlist(http_connection_t *hc, int pltype) hq = &hc->hc_reply; hostpath = http_get_hostpath(hc); - htsbuf_qprintf(hq, "#EXTM3U\n"); + htsbuf_append_str(hq, "#EXTM3U\n"); LIST_FOREACH(de, &dvrentries, de_global_link) { fsize = dvr_get_filesize(de); if(!fsize) @@ -905,7 +905,7 @@ http_dvr_playlist(http_connection_t *hc, int pltype, dvr_entry_t *de) bandwidth = ((8*fsize) / (durration*1024.0)); strftime(buf, sizeof(buf), "%FT%T%z", localtime_r(&(de->de_start), &tm)); - htsbuf_qprintf(hq, "#EXTM3U\n"); + htsbuf_append_str(hq, "#EXTM3U\n"); htsbuf_qprintf(hq, "#EXTINF:%"PRItime_t",%s\n", durration, lang_str_get(de->de_title, NULL)); htsbuf_qprintf(hq, "#EXT-X-TARGETDURATION:%"PRItime_t"\n", durration);