203 |
|
|
204 |
|
|
205 |
/** |
/** |
206 |
|
* Replace all occurrences of the sub-string old in the string s with |
207 |
|
* the new sub-string new. The method is case sensitive for the |
208 |
|
* sub-strings new and old. The string parameter s must be an |
209 |
|
* allocated string, not a character array. |
210 |
|
* @param src An allocated string reference (e.g. &string) |
211 |
|
* @param old The old sub-string |
212 |
|
* @param new The new sub-string |
213 |
|
* @return src where all occurrences of the old sub-string are |
214 |
|
* replaced with the new sub-string. |
215 |
|
*/ |
216 |
|
char *replace_string(char **src, const char *old, const char *new) { |
217 |
|
|
218 |
|
int i; |
219 |
|
int d; |
220 |
|
|
221 |
|
ASSERT(src && *src && old && new); |
222 |
|
|
223 |
|
i= count_words(*src, old); |
224 |
|
d= strlen(new)-strlen(old); |
225 |
|
|
226 |
|
if(i==0) |
227 |
|
return *src; |
228 |
|
if(d>0) |
229 |
|
d*= i; |
230 |
|
else |
231 |
|
d= 0; |
232 |
|
|
233 |
|
{ |
234 |
|
char *p, *q; |
235 |
|
int l= strlen(old); |
236 |
|
char buf[strlen(*src)+d+1]; |
237 |
|
|
238 |
|
q= *src; |
239 |
|
*buf= '\0'; |
240 |
|
|
241 |
|
while((p= strstr(q, old))) { |
242 |
|
|
243 |
|
*p= '\0'; |
244 |
|
strcat(buf, q); |
245 |
|
strcat(buf, new); |
246 |
|
p+= l; |
247 |
|
q= p; |
248 |
|
|
249 |
|
} |
250 |
|
|
251 |
|
strcat(buf, q); |
252 |
|
free(*src); |
253 |
|
*src= xstrdup(buf); |
254 |
|
|
255 |
|
} |
256 |
|
|
257 |
|
return *src; |
258 |
|
|
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
/** |
263 |
|
* Count the number the sub-string word occurs in s. |
264 |
|
* @param s The String to search for word in |
265 |
|
* @param word The sub-string to count in s |
266 |
|
*/ |
267 |
|
int count_words(char *s, const char *word) { |
268 |
|
|
269 |
|
int i= 0; |
270 |
|
char *p= s; |
271 |
|
|
272 |
|
ASSERT(s && word); |
273 |
|
|
274 |
|
while((p= strstr(p, word))) { i++; p++; } |
275 |
|
|
276 |
|
return i; |
277 |
|
|
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
/** |
282 |
* Return TRUE if the string <i>a</i> starts with the string <i>b</i>. |
* Return TRUE if the string <i>a</i> starts with the string <i>b</i>. |
283 |
* @param a The string to search for b in |
* @param a The string to search for b in |
284 |
* @param b The sub-string to test a against |
* @param b The sub-string to test a against |
537 |
if(s->portlist) { |
if(s->portlist) { |
538 |
|
|
539 |
for(n= s->portlist; n; n= n->next) { |
for(n= s->portlist; n; n= n->next) { |
540 |
|
|
541 |
if(n->family == AF_INET) { |
if(n->family == AF_INET) { |
542 |
|
|
543 |
if(n->ssl != NULL) { |
if(n->SSL.use_ssl) { |
544 |
|
|
545 |
printf(" %-20s = %s:%d%s [protocol %s via SSL]\n", "Host:Port", |
printf(" %-20s = %s:%d%s [protocol %s via SSL]\n", "Host:Port", |
546 |
n->hostname, n->port, n->request?n->request:"", |
n->hostname, n->port, n->request?n->request:"", |
547 |
n->protocol->name); |
n->protocol->name); |
548 |
|
|
549 |
if(n->certmd5 != NULL) |
if(n->SSL.certmd5 != NULL) |
550 |
printf(" %-20s = %s\n", "Server cert md5 sum", n->certmd5); |
printf(" %-20s = %s\n", "Server cert md5 sum", n->SSL.certmd5); |
551 |
|
|
552 |
} else { |
} else { |
553 |
|
|
554 |
printf(" %-20s = %s:%d%s [protocol %s]\n", "Host:Port", |
printf(" %-20s = %s:%d%s [protocol %s]\n", "Host:Port", |
555 |
n->hostname, n->port, n->request?n->request:"", |
n->hostname, n->port, n->request?n->request:"", |
556 |
n->protocol->name); |
n->protocol->name); |
557 |
|
|
558 |
} |
} |
559 |
|
|
560 |
} else if(n->family == AF_UNIX) { |
} else if(n->family == AF_UNIX) { |
561 |
|
|
562 |
printf(" %-20s = %s [protocol %s]\n", "Unix Socket", |
printf(" %-20s = %s [protocol %s]\n", "Unix Socket", |
563 |
n->pathname, n->protocol->name); |
n->pathname, n->protocol->name); |
564 |
|
|
565 |
} |
} |
566 |
|
|
567 |
} |
} |
568 |
|
|
569 |
} |
} |
570 |
|
|
571 |
for(t= s->timestamplist; t; t= t->next) { |
for(t= s->timestamplist; t; t= t->next) { |