cleanup, merge snprintf calls

Originally committed as revision 15240 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Baptiste Coudurier 16 years ago
parent 24b8aa84d0
commit a3aa4fed62
  1. 110
      ffserver.c

@ -1323,14 +1323,14 @@ static int http_parse_request(HTTPContext *c)
if (stream->stream_type == STREAM_TYPE_REDIRECT) { if (stream->stream_type == STREAM_TYPE_REDIRECT) {
c->http_error = 301; c->http_error = 301;
q = c->buffer; q = c->buffer;
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 301 Moved\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Location: %s\r\n", stream->feed_filename); "HTTP/1.0 301 Moved\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: text/html\r\n"); "Location: %s\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: text/html\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<html><head><title>Moved</title></head><body>\r\n"); "\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "You should be <a href=\"%s\">redirected</a>.\r\n", stream->feed_filename); "<html><head><title>Moved</title></head><body>\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</body></html>\r\n"); "You should be <a href=\"%s\">redirected</a>.\r\n"
"</body></html>\r\n", stream->feed_filename, stream->feed_filename);
/* prepare output buffer */ /* prepare output buffer */
c->buffer_ptr = c->buffer; c->buffer_ptr = c->buffer;
c->buffer_end = q; c->buffer_end = q;
@ -1361,15 +1361,15 @@ static int http_parse_request(HTTPContext *c)
if (c->post == 0 && max_bandwidth < current_bandwidth) { if (c->post == 0 && max_bandwidth < current_bandwidth) {
c->http_error = 200; c->http_error = 200;
q = c->buffer; q = c->buffer;
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 Server too busy\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: text/html\r\n"); "HTTP/1.0 200 Server too busy\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: text/html\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<html><head><title>Too busy</title></head><body>\r\n"); "\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<p>The server is too busy to serve your request at this time.</p>\r\n"); "<html><head><title>Too busy</title></head><body>\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<p>The bandwidth being served (including your stream) is %lldkbit/sec, and this exceeds the limit of %lldkbit/sec.</p>\r\n", "<p>The server is too busy to serve your request at this time.</p>\r\n"
current_bandwidth, max_bandwidth); "<p>The bandwidth being served (including your stream) is %lldkbit/sec, "
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</body></html>\r\n"); "and this exceeds the limit of %lldkbit/sec.</p>\r\n"
"</body></html>\r\n", current_bandwidth, max_bandwidth);
/* prepare output buffer */ /* prepare output buffer */
c->buffer_ptr = c->buffer; c->buffer_ptr = c->buffer;
c->buffer_end = q; c->buffer_end = q;
@ -1412,30 +1412,30 @@ static int http_parse_request(HTTPContext *c)
q = c->buffer; q = c->buffer;
switch(redir_type) { switch(redir_type) {
case REDIR_ASX: case REDIR_ASX:
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 ASX Follows\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: video/x-ms-asf\r\n"); "HTTP/1.0 200 ASX Follows\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: video/x-ms-asf\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<ASX Version=\"3\">\r\n"); "\r\n"
//q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<!-- Autogenerated by ffserver -->\r\n"); "<ASX Version=\"3\">\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n", //"<!-- Autogenerated by ffserver -->\r\n"
hostbuf, filename, info); "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</ASX>\r\n"); "</ASX>\r\n", hostbuf, filename, info);
break; break;
case REDIR_RAM: case REDIR_RAM:
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 RAM Follows\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: audio/x-pn-realaudio\r\n"); "HTTP/1.0 200 RAM Follows\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: audio/x-pn-realaudio\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "# Autogenerated by ffserver\r\n"); "\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "http://%s/%s%s\r\n", "# Autogenerated by ffserver\r\n"
hostbuf, filename, info); "http://%s/%s%s\r\n", hostbuf, filename, info);
break; break;
case REDIR_ASF: case REDIR_ASF:
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 ASF Redirect follows\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: video/x-ms-asf\r\n"); "HTTP/1.0 200 ASF Redirect follows\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: video/x-ms-asf\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "[Reference]\r\n"); "\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Ref1=http://%s/%s%s\r\n", "[Reference]\r\n"
hostbuf, filename, info); "Ref1=http://%s/%s%s\r\n", hostbuf, filename, info);
break; break;
case REDIR_RTSP: case REDIR_RTSP:
{ {
@ -1445,13 +1445,12 @@ static int http_parse_request(HTTPContext *c)
p = strrchr(hostname, ':'); p = strrchr(hostname, ':');
if (p) if (p)
*p = '\0'; *p = '\0';
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 RTSP Redirect follows\r\n"); q += snprintf(q, c->buffer_size,
/* XXX: incorrect mime type ? */ "HTTP/1.0 200 RTSP Redirect follows\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: application/x-rtsp\r\n"); /* XXX: incorrect mime type ? */
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: application/x-rtsp\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "rtsp://%s:%d/%s\r\n", "\r\n"
hostname, ntohs(my_rtsp_addr.sin_port), "rtsp://%s:%d/%s\r\n", hostname, ntohs(my_rtsp_addr.sin_port), filename);
filename);
} }
break; break;
case REDIR_SDP: case REDIR_SDP:
@ -1460,9 +1459,10 @@ static int http_parse_request(HTTPContext *c)
int sdp_data_size, len; int sdp_data_size, len;
struct sockaddr_in my_addr; struct sockaddr_in my_addr;
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 OK\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: application/sdp\r\n"); "HTTP/1.0 200 OK\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: application/sdp\r\n"
"\r\n");
len = sizeof(my_addr); len = sizeof(my_addr);
getsockname(c->fd, (struct sockaddr *)&my_addr, &len); getsockname(c->fd, (struct sockaddr *)&my_addr, &len);
@ -1608,14 +1608,14 @@ static int http_parse_request(HTTPContext *c)
send_error: send_error:
c->http_error = 404; c->http_error = 404;
q = c->buffer; q = c->buffer;
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 404 Not Found\r\n"); q += snprintf(q, c->buffer_size,
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: %s\r\n", "text/html"); "HTTP/1.0 404 Not Found\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n"); "Content-type: text/html\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<HTML>\n"); "\r\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<HEAD><TITLE>404 Not Found</TITLE></HEAD>\n"); "<HTML>\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<BODY>%s</BODY>\n", msg); "<HEAD><TITLE>404 Not Found</TITLE></HEAD>\n"
q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</HTML>\n"); "<BODY>%s</BODY>\n"
"</HTML>\n", msg);
/* prepare output buffer */ /* prepare output buffer */
c->buffer_ptr = c->buffer; c->buffer_ptr = c->buffer;
c->buffer_end = q; c->buffer_end = q;

Loading…
Cancel
Save