Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
41dd5121
Commit
41dd5121
authored
23 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
adjusted to work on test case 11 better
parent
94482d7c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/server/getpart.c
+1
-1
1 addition, 1 deletion
tests/server/getpart.c
tests/server/sws.c
+89
-72
89 additions, 72 deletions
tests/server/sws.c
with
90 additions
and
73 deletions
tests/server/getpart.c
+
1
−
1
View file @
41dd5121
...
...
@@ -13,6 +13,7 @@
#define show(x)
#endif
static
char
*
appendstring
(
char
*
string
,
/* original string */
char
*
buffer
,
/* to append */
int
*
stringlen
,
int
*
stralloc
)
...
...
@@ -46,7 +47,6 @@ char *spitout(FILE *stream, char *main, char *sub, int *size)
char
*
string
;
int
stringlen
=
0
;
int
stralloc
=
256
;
int
len
;
enum
{
STATE_OUTSIDE
,
...
...
This diff is collapsed.
Click to expand it.
tests/server/sws.c
+
89
−
72
View file @
41dd5121
...
...
@@ -5,14 +5,14 @@
#include
<string.h>
#include
<unistd.h>
#include
<signal.h>
#include
<getopt.h>
#include
<sys/time.h>
#include
<sys/types.h>
#include
<sys/wait.h>
#include
<sys/socket.h>
#include
<netinet/in.h>
#include
<netdb.h>
#include
<assert.h>
char
*
spitout
(
FILE
*
stream
,
char
*
main
,
char
*
sub
,
int
*
size
);
#define DEFAULT_PORT 8999
...
...
@@ -80,7 +80,7 @@ static void sigterm_handler(int sig)
int
ProcessRequest
(
char
*
request
)
{
char
*
line
=
request
;
long
contentlength
=
-
1
;
unsigned
long
contentlength
=
0
;
#define END_OF_HEADERS "\r\n\r\n"
...
...
@@ -111,7 +111,7 @@ int ProcessRequest(char *request)
line
++
;
}
while
(
line
);
if
(
contentlength
>
-
1
)
{
if
(
contentlength
>
0
)
{
if
(
contentlength
<=
strlen
(
end
+
strlen
(
END_OF_HEADERS
)))
return
1
;
/* done */
else
...
...
@@ -138,13 +138,15 @@ void storerequest(char *reqbuf)
#define REQBUFSIZ 4096
#define MAXDOCNAMELEN 1024
#define REQUEST_KEYWORD_SIZE 256
static
int
get_request
(
int
sock
)
static
int
get_request
(
int
sock
,
int
*
part
)
{
char
reqbuf
[
REQBUFSIZ
],
doc
[
MAXDOCNAMELEN
];
char
request
[
REQUEST_KEYWORD_SIZE
];
unsigned
int
offset
=
0
;
int
prot_major
,
prot_minor
;
*
part
=
0
;
/* part zero equals none */
while
(
offset
<
REQBUFSIZ
)
{
int
got
=
recv
(
sock
,
reqbuf
+
offset
,
REQBUFSIZ
-
offset
,
0
);
if
(
got
<=
0
)
{
...
...
@@ -191,7 +193,15 @@ static int get_request(int sock)
logmsg
(
"Are-we-friendly question received"
);
return
-
2
;
}
test_no
=
strtol
(
ptr
+
1
,
&
ptr
,
10
);
ptr
++
;
/* skip the slash */
test_no
=
strtol
(
ptr
,
&
ptr
,
10
);
if
(
test_no
>
10000
)
{
*
part
=
test_no
%
10000
;
test_no
/=
10000
;
}
logmsg
(
"Found test number in PATH"
);
}
...
...
@@ -209,7 +219,7 @@ static int get_request(int sock)
}
static
int
send_doc
(
int
sock
,
int
doc
)
static
int
send_doc
(
int
sock
,
int
doc
,
int
part_no
)
{
int
written
;
int
count
;
...
...
@@ -218,6 +228,7 @@ static int send_doc(int sock, int doc)
FILE
*
stream
;
char
filename
[
256
];
char
partbuf
[
80
]
=
"data"
;
if
(
doc
<
0
)
{
if
(
-
2
==
doc
)
...
...
@@ -237,7 +248,11 @@ static int send_doc(int sock, int doc)
return
0
;
}
ptr
=
buffer
=
spitout
(
stream
,
"reply"
,
"data"
,
&
count
);
if
(
0
!=
part_no
)
{
sprintf
(
partbuf
,
"data%d"
,
part_no
);
}
ptr
=
buffer
=
spitout
(
stream
,
"reply"
,
partbuf
,
&
count
);
}
do
{
...
...
@@ -260,84 +275,86 @@ static int send_doc(int sock, int doc)
int
main
(
int
argc
,
char
*
argv
[])
{
struct
sockaddr_in
me
;
int
sock
,
msgsock
,
flag
;
unsigned
short
port
=
DEFAULT_PORT
;
char
*
logfile
=
DEFAULT_LOGFILE
;
if
(
argc
>
1
)
port
=
atoi
(
argv
[
1
]);
struct
sockaddr_in
me
;
int
sock
,
msgsock
,
flag
;
unsigned
short
port
=
DEFAULT_PORT
;
char
*
logfile
=
DEFAULT_LOGFILE
;
int
part_no
;
if
(
argc
>
1
)
port
=
atoi
(
argv
[
1
]);
/* FIX: write our pid to a file name */
/* FIX: write our pid to a file name */
logfp
=
fopen
(
logfile
,
"a"
);
if
(
!
logfp
)
{
perror
(
logfile
);
exit
(
1
);
}
logfp
=
fopen
(
logfile
,
"a"
);
if
(
!
logfp
)
{
perror
(
logfile
);
exit
(
1
);
}
signal
(
SIGPIPE
,
sigpipe_handler
);
signal
(
SIGINT
,
sigterm_handler
);
signal
(
SIGTERM
,
sigterm_handler
);
/* FIX: make a more portable signal handler */
signal
(
SIGPIPE
,
sigpipe_handler
);
signal
(
SIGINT
,
sigterm_handler
);
signal
(
SIGTERM
,
sigterm_handler
);
siginterrupt
(
SIGPIPE
,
1
);
siginterrupt
(
SIGINT
,
1
);
siginterrupt
(
SIGTERM
,
1
);
siginterrupt
(
SIGPIPE
,
1
);
siginterrupt
(
SIGINT
,
1
);
siginterrupt
(
SIGTERM
,
1
);
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
sock
<
0
)
{
perror
(
"opening stream socket"
);
fprintf
(
logfp
,
"Error opening socket -- aborting
\n
"
);
fclose
(
logfp
);
exit
(
1
);
}
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
sock
<
0
)
{
perror
(
"opening stream socket"
);
fprintf
(
logfp
,
"Error opening socket -- aborting
\n
"
);
fclose
(
logfp
);
exit
(
1
);
}
flag
=
1
;
if
(
setsockopt
(
sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
const
void
*
)
&
flag
,
sizeof
(
int
))
<
0
)
{
perror
(
"setsockopt(SO_REUSEADDR)"
);
}
flag
=
1
;
if
(
setsockopt
(
sock
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
const
void
*
)
&
flag
,
sizeof
(
int
))
<
0
)
{
perror
(
"setsockopt(SO_REUSEADDR)"
);
}
me
.
sin_family
=
AF_INET
;
me
.
sin_addr
.
s_addr
=
INADDR_ANY
;
me
.
sin_port
=
htons
(
port
);
if
(
bind
(
sock
,
(
struct
sockaddr
*
)
&
me
,
sizeof
me
)
<
0
)
{
perror
(
"binding stream socket"
);
fprintf
(
logfp
,
"Error binding socket -- aborting
\n
"
);
fclose
(
logfp
);
exit
(
1
);
}
me
.
sin_family
=
AF_INET
;
me
.
sin_addr
.
s_addr
=
INADDR_ANY
;
me
.
sin_port
=
htons
(
port
);
if
(
bind
(
sock
,
(
struct
sockaddr
*
)
&
me
,
sizeof
me
)
<
0
)
{
perror
(
"binding stream socket"
);
fprintf
(
logfp
,
"Error binding socket -- aborting
\n
"
);
fclose
(
logfp
);
exit
(
1
);
}
/* start accepting connections */
listen
(
sock
,
5
);
/* start accepting connections */
listen
(
sock
,
5
);
printf
(
"*** %s listening on port %u ***
\n
"
,
VERSION
,
port
);
printf
(
"*** %s listening on port %u ***
\n
"
,
VERSION
,
port
);
while
(
!
sigterm
)
{
int
doc
;
while
(
!
sigterm
)
{
int
doc
;
msgsock
=
accept
(
sock
,
NULL
,
NULL
);
if
(
msgsock
==
-
1
)
{
if
(
sigterm
)
{
break
;
}
/* perror("accept"); */
continue
;
msgsock
=
accept
(
sock
,
NULL
,
NULL
);
if
(
msgsock
==
-
1
)
{
if
(
sigterm
)
{
break
;
}
logmsg
(
"New client connected"
);
doc
=
get_request
(
msgsock
);
send_doc
(
msgsock
,
doc
);
close
(
msgsock
);
/* perror("accept"); */
continue
;
}
logmsg
(
"New client connected"
);
close
(
sock
);
fclose
(
logfp
);
doc
=
get_request
(
msgsock
,
&
part_no
);
send_doc
(
msgsock
,
doc
,
part_no
);
return
0
;
close
(
msgsock
);
}
close
(
sock
);
fclose
(
logfp
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment