MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / str2s

Function str2s

ut.h:184–218  ·  view source on GitHub ↗

converts a str to an u. short, returns the u. short and sets *err on * error and if err!=null */

Source from the content-addressed store, hash-verified

182 * error and if err!=null
183 */
184static inline unsigned short str2s(const char* s, unsigned int len,
185 int *err)
186{
187 unsigned short ret;
188 int i;
189 unsigned char *limit;
190 unsigned char *str;
191
192 /*init*/
193 str=(unsigned char*)s;
194 ret=i=0;
195 limit=str+len;
196
197 for(;str<limit ;str++){
198 if ( (*str <= '9' ) && (*str >= '0') ){
199 ret=ret*10+*str-'0';
200 i++;
201 if (i>5) goto error_digits;
202 }else{
203 //error unknown char
204 goto error_char;
205 }
206 }
207 if (err) *err=0;
208 return ret;
209
210error_digits:
211 LM_DBG("too many letters in [%.*s]\n", (int)len, s);
212 if (err) *err=1;
213 return 0;
214error_char:
215 LM_DBG("unexpected char %c in %.*s\n", *str, (int)len, s);
216 if (err) *err=1;
217 return 0;
218}
219
220
221static inline int btostr( char *p, unsigned char val)

Callers 13

datagram_parseFunction · 0.85
is_maxfwd_presentFunction · 0.85
sip_validate_hdrsFunction · 0.85
stream_parseFunction · 0.85
jsonrpc_get_dstFunction · 0.85
xmlrpc_parseFunction · 0.85
rmq_parseFunction · 0.85
sdp_mangle_portFunction · 0.85
parse_cachedb_urlFunction · 0.85
parse_viaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected