Browse code

cleanup, merge snprintf calls

Originally committed as revision 15240 to svn://svn.ffmpeg.org/ffmpeg/trunk

Baptiste Coudurier authored on 2008/09/07 13:56:44
Showing 1 changed files
... ...
@@ -1323,14 +1323,14 @@ static int http_parse_request(HTTPContext *c)
1323 1323
     if (stream->stream_type == STREAM_TYPE_REDIRECT) {
1324 1324
         c->http_error = 301;
1325 1325
         q = c->buffer;
1326
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 301 Moved\r\n");
1327
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Location: %s\r\n", stream->feed_filename);
1328
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: text/html\r\n");
1329
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1330
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<html><head><title>Moved</title></head><body>\r\n");
1331
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "You should be <a href=\"%s\">redirected</a>.\r\n", stream->feed_filename);
1332
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</body></html>\r\n");
1333
-
1326
+        q += snprintf(q, c->buffer_size,
1327
+                      "HTTP/1.0 301 Moved\r\n"
1328
+                      "Location: %s\r\n"
1329
+                      "Content-type: text/html\r\n"
1330
+                      "\r\n"
1331
+                      "<html><head><title>Moved</title></head><body>\r\n"
1332
+                      "You should be <a href=\"%s\">redirected</a>.\r\n"
1333
+                      "</body></html>\r\n", stream->feed_filename, stream->feed_filename);
1334 1334
         /* prepare output buffer */
1335 1335
         c->buffer_ptr = c->buffer;
1336 1336
         c->buffer_end = q;
... ...
@@ -1361,15 +1361,15 @@ static int http_parse_request(HTTPContext *c)
1361 1361
     if (c->post == 0 && max_bandwidth < current_bandwidth) {
1362 1362
         c->http_error = 200;
1363 1363
         q = c->buffer;
1364
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 Server too busy\r\n");
1365
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: text/html\r\n");
1366
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1367
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<html><head><title>Too busy</title></head><body>\r\n");
1368
-        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");
1369
-        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",
1370
-            current_bandwidth, max_bandwidth);
1371
-        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</body></html>\r\n");
1372
-
1364
+        q += snprintf(q, c->buffer_size,
1365
+                      "HTTP/1.0 200 Server too busy\r\n"
1366
+                      "Content-type: text/html\r\n"
1367
+                      "\r\n"
1368
+                      "<html><head><title>Too busy</title></head><body>\r\n"
1369
+                      "<p>The server is too busy to serve your request at this time.</p>\r\n"
1370
+                      "<p>The bandwidth being served (including your stream) is %lldkbit/sec, "
1371
+                      "and this exceeds the limit of %lldkbit/sec.</p>\r\n"
1372
+                      "</body></html>\r\n", current_bandwidth, max_bandwidth);
1373 1373
         /* prepare output buffer */
1374 1374
         c->buffer_ptr = c->buffer;
1375 1375
         c->buffer_end = q;
... ...
@@ -1412,30 +1412,30 @@ static int http_parse_request(HTTPContext *c)
1412 1412
                     q = c->buffer;
1413 1413
                     switch(redir_type) {
1414 1414
                     case REDIR_ASX:
1415
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 ASX Follows\r\n");
1416
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: video/x-ms-asf\r\n");
1417
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1418
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<ASX Version=\"3\">\r\n");
1419
-                        //q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<!-- Autogenerated by ffserver -->\r\n");
1420
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n",
1421
-                                hostbuf, filename, info);
1422
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</ASX>\r\n");
1415
+                        q += snprintf(q, c->buffer_size,
1416
+                                      "HTTP/1.0 200 ASX Follows\r\n"
1417
+                                      "Content-type: video/x-ms-asf\r\n"
1418
+                                      "\r\n"
1419
+                                      "<ASX Version=\"3\">\r\n"
1420
+                                      //"<!-- Autogenerated by ffserver -->\r\n"
1421
+                                      "<ENTRY><REF HREF=\"http://%s/%s%s\"/></ENTRY>\r\n"
1422
+                                      "</ASX>\r\n", hostbuf, filename, info);
1423 1423
                         break;
1424 1424
                     case REDIR_RAM:
1425
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 RAM Follows\r\n");
1426
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: audio/x-pn-realaudio\r\n");
1427
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1428
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "# Autogenerated by ffserver\r\n");
1429
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "http://%s/%s%s\r\n",
1430
-                                hostbuf, filename, info);
1425
+                        q += snprintf(q, c->buffer_size,
1426
+                                      "HTTP/1.0 200 RAM Follows\r\n"
1427
+                                      "Content-type: audio/x-pn-realaudio\r\n"
1428
+                                      "\r\n"
1429
+                                      "# Autogenerated by ffserver\r\n"
1430
+                                      "http://%s/%s%s\r\n", hostbuf, filename, info);
1431 1431
                         break;
1432 1432
                     case REDIR_ASF:
1433
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 ASF Redirect follows\r\n");
1434
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: video/x-ms-asf\r\n");
1435
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1436
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "[Reference]\r\n");
1437
-                        q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Ref1=http://%s/%s%s\r\n",
1438
-                                hostbuf, filename, info);
1433
+                        q += snprintf(q, c->buffer_size,
1434
+                                      "HTTP/1.0 200 ASF Redirect follows\r\n"
1435
+                                      "Content-type: video/x-ms-asf\r\n"
1436
+                                      "\r\n"
1437
+                                      "[Reference]\r\n"
1438
+                                      "Ref1=http://%s/%s%s\r\n", hostbuf, filename, info);
1439 1439
                         break;
1440 1440
                     case REDIR_RTSP:
1441 1441
                         {
... ...
@@ -1445,13 +1445,12 @@ static int http_parse_request(HTTPContext *c)
1445 1445
                             p = strrchr(hostname, ':');
1446 1446
                             if (p)
1447 1447
                                 *p = '\0';
1448
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 RTSP Redirect follows\r\n");
1449
-                            /* XXX: incorrect mime type ? */
1450
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: application/x-rtsp\r\n");
1451
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1452
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "rtsp://%s:%d/%s\r\n",
1453
-                                         hostname, ntohs(my_rtsp_addr.sin_port),
1454
-                                         filename);
1448
+                            q += snprintf(q, c->buffer_size,
1449
+                                          "HTTP/1.0 200 RTSP Redirect follows\r\n"
1450
+                                          /* XXX: incorrect mime type ? */
1451
+                                          "Content-type: application/x-rtsp\r\n"
1452
+                                          "\r\n"
1453
+                                          "rtsp://%s:%d/%s\r\n", hostname, ntohs(my_rtsp_addr.sin_port), filename);
1455 1454
                         }
1456 1455
                         break;
1457 1456
                     case REDIR_SDP:
... ...
@@ -1460,9 +1459,10 @@ static int http_parse_request(HTTPContext *c)
1460 1460
                             int sdp_data_size, len;
1461 1461
                             struct sockaddr_in my_addr;
1462 1462
 
1463
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 200 OK\r\n");
1464
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: application/sdp\r\n");
1465
-                            q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1463
+                            q += snprintf(q, c->buffer_size,
1464
+                                          "HTTP/1.0 200 OK\r\n"
1465
+                                          "Content-type: application/sdp\r\n"
1466
+                                          "\r\n");
1466 1467
 
1467 1468
                             len = sizeof(my_addr);
1468 1469
                             getsockname(c->fd, (struct sockaddr *)&my_addr, &len);
... ...
@@ -1608,14 +1608,14 @@ static int http_parse_request(HTTPContext *c)
1608 1608
  send_error:
1609 1609
     c->http_error = 404;
1610 1610
     q = c->buffer;
1611
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "HTTP/1.0 404 Not Found\r\n");
1612
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "Content-type: %s\r\n", "text/html");
1613
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "\r\n");
1614
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<HTML>\n");
1615
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<HEAD><TITLE>404 Not Found</TITLE></HEAD>\n");
1616
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "<BODY>%s</BODY>\n", msg);
1617
-    q += snprintf(q, q - (char *) c->buffer + c->buffer_size, "</HTML>\n");
1618
-
1611
+    q += snprintf(q, c->buffer_size,
1612
+                  "HTTP/1.0 404 Not Found\r\n"
1613
+                  "Content-type: text/html\r\n"
1614
+                  "\r\n"
1615
+                  "<HTML>\n"
1616
+                  "<HEAD><TITLE>404 Not Found</TITLE></HEAD>\n"
1617
+                  "<BODY>%s</BODY>\n"
1618
+                  "</HTML>\n", msg);
1619 1619
     /* prepare output buffer */
1620 1620
     c->buffer_ptr = c->buffer;
1621 1621
     c->buffer_end = q;