Browse code

core: merged proto id to name functions

Daniel-Constantin Mierla authored on 15/12/2011 12:01:51
Showing 6 changed files
... ...
@@ -937,24 +937,6 @@ void dst_blst_mem_info(rpc_t* rpc, void* ctx)
937 937
 
938 938
 
939 939
 
940
-static char* get_proto_name(unsigned char proto)
941
-{
942
-	switch(proto){
943
-		case PROTO_NONE:
944
-			return "*";
945
-		case PROTO_UDP:
946
-			return "udp";
947
-		case PROTO_TCP:
948
-			return "tcp";
949
-		case PROTO_TLS:
950
-			return "tls";
951
-		case PROTO_SCTP:
952
-			return "sctp";
953
-		default:
954
-			return "unknown";
955
-	}
956
-}
957
-
958 940
 
959 941
 #ifdef USE_DST_BLACKLIST_STATS
960 942
 
... ...
@@ -399,6 +399,14 @@ static struct _check_self_func {
399 399
 	struct _check_self_func *next;
400 400
 } *_check_self_func_list = NULL;
401 401
 
402
+/* check if _check_self_func_list is set
403
+ * - return 1 if yes, 0 if no
404
+ */
405
+int is_check_self_func_list_set(void)
406
+{
407
+	return (_check_self_func_list)?1:0;
408
+}
409
+
402 410
 /* register a function to be called when matching for myself
403 411
  * - return 0 on success, -1 on error
404 412
  * - f must have same prototype as check_self() and return same kind of values
... ...
@@ -105,6 +105,7 @@ int update_sock_struct_from_via( union sockaddr_union* to,
105 105
 
106 106
 int forward_reply( struct sip_msg* msg);
107 107
 
108
+int is_check_self_func_list_set(void);
108 109
 
109 110
 
110 111
 /* params:
... ...
@@ -337,7 +337,7 @@ int is_mcast(struct ip_addr* ip)
337 337
  * @param proto - protocol number
338 338
  * @return  string with the protocol name or "unknown".
339 339
  */
340
-char* proto2a(enum sip_protos proto)
340
+char* get_proto_name(unsigned int proto)
341 341
 {
342 342
 	switch(proto){
343 343
 		case PROTO_NONE:
... ...
@@ -350,8 +350,7 @@ char* proto2a(enum sip_protos proto)
350 350
 			return "tls";
351 351
 		case PROTO_SCTP:
352 352
 			return "sctp";
353
-		case PROTO_OTHER:
354
-			return "other";
353
+		default:
354
+			return "unknown";
355 355
 	}
356
-	return "unknown";
357 356
 }
... ...
@@ -250,7 +250,8 @@ void print_ip(char* prefix, struct ip_addr* ip, char* suffix);
250 250
 void stdout_print_ip(struct ip_addr* ip);
251 251
 void print_net(struct net* net);
252 252
 
253
-char* proto2a(enum sip_protos proto);
253
+char* get_proto_name(unsigned int proto);
254
+#define proto2a get_proto_name
254 255
 
255 256
 
256 257
 
... ...
@@ -282,7 +282,7 @@ static void free_sock_info(struct socket_info* si)
282 282
 
283 283
 
284 284
 
285
-static char* get_proto_name(unsigned short proto)
285
+static char* get_valid_proto_name(unsigned short proto)
286 286
 {
287 287
 	switch(proto){
288 288
 		case PROTO_NONE:
... ...
@@ -325,7 +325,7 @@ int socket2str(char* s, int* len, struct socket_info* si)
325 325
 	str proto;
326 326
 	int l;
327 327
 	
328
-	proto.s = get_proto_name(si->proto);
328
+	proto.s = get_valid_proto_name(si->proto);
329 329
 	proto.len = strlen(proto.s);
330 330
 	
331 331
 	l = proto.len + si->address_str.len + si->port_no_str.len + 2;
... ...
@@ -1650,7 +1650,7 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
1650 1650
 			){
1651 1651
 			if (si->flags & SI_IS_MCAST){
1652 1652
 				LOG(L_WARN, "WARNING: removing entry %s:%s [%s]:%s\n",
1653
-					get_proto_name(si->proto), si->name.s, 
1653
+					get_valid_proto_name(si->proto), si->name.s, 
1654 1654
 					si->address_str.s, si->port_no_str.s);
1655 1655
 				l = si;
1656 1656
 				si=si->next;
... ...
@@ -1662,7 +1662,7 @@ static int fix_socket_list(struct socket_info **list, int* type_flags)
1662 1662
 					if (ail->flags & SI_IS_MCAST){
1663 1663
 						LOG(L_WARN, "WARNING: removing mh entry %s:%s"
1664 1664
 								" [%s]:%s\n",
1665
-								get_proto_name(si->proto), ail->name.s, 
1665
+								get_valid_proto_name(si->proto), ail->name.s, 
1666 1666
 								ail->address_str.s, si->port_no_str.s);
1667 1667
 						tmp_ail=ail;
1668 1668
 						ail=ail->next;
... ...
@@ -1866,7 +1866,7 @@ void print_all_socket_lists()
1866 1866
 		for(si=list?*list:0; si; si=si->next){
1867 1867
 			if (si->addr_info_lst){
1868 1868
 				printf("             %s: (%s",
1869
-						get_proto_name(proto),
1869
+						get_valid_proto_name(proto),
1870 1870
 						si->address_str.s);
1871 1871
 				for (ai=si->addr_info_lst; ai; ai=ai->next)
1872 1872
 					printf(", %s", ai->address_str.s);
... ...
@@ -1876,7 +1876,7 @@ void print_all_socket_lists()
1876 1876
 						si->flags & SI_IS_MHOMED? " mhomed" : "");
1877 1877
 			}else{
1878 1878
 				printf("             %s: %s",
1879
-						get_proto_name(proto),
1879
+						get_valid_proto_name(proto),
1880 1880
 						si->name.s);
1881 1881
 				if (!si->flags & SI_IS_IP)
1882 1882
 					printf(" [%s]", si->address_str.s);
... ...
@@ -1896,10 +1896,10 @@ void print_aliases()
1896 1896
 
1897 1897
 	for(a=aliases; a; a=a->next) 
1898 1898
 		if (a->port)
1899
-			printf("             %s: %.*s:%d\n", get_proto_name(a->proto), 
1899
+			printf("             %s: %.*s:%d\n", get_valid_proto_name(a->proto), 
1900 1900
 					a->alias.len, a->alias.s, a->port);
1901 1901
 		else
1902
-			printf("             %s: %.*s:*\n", get_proto_name(a->proto), 
1902
+			printf("             %s: %.*s:*\n", get_valid_proto_name(a->proto), 
1903 1903
 					a->alias.len, a->alias.s);
1904 1904
 }
1905 1905