mirror of
https://github.com/curl/curl.git
synced 2026-08-25 14:23:39 +03:00
tests/server: round of tidy-ups (part 2)
General tidy-ups, to identify and reduce duplications and potential issues, while also making the server modules compile as a single binary. - ensure unique symbols and no shadowing across server sources, by renaming variables. - move globals common to multiple servers into shared `util` module. - drop constants with a single use. - undef macro before re-using them across server sources. - move common functions into shared `util` module. - drop redundant static declarations. - disable IPv6 code when built without IPv6. - start syncing the 3 almost identical copies of `sockdaemon` function. - drop unused `timeval.h` header. - drop `poll()` from `wait_ms()`, for macOS, following an earlier core update. Follow-up toc72cefea0f#15096 Follow-up to9213e4e497#16525 Cherry-picked from #15000 Closes #16609
This commit is contained in:
parent
07f99b72d5
commit
bc55b435af
9 changed files with 369 additions and 430 deletions
|
|
@ -56,19 +56,15 @@
|
|||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#ifdef USE_IPV6
|
||||
static bool use_ipv6 = FALSE;
|
||||
#endif
|
||||
static const char *ipv_inuse = "IPv4";
|
||||
static int serverlogslocked = 0;
|
||||
|
||||
#undef REQBUFSIZ
|
||||
#define REQBUFSIZ 150000
|
||||
|
||||
static long prevtestno = -1; /* previous test number we served */
|
||||
static long prevpartno = -1; /* previous part number we served */
|
||||
static bool prevbounce = FALSE; /* instructs the server to override the
|
||||
requested part number to prevpartno + 1 when
|
||||
prevtestno and current test are the same */
|
||||
static long rtspd_prevtestno = -1; /* previous test number we served */
|
||||
static long rtspd_prevpartno = -1; /* previous part number we served */
|
||||
static bool rtspd_prevbounce = FALSE; /* instructs the server to override the
|
||||
requested part number to
|
||||
prevpartno + 1 when prevtestno and
|
||||
current test are the same */
|
||||
|
||||
#define RCMD_NORMALREQ 0 /* default request, use the tests file normally */
|
||||
#define RCMD_IDLE 1 /* told to sit idle */
|
||||
|
|
@ -85,7 +81,7 @@ typedef enum {
|
|||
#define SET_RTP_PKT_LEN(p,l) (((p)[2] = (char)(((l) >> 8) & 0xFF)), \
|
||||
((p)[3] = (char)((l) & 0xFF)))
|
||||
|
||||
struct httprequest {
|
||||
struct rtspd_httprequest {
|
||||
char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
|
||||
size_t checkindex; /* where to start checking of the request */
|
||||
size_t offset; /* size of the incoming request */
|
||||
|
|
@ -112,14 +108,6 @@ struct httprequest {
|
|||
size_t rtp_buffersize;
|
||||
};
|
||||
|
||||
static int ProcessRequest(struct httprequest *req);
|
||||
static void storerequest(char *reqbuf, size_t totalsize);
|
||||
|
||||
#define DEFAULT_PORT 8999
|
||||
|
||||
static const char *logdir = "log";
|
||||
static char loglockfile[256];
|
||||
|
||||
#define RTSPDVERSION "curl test suite RTSP server/0.1"
|
||||
|
||||
#define REQUEST_DUMP "server.input"
|
||||
|
|
@ -145,7 +133,7 @@ static char loglockfile[256];
|
|||
|
||||
|
||||
/* sent as reply to a QUIT */
|
||||
static const char *docquit =
|
||||
static const char *docquit_rtsp =
|
||||
"HTTP/1.1 200 Goodbye" END_OF_HEADERS;
|
||||
|
||||
/* sent as reply to a CONNECT */
|
||||
|
|
@ -179,7 +167,7 @@ static const char *doc404_RTSP = "RTSP/1.0 404 Not Found\r\n"
|
|||
#define RTP_DATA_SIZE 12
|
||||
static const char *RTP_DATA = "$_1234\n\0Rsdf";
|
||||
|
||||
static int ProcessRequest(struct httprequest *req)
|
||||
static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
|
||||
{
|
||||
char *line = &req->reqbuf[req->checkindex];
|
||||
bool chunked = FALSE;
|
||||
|
|
@ -189,7 +177,7 @@ static int ProcessRequest(struct httprequest *req)
|
|||
int prot_major, prot_minor;
|
||||
char *end = strstr(line, END_OF_HEADERS);
|
||||
|
||||
logmsg("ProcessRequest() called with testno %ld and line [%s]",
|
||||
logmsg("rtspd_ProcessRequest() called with testno %ld and line [%s]",
|
||||
req->testno, line);
|
||||
|
||||
/* try to figure out the request characteristics as soon as possible, but
|
||||
|
|
@ -418,10 +406,10 @@ static int ProcessRequest(struct httprequest *req)
|
|||
|
||||
if(!end) {
|
||||
/* we don't have a complete request yet! */
|
||||
logmsg("ProcessRequest returned without a complete request");
|
||||
logmsg("rtspd_ProcessRequest returned without a complete request");
|
||||
return 0; /* not complete yet */
|
||||
}
|
||||
logmsg("ProcessRequest found a complete request");
|
||||
logmsg("rtspd_ProcessRequest found a complete request");
|
||||
|
||||
if(req->pipe)
|
||||
/* we do have a full set, advance the checkindex to after the end of the
|
||||
|
|
@ -573,7 +561,7 @@ static int ProcessRequest(struct httprequest *req)
|
|||
}
|
||||
|
||||
/* store the entire request in a file */
|
||||
static void storerequest(char *reqbuf, size_t totalsize)
|
||||
static void rtspd_storerequest(char *reqbuf, size_t totalsize)
|
||||
{
|
||||
int res;
|
||||
int error = 0;
|
||||
|
|
@ -627,7 +615,7 @@ storerequest_cleanup:
|
|||
}
|
||||
|
||||
/* return 0 on success, non-zero on failure */
|
||||
static int get_request(curl_socket_t sock, struct httprequest *req)
|
||||
static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
|
||||
{
|
||||
int error;
|
||||
int fail = 0;
|
||||
|
|
@ -695,7 +683,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
|
|||
if(fail) {
|
||||
/* dump the request received so far to the external file */
|
||||
reqbuf[req->offset] = '\0';
|
||||
storerequest(reqbuf, req->offset);
|
||||
rtspd_storerequest(reqbuf, req->offset);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -704,7 +692,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
|
|||
req->offset += (size_t)got;
|
||||
reqbuf[req->offset] = '\0';
|
||||
|
||||
done_processing = ProcessRequest(req);
|
||||
done_processing = rtspd_ProcessRequest(req);
|
||||
if(got_exit_signal)
|
||||
return 1;
|
||||
if(done_processing && req->pipe) {
|
||||
|
|
@ -730,7 +718,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
|
|||
reqbuf[req->offset] = '\0';
|
||||
|
||||
/* dump the request to an external file */
|
||||
storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset);
|
||||
rtspd_storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset);
|
||||
if(got_exit_signal)
|
||||
return 1;
|
||||
|
||||
|
|
@ -738,7 +726,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
|
|||
}
|
||||
|
||||
/* returns -1 on failure */
|
||||
static int send_doc(curl_socket_t sock, struct httprequest *req)
|
||||
static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req)
|
||||
{
|
||||
ssize_t written;
|
||||
size_t count;
|
||||
|
|
@ -791,7 +779,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
switch(req->testno) {
|
||||
case DOCNUMBER_QUIT:
|
||||
logmsg("Replying to QUIT");
|
||||
buffer = docquit;
|
||||
buffer = docquit_rtsp;
|
||||
break;
|
||||
case DOCNUMBER_WERULEZ:
|
||||
/* we got a "friends?" question, reply back that we sure are */
|
||||
|
|
@ -890,11 +878,11 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
logmsg("connection close instruction \"swsclose\" found in response");
|
||||
}
|
||||
if(strstr(buffer, "swsbounce")) {
|
||||
prevbounce = TRUE;
|
||||
rtspd_prevbounce = TRUE;
|
||||
logmsg("enable \"swsbounce\" in the next request");
|
||||
}
|
||||
else
|
||||
prevbounce = FALSE;
|
||||
rtspd_prevbounce = FALSE;
|
||||
|
||||
dump = fopen(responsedump, "ab");
|
||||
if(!dump) {
|
||||
|
|
@ -1016,8 +1004,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
free(cmd);
|
||||
req->open = persistent;
|
||||
|
||||
prevtestno = req->testno;
|
||||
prevpartno = req->partno;
|
||||
rtspd_prevtestno = req->testno;
|
||||
rtspd_prevpartno = req->partno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1031,17 +1019,17 @@ int main(int argc, char *argv[])
|
|||
int wrotepidfile = 0;
|
||||
int wroteportfile = 0;
|
||||
int flag;
|
||||
unsigned short port = DEFAULT_PORT;
|
||||
const char *pidname = ".rtsp.pid";
|
||||
const char *portname = NULL; /* none by default */
|
||||
struct httprequest req;
|
||||
unsigned short port = 8999;
|
||||
struct rtspd_httprequest req;
|
||||
int rc;
|
||||
int error;
|
||||
int arg = 1;
|
||||
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
pidname = ".rtsp.pid";
|
||||
serverlogfile = "log/rtspd.log";
|
||||
serverlogslocked = 0;
|
||||
|
||||
while(argc > arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
|
|
@ -1284,9 +1272,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
/* initialization of httprequest struct is done in get_request(), but due
|
||||
to pipelining treatment the pipelining struct field must be initialized
|
||||
previously to FALSE every time a new connection arrives. */
|
||||
/* initialization of httprequest struct is done in rtspd_get_request(),
|
||||
but due to pipelining treatment the pipelining struct field must be
|
||||
initialized previously to FALSE every time a new connection arrives. */
|
||||
|
||||
req.pipelining = FALSE;
|
||||
|
||||
|
|
@ -1294,24 +1282,24 @@ int main(int argc, char *argv[])
|
|||
if(got_exit_signal)
|
||||
break;
|
||||
|
||||
if(get_request(msgsock, &req))
|
||||
if(rtspd_get_request(msgsock, &req))
|
||||
/* non-zero means error, break out of loop */
|
||||
break;
|
||||
|
||||
if(prevbounce) {
|
||||
if(rtspd_prevbounce) {
|
||||
/* bounce treatment requested */
|
||||
if(req.testno == prevtestno) {
|
||||
req.partno = prevpartno + 1;
|
||||
if(req.testno == rtspd_prevtestno) {
|
||||
req.partno = rtspd_prevpartno + 1;
|
||||
logmsg("BOUNCE part number to %ld", req.partno);
|
||||
}
|
||||
else {
|
||||
prevbounce = FALSE;
|
||||
prevtestno = -1;
|
||||
prevpartno = -1;
|
||||
rtspd_prevbounce = FALSE;
|
||||
rtspd_prevtestno = -1;
|
||||
rtspd_prevpartno = -1;
|
||||
}
|
||||
}
|
||||
|
||||
send_doc(msgsock, &req);
|
||||
rtspd_send_doc(msgsock, &req);
|
||||
if(got_exit_signal)
|
||||
break;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue