Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kv-distributed
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
BHAVESHKUMAR SHYAMSUNDAR YADAV
kv-distributed
Commits
b97566f8
Commit
b97566f8
authored
Nov 24, 2019
by
AXEL JAMES
Committed by
Bhavesh Yadav
Nov 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds address field parsingl
parent
f518d94c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
server/parsexml.c
server/parsexml.c
+46
-3
server/parsexml.h
server/parsexml.h
+3
-1
No files found.
server/parsexml.c
View file @
b97566f8
...
...
@@ -21,7 +21,7 @@ char *toRespXML(char* msg){
}
char
*
toXML
(
char
*
reqType
,
char
*
key
,
char
*
value
){
char
*
toXML
(
char
*
reqType
,
char
*
key
,
char
*
value
,
char
*
ip
,
int
port
){
char
*
line1
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
"
;
char
*
line21
=
"<KVMessage type=
\"
"
;
...
...
@@ -30,10 +30,14 @@ char * toXML(char *reqType, char *key, char * value){
char
*
line32
=
"</Key>
\n
"
;
char
*
line41
=
"<Value>"
;
char
*
line42
=
"</Value>
\n
"
;
char
*
line61
=
"<Address>"
;
char
*
line62
=
"</Address>
\n
"
;
char
*
line5
=
"</KVMessage>
\n
"
;
char
*
line6
;
int
len2
=
strlen
(
line21
)
+
strlen
(
line22
)
+
strlen
(
reqType
)
+
1
;
int
len3
=
strlen
(
line31
)
+
strlen
(
line32
)
+
strlen
(
key
)
+
1
;
int
len4
=
strlen
(
line41
)
+
strlen
(
line42
)
+
strlen
(
value
)
+
1
;
int
len6
=
strlen
(
line61
)
+
strlen
(
line62
)
+
21
;
char
*
line2
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len2
);
char
*
line3
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len3
);
...
...
@@ -52,17 +56,37 @@ char * toXML(char *reqType, char *key, char * value){
strcat
(
line4
,
line42
);
int
msglen
=
strlen
(
line1
)
+
strlen
(
line2
)
+
strlen
(
line3
)
+
strlen
(
line4
)
+
strlen
(
line5
)
+
1
;
if
(
ip
!=
NULL
)
{
char
str
[
7
];
sprintf
(
str
,
" %d"
,
port
);
line6
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len6
);
strcpy
(
line6
,
line61
);
strcat
(
line6
,
ip
);
strcat
(
line6
,
str
);
strcat
(
line6
,
line62
);
msglen
+=
strlen
(
line6
);
}
char
*
message
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
msglen
);
strcpy
(
message
,
line1
);
strcat
(
message
,
line2
);
strcat
(
message
,
line3
);
if
(
!
strcmp
(
reqType
,
"putreq"
)
||
!
strcmp
(
reqType
,
"resp"
))
strcat
(
message
,
line4
);
if
(
ip
!=
NULL
)
{
strcat
(
message
,
line6
);
}
strcat
(
message
,
line5
);
free
(
line2
);
free
(
line3
);
free
(
line4
);
printf
(
"Message%s"
,
message
);
return
message
;
}
...
...
@@ -111,7 +135,7 @@ extReq_t *extractXML(char *buffer){
char
*
p
,
*
q
;
req
->
operation
=
malloc
(
sizeof
(
char
)
*
12
);
req
->
err
=
malloc
(
sizeof
(
char
)
*
170
);
req
->
val
=
malloc
(
sizeof
(
char
)
*
256
*
1024
+
1
);
req
->
val
=
malloc
(
sizeof
(
char
)
*
256
*
1024
+
1
);
req
->
error
=
true
;
p
=
strstr
(
buffer
,
"type="
)
+
6
;
q
=
strstr
(
buffer
,
"
\"
>"
);
...
...
@@ -154,7 +178,26 @@ extReq_t *extractXML(char *buffer){
req
->
val
[
q
-
p
]
=
'\0'
;
}
}
p
=
strstr
(
buffer
,
"<Address>"
)
+
9
;
q
=
strstr
(
buffer
,
"</Address>"
);
if
(
p
!=
NULL
&&
q
!=
NULL
){
strcpy
(
req
->
ipAddr
,
strtok
(
p
,
" "
));
int
l
=
strlen
(
req
->
ipAddr
);
char
port_s
[
6
];
memcpy
(
port_s
,
p
+
l
+
1
,
q
-
p
-
l
-
1
);
port_s
[
q
-
p
-
l
-
1
]
=
'\0'
;
req
->
port
=
atoi
(
port_s
);
}
req
->
error
=
false
;
return
req
;
}
\ No newline at end of file
}
// void main(){
// extReq_t *request = extractXML(toXML("abc","cdefg","123","111.111.111.111",12345));
// printf("Parsed msg:%s %d",request->ipAddr,request->port);
// }
\ No newline at end of file
server/parsexml.h
View file @
b97566f8
...
...
@@ -5,10 +5,12 @@ struct extractedReq {
char
*
val
;
char
*
operation
;
char
*
err
;
char
ipAddr
[
16
];
int
port
;
bool
error
;
};
typedef
struct
extractedReq
extReq_t
;
char
*
toXML
(
char
*
reqType
,
char
*
key
,
char
*
value
);
char
*
toXML
(
char
*
reqType
,
char
*
key
,
char
*
value
,
char
*
ip
,
int
port
);
extReq_t
*
extractXML
(
char
*
buffer
);
char
*
toRespXML
(
char
*
msg
);
char
*
extractRespXml
(
FILE
*
fp
,
char
*
buffer
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment