... | ... |
@@ -41,8 +41,13 @@ core: |
41 | 41 |
- new parts: |
42 | 42 |
UNIX domain socket server implemented |
43 | 43 |
- changes: |
44 |
+ - command line: removed -p port and extended -l: |
|
45 |
+ -l [proto:]addr[:port] , where proto=udp|tcp and |
|
46 |
+ addr= host|ip_address|interface_name. The format is the same |
|
47 |
+ as for listen in the config file. ipv6 addresses must be enclosed in |
|
48 |
+ []. |
|
44 | 49 |
- added from_uri & to_uri: behave exactly like uri but use the |
45 |
- "From:"/"To:" uris |
|
50 |
+ "From:"/"To:" uris |
|
46 | 51 |
(e.g.: if (from_uri==myself) ..., if (to_uri=~"^sip:test@")... ) |
47 | 52 |
- config: better escape support in strings (e.g. \", \<cr>, \x0a, \012) |
48 | 53 |
- bad network addresses are now automatically fixed |
... | ... |
@@ -54,6 +54,8 @@ |
54 | 54 |
* => kill all or abort) (andrei) |
55 | 55 |
* force a shm_unlock before cleaning-up, in case we have a |
56 | 56 |
* crashed childvwhich still holds the lock (andrei) |
57 |
+ * 2004-12-02 removed -p, extended -l to support [proto:]address[:port], |
|
58 |
+ * added parse_phostport, parse_proto (andrei) |
|
57 | 59 |
*/ |
58 | 60 |
|
59 | 61 |
|
... | ... |
@@ -135,12 +137,12 @@ Usage: " NAME " -l address [-p port] [-l address [-p port]...] [options]\n\ |
135 | 137 |
Options:\n\ |
136 | 138 |
-f file Configuration file (default " CFG_FILE ")\n\ |
137 | 139 |
-c Check configuration file for errors\n\ |
138 |
- -p port Listen on the specified port (default: 5060)\n\ |
|
139 |
- applies to the last address in -l and to all \n\ |
|
140 |
- following that do not have a corresponding -p\n\ |
|
141 | 140 |
-l address Listen on the specified address/interface (multiple -l\n\ |
142 |
- mean listening on more addresses). The default behavior\n\ |
|
143 |
- is to listen on all the interfaces\n\ |
|
141 |
+ mean listening on more addresses). The address format is\n\ |
|
142 |
+ [proto:]addr[:port], where proto=udp|tcp and \n\ |
|
143 |
+ addr= host|ip_address|interface_name. E.g: -l locahost, \n\ |
|
144 |
+ -l udp:127.0.0.1:5080, -l eth0:5062 The default behavior\n\ |
|
145 |
+ is to listen on all the interfaces.\n\ |
|
144 | 146 |
-n processes Number of child processes to fork per interface\n\ |
145 | 147 |
(default: 8)\n\ |
146 | 148 |
-r Use dns to check if is necessary to add a \"received=\"\n\ |
... | ... |
@@ -673,6 +675,126 @@ error: |
673 | 675 |
|
674 | 676 |
|
675 | 677 |
|
678 |
+/* returns -1 on error, 0 on success |
|
679 |
+ * sets proto */ |
|
680 |
+static int parse_proto(unsigned char* s, long len, int* proto) |
|
681 |
+{ |
|
682 |
+#define PROTO2UINT(a, b, c) (( (((unsigned int)(a))<<16)+ \ |
|
683 |
+ (((unsigned int)(b))<<8)+ \ |
|
684 |
+ ((unsigned int)(c)) ) | 0x20202020) |
|
685 |
+ unsigned int i; |
|
686 |
+ if (len!=3) return -1; |
|
687 |
+ i=PROTO2UINT(s[0], s[1], s[2]); |
|
688 |
+ switch(i){ |
|
689 |
+ case PROTO2UINT('u', 'd', 'p'): |
|
690 |
+ *proto=PROTO_UDP; |
|
691 |
+ break; |
|
692 |
+#ifdef USE_TCP |
|
693 |
+ case PROTO2UINT('t', 'c', 'p'): |
|
694 |
+ *proto=PROTO_TCP; |
|
695 |
+ break; |
|
696 |
+#ifdef USE_TLS |
|
697 |
+ case PROTO2UINT('t', 'l', 's'): |
|
698 |
+ *proto=PROTO_TLS; |
|
699 |
+ break; |
|
700 |
+#endif |
|
701 |
+#endif |
|
702 |
+ default: |
|
703 |
+ return -1; |
|
704 |
+ } |
|
705 |
+ return 0; |
|
706 |
+} |
|
707 |
+ |
|
708 |
+ |
|
709 |
+ |
|
710 |
+/* |
|
711 |
+ * parses [proto:]host[:port] |
|
712 |
+ * where proto= udp|tcp|tls |
|
713 |
+ * returns 0 on success and -1 on failure |
|
714 |
+ */ |
|
715 |
+static int parse_phostport(char* s, char** host, int* hlen, int* port, |
|
716 |
+ int* proto) |
|
717 |
+{ |
|
718 |
+ char* first; /* first ':' occurrence */ |
|
719 |
+ char* second; /* second ':' occurrence */ |
|
720 |
+ char* p; |
|
721 |
+ int bracket; |
|
722 |
+ char* tmp; |
|
723 |
+ |
|
724 |
+ first=second=0; |
|
725 |
+ bracket=0; |
|
726 |
+ |
|
727 |
+ /* find the first 2 ':', ignoring possible ipv6 addresses |
|
728 |
+ * (substrings between []) |
|
729 |
+ */ |
|
730 |
+ for(p=s; *p; p++){ |
|
731 |
+ switch(*p){ |
|
732 |
+ case '[': |
|
733 |
+ bracket++; |
|
734 |
+ if (bracket>1) goto error_brackets; |
|
735 |
+ break; |
|
736 |
+ case ']': |
|
737 |
+ bracket--; |
|
738 |
+ if (bracket<0) goto error_brackets; |
|
739 |
+ break; |
|
740 |
+ case ':': |
|
741 |
+ if (bracket==0){ |
|
742 |
+ if (first==0) first=p; |
|
743 |
+ else if( second==0) second=p; |
|
744 |
+ else goto error_colons; |
|
745 |
+ } |
|
746 |
+ break; |
|
747 |
+ } |
|
748 |
+ } |
|
749 |
+ if (p==s) return -1; |
|
750 |
+ if (*(p-1)==':') goto error_colons; |
|
751 |
+ |
|
752 |
+ if (first==0){ /* no ':' => only host */ |
|
753 |
+ *host=s; |
|
754 |
+ *hlen=(int)(p-s); |
|
755 |
+ *port=0; |
|
756 |
+ *proto=0; |
|
757 |
+ return 0; |
|
758 |
+ } |
|
759 |
+ if (second){ /* 2 ':' found => check if valid */ |
|
760 |
+ if (parse_proto(s, first-s, proto)<0) goto error_proto; |
|
761 |
+ *port=strtol(second+1, &tmp, 10); |
|
762 |
+ if ((tmp==0)||(*tmp)||(tmp==second+1)) goto error_port; |
|
763 |
+ *host=first+1; |
|
764 |
+ *hlen=(int)(second-*host); |
|
765 |
+ return 0; |
|
766 |
+ } |
|
767 |
+ /* only 1 ':' found => it's either proto:host or host:port */ |
|
768 |
+ *port=strtol(first+1, &tmp, 10); |
|
769 |
+ if ((tmp==0)||(*tmp)||(tmp==first+1)){ |
|
770 |
+ /* invalid port => it's proto:host */ |
|
771 |
+ if (parse_proto(s, first-s, proto)<0) goto error_proto; |
|
772 |
+ *port=0; |
|
773 |
+ *host=first+1; |
|
774 |
+ *hlen=(int)(p-*host); |
|
775 |
+ }else{ |
|
776 |
+ /* valid port => its host:port */ |
|
777 |
+ *proto=0; |
|
778 |
+ *host=s; |
|
779 |
+ *hlen=(int)(first-*host); |
|
780 |
+ } |
|
781 |
+ return 0; |
|
782 |
+error_brackets: |
|
783 |
+ LOG(L_ERR, "ERROR: parse_phostport: too many brackets in %s\n", s); |
|
784 |
+ return -1; |
|
785 |
+error_colons: |
|
786 |
+ LOG(L_ERR, "ERROR: parse_phostport: too many colons in %s\n", s); |
|
787 |
+ return -1; |
|
788 |
+error_proto: |
|
789 |
+ LOG(L_ERR, "ERROR: parse_phostport: bad protocol in %s\n", s); |
|
790 |
+ return -1; |
|
791 |
+error_port: |
|
792 |
+ LOG(L_ERR, "ERROR: parse_phostport: bad port number in %s\n", s); |
|
793 |
+ return -1; |
|
794 |
+} |
|
795 |
+ |
|
796 |
+ |
|
797 |
+ |
|
676 | 798 |
/* main loop */ |
677 | 799 |
int main_loop() |
678 | 800 |
{ |
... | ... |
@@ -1064,6 +1186,9 @@ int main(int argc, char** argv) |
1064 | 1186 |
FILE* cfg_stream; |
1065 | 1187 |
int c,r; |
1066 | 1188 |
char *tmp; |
1189 |
+ int tmp_len; |
|
1190 |
+ int port; |
|
1191 |
+ int proto; |
|
1067 | 1192 |
char *options; |
1068 | 1193 |
int ret; |
1069 | 1194 |
unsigned int seed; |
... | ... |
@@ -1090,7 +1215,7 @@ int main(int argc, char** argv) |
1090 | 1215 |
#ifdef STATS |
1091 | 1216 |
"s:" |
1092 | 1217 |
#endif |
1093 |
- "f:cp:m:b:l:n:N:rRvdDETVhw:t:u:g:P:G:i:x:"; |
|
1218 |
+ "f:cm:b:l:n:N:rRvdDETVhw:t:u:g:P:G:i:x:"; |
|
1094 | 1219 |
|
1095 | 1220 |
while((c=getopt(argc,argv,options))!=-1){ |
1096 | 1221 |
switch(c){ |
... | ... |
@@ -1106,13 +1231,6 @@ int main(int argc, char** argv) |
1106 | 1231 |
stat_file=optarg; |
1107 | 1232 |
#endif |
1108 | 1233 |
break; |
1109 |
- case 'p': |
|
1110 |
- port_no=strtol(optarg, &tmp, 10); |
|
1111 |
- if (tmp &&(*tmp)){ |
|
1112 |
- fprintf(stderr, "bad port number: -p %s\n", optarg); |
|
1113 |
- goto error; |
|
1114 |
- } |
|
1115 |
- break; |
|
1116 | 1234 |
case 'm': |
1117 | 1235 |
shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024; |
1118 | 1236 |
if (tmp &&(*tmp)){ |
... | ... |
@@ -1133,8 +1251,15 @@ int main(int argc, char** argv) |
1133 | 1251 |
} |
1134 | 1252 |
break; |
1135 | 1253 |
case 'l': |
1254 |
+ if (parse_phostport(optarg, &tmp, &tmp_len, |
|
1255 |
+ &port, &proto)<0){ |
|
1256 |
+ fprintf(stderr, "bad -l address specifier: %s\n", |
|
1257 |
+ optarg); |
|
1258 |
+ goto error; |
|
1259 |
+ } |
|
1260 |
+ tmp[tmp_len]=0; /* null terminate the host */ |
|
1136 | 1261 |
/* add a new addr. to our address list */ |
1137 |
- if (add_listen_iface(optarg, 0, 0, 0)!=0){ |
|
1262 |
+ if (add_listen_iface(tmp, port, proto, 0)!=0){ |
|
1138 | 1263 |
fprintf(stderr, "failed to add new listen address\n"); |
1139 | 1264 |
goto error; |
1140 | 1265 |
} |