Browse code

sip: moved sip_target_set to resolver

Raphael Coeffic authored on 19/11/2013 12:27:38
Showing 4 changed files
... ...
@@ -591,6 +591,82 @@ const dns_handle& dns_handle::operator = (const dns_handle& rh)
591 591
     return *this;
592 592
 }
593 593
 
594
+sip_target::sip_target() {}
595
+
596
+sip_target::sip_target(const sip_target& target)
597
+{
598
+    *this = target;
599
+}
600
+
601
+const sip_target& sip_target::operator = (const sip_target& target)
602
+{
603
+    memcpy(&ss,&target.ss,sizeof(sockaddr_storage));
604
+    memcpy(trsp,target.trsp,SIP_TRSP_SIZE_MAX+1);
605
+    return target;
606
+}
607
+
608
+void sip_target::clear()
609
+{
610
+    memset(&ss,0,sizeof(sockaddr_storage));
611
+    memset(trsp,'\0',SIP_TRSP_SIZE_MAX+1);
612
+}
613
+
614
+sip_target_set::sip_target_set()
615
+    : dest_list(),
616
+      dest_list_it(dest_list.begin())
617
+{}
618
+
619
+void sip_target_set::reset_iterator()
620
+{
621
+    dest_list_it = dest_list.begin();
622
+}
623
+
624
+bool sip_target_set::has_next()
625
+{
626
+    return dest_list_it != dest_list.end();
627
+}
628
+
629
+int sip_target_set::get_next(sockaddr_storage* ss, cstring& next_trsp,
630
+			     unsigned int flags)
631
+{
632
+    do {
633
+	if(!has_next())
634
+	    return -1;
635
+
636
+	sip_target& t = *dest_list_it;
637
+	memcpy(ss,&t.ss,sizeof(sockaddr_storage));
638
+	next_trsp = cstring(t.trsp);
639
+
640
+	next();
641
+
642
+	// set default transport to UDP
643
+	if(!next_trsp.len)
644
+	    next_trsp = cstring("udp");
645
+
646
+    } while(!(flags & TR_FLAG_DISABLE_BL) &&
647
+	    tr_blacklist::instance()->exist(ss));
648
+
649
+    return 0;
650
+}
651
+
652
+bool sip_target_set::next()
653
+{
654
+    dest_list_it++;
655
+    return has_next();
656
+}
657
+
658
+void sip_target_set::debug()
659
+{
660
+    DBG("target list:");
661
+
662
+    for(list<sip_target>::iterator it = dest_list.begin();
663
+	it != dest_list.end(); it++) {
664
+
665
+	DBG("\t%s:%u/%s to target list",
666
+	    am_inet_ntop(&it->ss).c_str(),
667
+	    am_get_port(&it->ss),it->trsp);
668
+    }
669
+}
594 670
 
595 671
 _resolver::_resolver()
596 672
     : cache(DNS_CACHE_SIZE)
... ...
@@ -168,6 +168,39 @@ private:
168 168
     int            ip_n;
169 169
 };
170 170
 
171
+#define SIP_TRSP_SIZE_MAX 4
172
+
173
+struct sip_target
174
+{
175
+    sockaddr_storage ss;
176
+    char             trsp[SIP_TRSP_SIZE_MAX+1];
177
+
178
+    sip_target();
179
+    sip_target(const sip_target& target);
180
+
181
+    void clear();
182
+    const sip_target& operator = (const sip_target& target);
183
+};
184
+
185
+struct sip_target_set
186
+{
187
+    list<sip_target>           dest_list;
188
+    list<sip_target>::iterator dest_list_it;
189
+
190
+    sip_target_set();
191
+
192
+    void reset_iterator();
193
+    bool has_next();
194
+    int  get_next(sockaddr_storage* ss, cstring& next_trsp,
195
+		  unsigned int flags);
196
+    bool next();
197
+
198
+    void debug();
199
+
200
+private:
201
+    sip_target_set(const sip_target_set&) {}
202
+};
203
+
171 204
 class _resolver
172 205
     : AmThread
173 206
 {
... ...
@@ -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];