Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use htsbuf_append_str() instead htsbuf_qprintf() where possible
  • Loading branch information
perexg committed Nov 21, 2015
1 parent a876898 commit cd6dc6d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/config.c
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/htsbuf.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/htsmsg_json.c
Expand Up @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions src/http.c
Expand Up @@ -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);

Expand All @@ -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)
Expand All @@ -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");
Expand All @@ -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);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ http_error(http_connection_t *hc, int error)
htsbuf_qprintf(&hc->hc_reply, "<P><A HREF=\"%s/\">Default Login</A></P>",
tvheadend_webroot ? tvheadend_webroot : "");

htsbuf_qprintf(&hc->hc_reply, "</BODY></HTML>\r\n");
htsbuf_append_str(&hc->hc_reply, "</BODY></HTML>\r\n");

http_send_reply(hc, error, "text/html", NULL, NULL, 0);
} else {
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/httpc.c
Expand Up @@ -589,29 +589,29 @@ http_client_send( http_client_t *hc, enum http_cmd cmd,
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);
if (s == NULL) {
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)
Expand Down
18 changes: 9 additions & 9 deletions src/satip/rtsp.c
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/satip/server.c
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 24 additions & 20 deletions src/webui/extjs.c
Expand Up @@ -44,13 +44,13 @@ static void
extjs_load(htsbuf_queue_t *hq, const char *script, ...)
{
va_list ap;
htsbuf_qprintf(hq, "<script type=\"text/javascript\" src=\"");
htsbuf_append_str(hq, "<script type=\"text/javascript\" src=\"");

va_start(ap, script);
htsbuf_vqprintf(hq, script, ap);
va_end(ap);

htsbuf_qprintf(hq, "\"></script>\n");
htsbuf_append_str(hq, "\"></script>\n");
}

/**
Expand All @@ -61,13 +61,13 @@ extjs_lcss(htsbuf_queue_t *hq, const char *css, ...)
{
va_list ap;

htsbuf_qprintf(hq, "<link rel=\"stylesheet\" type=\"text/css\" href=\"");
htsbuf_append_str(hq, "<link rel=\"stylesheet\" type=\"text/css\" href=\"");

va_start(ap, css);
htsbuf_vqprintf(hq, css, ap);
va_end(ap);

htsbuf_qprintf(hq, "\"/>\n");
htsbuf_append_str(hq, "\"/>\n");
}

/**
Expand All @@ -78,13 +78,13 @@ extjs_exec(htsbuf_queue_t *hq, const char *fmt, ...)
{
va_list ap;

htsbuf_qprintf(hq, "<script type=\"text/javascript\">\n");
htsbuf_append_str(hq, "<script type=\"text/javascript\">\n");

va_start(ap, fmt);
htsbuf_vqprintf(hq, fmt, ap);
va_end(ap);

htsbuf_qprintf(hq, "\n</script>\n");
htsbuf_append_str(hq, "\n</script>\n");
}

/**
Expand All @@ -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, "<html>\n");
htsbuf_qprintf(hq, "<head>\n");
htsbuf_append_str(hq, "<html>\n");
htsbuf_append_str(hq, "<head>\n");

htsbuf_qprintf(hq, "<meta name=\"apple-itunes-app\" content=\"app-id=638900112\">\n");
htsbuf_append_str(hq, "<meta name=\"apple-itunes-app\" content=\"app-id=638900112\">\n");

if (tvheadend_webui_debug) {

Expand All @@ -116,7 +116,7 @@ Ext.onReady(tvheadend.app.init, tvheadend.app);\
");


htsbuf_qprintf(hq,
htsbuf_append_str(hq,
"<style type=\"text/css\">\n"
"html, body {\n"
"\tfont:normal 12px verdana;\n"
Expand All @@ -133,12 +133,14 @@ Ext.onReady(tvheadend.app.init, tvheadend.app);\
"\tmargin:5px;\n"
"}\n"
"</style>\n"
"<title>%s</title>\n"
"<title>");
htsbuf_append_str(hq, config.server_name);
htsbuf_append_str(hq,
"</title>\n"
"</head>\n"
"<body>\n"
"<div id=\"systemlog\"></div>\n"
"</body></html>\n",
config.server_name);
"</body></html>\n");

http_output_html(hc);
return 0;
Expand All @@ -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, "<!DOCTYPE html>\n");
htsbuf_qprintf(hq, "<html>\n");
htsbuf_qprintf(hq, "<head>\n");
htsbuf_qprintf(hq, "<title>%s</title>\n", config.server_name);
htsbuf_append_str(hq, "<!DOCTYPE html>\n");
htsbuf_append_str(hq, "<html>\n");
htsbuf_append_str(hq, "<head>\n");
htsbuf_append_str(hq, "<title>");
htsbuf_append_str(hq, config.server_name);
htsbuf_append_str(hq, "</title>\n");

if (tvheadend_webui_debug) {

Expand All @@ -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, "</head>\n");
htsbuf_qprintf(hq, "<body></body>\n");
htsbuf_qprintf(hq, "</html>\n");
htsbuf_append_str(hq, "</head>\n");
htsbuf_append_str(hq, "<body></body>\n");
htsbuf_append_str(hq, "</html>\n");

http_output_html(hc);

Expand Down

0 comments on commit cd6dc6d

Please sign in to comment.