mirror of /home/gitosis/repositories/libowfat.git
Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat
https://www.fefe.de/libowfat/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
711 B
25 lines
711 B
#include "scan.h" |
|
|
|
/* parse a netstring, input buffer is in (len bytes). |
|
* if parsing is successful: |
|
* *dest points to string and *slen is size of string |
|
* return number of bytes parsed |
|
* else |
|
* return 0 |
|
* Note: *dest will point inside the input buffer! |
|
*/ |
|
size_t scan_netstring(const char* in,size_t len,char** dest,size_t* slen) { |
|
// [len]":"[string]"," |
|
// 3:foo,3:bar,4:fini, |
|
unsigned long l; |
|
size_t n=scan_ulongn(in,len,&l); |
|
if (!n || /* did not start with a number */ |
|
n+2+l<l || /* overflow */ |
|
n+2+l>len || /* longer than we have input data */ |
|
in[n]!=':' || /* syntax error */ |
|
in[n+l+1]!=',') |
|
return 0; |
|
*dest=(char*)in+n+1; |
|
*slen=l; |
|
return n+2+l; |
|
}
|
|
|