Browse code

sip: moved sip_target_set to resolver

Raphael Coeffic authored on 19/11/2013 12:27:38
Showing 4 changed files
... ...
@@ -720,6 +720,83 @@ dns_base_entry* dns_naptr_entry::get_rr(dns_record* rr, u_char* begin, u_char* e
720 720
     return naptr_r;
721 721
 }
722 722
 
723
+sip_target::sip_target() {}
724
+
725
+sip_target::sip_target(const sip_target& target)
726
+{
727
+    *this = target;
728
+}
729
+
730
+const sip_target& sip_target::operator = (const sip_target& target)
731
+{
732
+    memcpy(&ss,&target.ss,sizeof(sockaddr_storage));
733
+    memcpy(trsp,target.trsp,SIP_TRSP_SIZE_MAX+1);
734
+    return target;
735
+}
736
+
737
+void sip_target::clear()
738
+{
739
+    memset(&ss,0,sizeof(sockaddr_storage));
740
+    memset(trsp,'\0',SIP_TRSP_SIZE_MAX+1);
741
+}
742
+
743
+sip_target_set::sip_target_set()
744
+    : dest_list(),
745
+      dest_list_it(dest_list.begin())
746
+{}
747
+
748
+void sip_target_set::reset_iterator()
749
+{
750
+    dest_list_it = dest_list.begin();
751
+}
752
+
753
+bool sip_target_set::has_next()
754
+{
755
+    return dest_list_it != dest_list.end();
756
+}
757
+
758
+int sip_target_set::get_next(sockaddr_storage* ss, cstring& next_trsp,
759
+			     unsigned int flags)
760
+{
761
+    do {
762
+	if(!has_next())
763
+	    return -1;
764
+
765
+	sip_target& t = *dest_list_it;
766
+	memcpy(ss,&t.ss,sizeof(sockaddr_storage));
767
+	next_trsp = cstring(t.trsp);
768
+
769
+	next();
770
+
771
+	// set default transport to UDP
772
+	if(!next_trsp.len)
773
+	    next_trsp = cstring("udp");
774
+
775
+    } while(!(flags & TR_FLAG_DISABLE_BL) &&
776
+	    tr_blacklist::instance()->exist(ss));
777
+
778
+    return 0;
779
+}
780
+
781
+bool sip_target_set::next()
782
+{
783
+    dest_list_it++;
784
+    return has_next();
785
+}
786
+
787
+void sip_target_set::debug()
788
+{
789
+    DBG("target list:");
790
+
791
+    for(list<sip_target>::iterator it = dest_list.begin();
792
+	it != dest_list.end(); it++) {
793
+
794
+	DBG("\t%s:%u/%s to target list",
795
+	    am_inet_ntop(&it->ss).c_str(),
796
+	    am_get_port(&it->ss),it->trsp);
797
+    }
798
+}
799
+
723 800
 _resolver::_resolver()
724 801
     : cache(DNS_CACHE_SIZE)
725 802
 {
... ...
@@ -203,6 +203,39 @@ public:
203 203
     int next_ip(dns_handle* h, sockaddr_storage* sa) { return -1; }
204 204
 };
205 205
 
206
+#define SIP_TRSP_SIZE_MAX 4
207
+
208
+struct sip_target
209
+{
210
+    sockaddr_storage ss;
211
+    char             trsp[SIP_TRSP_SIZE_MAX+1];
212
+
213
+    sip_target();
214
+    sip_target(const sip_target& target);
215
+
216
+    void clear();
217
+    const sip_target& operator = (const sip_target& target);
218
+};
219
+
220
+struct sip_target_set
221
+{
222
+    list<sip_target>           dest_list;
223
+    list<sip_target>::iterator dest_list_it;
224
+
225
+    sip_target_set();
226
+
227
+    void reset_iterator();
228
+    bool has_next();
229
+    int  get_next(sockaddr_storage* ss, cstring& next_trsp,
230
+		  unsigned int flags);
231
+    bool next();
232
+
233
+    void debug();
234
+
235
+private:
236
+    sip_target_set(const sip_target_set&) {}
237
+};
238
+
206 239
 typedef map<string,dns_entry*> dns_entry_map;
207 240
 
208 241
 class _resolver
... ...
@@ -66,19 +66,6 @@ inline trans_timer** fetch_timer(unsigned int timer_type, trans_timer** base)
66 66
     return NULL;
67 67
 }
68 68
 
69
-void sip_target_set::debug()
70
-{
71
-    DBG("target list:");
72
-
73
-    for(list<sip_target>::iterator it = dest_list.begin();
74
-	it != dest_list.end(); it++) {
75
-
76
-	DBG("\t%s:%u/%s to target list",
77
-	    am_inet_ntop(&it->ss).c_str(),
78
-	    am_get_port(&it->ss),it->trsp);
79
-    }
80
-}
81
-
82 69
 sip_trans::sip_trans()
83 70
     : msg(NULL),
84 71
       targets(NULL),
... ...
@@ -39,6 +39,8 @@
39 39
 using std::list;
40 40
 
41 41
 struct sip_msg;
42
+struct sip_target_set;
43
+
42 44
 class trsp_socket;
43 45
 class msg_logger;
44 46
 
... ...
@@ -102,66 +104,6 @@ public:
102 104
     void fire();
103 105
 };
104 106
 
105
-#define SIP_TRSP_SIZE_MAX 4
106
-
107
-struct sip_target
108
-{
109
-    sockaddr_storage ss;
110
-    char             trsp[SIP_TRSP_SIZE_MAX+1];
111
-
112
-    sip_target() {}
113
-
114
-    sip_target(const sip_target& target) {
115
-	*this = target;
116
-    }
117
-
118
-    const sip_target& operator = (const sip_target& target) {
119
-	memcpy(&ss,&target.ss,sizeof(sockaddr_storage));
120
-	memcpy(trsp,target.trsp,SIP_TRSP_SIZE_MAX+1);
121
-	return target;
122
-    }
123
-
124
-    void clear() {
125
-	memset(&ss,0,sizeof(sockaddr_storage));
126
-	memset(trsp,'\0',SIP_TRSP_SIZE_MAX+1);
127
-    }
128
-};
129
-
130
-struct sip_target_set
131
-{
132
-    list<sip_target>           dest_list;
133
-    list<sip_target>::iterator dest_list_it;
134
-
135
-    sip_target_set()
136
-	: dest_list(),
137
-	  dest_list_it(dest_list.begin())
138
-    {}
139
-
140
-    void reset_iterator() {
141
-	dest_list_it = dest_list.begin();
142
-    }
143
-
144
-    bool has_next() {
145
-	return dest_list_it != dest_list.end();
146
-    }
147
-
148
-    void copy_next(sockaddr_storage* ss, cstring* next_trsp) {
149
-	sip_target& t = *dest_list_it;
150
-	memcpy(ss,&t.ss,sizeof(sockaddr_storage));
151
-	*next_trsp = cstring(t.trsp);
152
-    }
153
-
154
-    bool next() {
155
-	dest_list_it++;
156
-	return has_next();
157
-    }
158
-
159
-    void debug();
160
-
161
-private:
162
-    sip_target_set(const sip_target_set&) {}
163
-};
164
-
165 107
 class sip_trans
166 108
 {
167 109
     trans_timer* timers[SIP_TRANS_TIMERS];