@@ -22,7 +22,6 @@ struct sip_dialog_t* sip_dialog_create(void)
2222 if (dialog )
2323 {
2424 dialog -> ref = 1 ;
25- LIST_INIT_HEAD (& dialog -> link );
2625 dialog -> state = DIALOG_ERALY ;
2726 dialog -> ptr = (char * )(dialog + 1 );
2827 atomic_increment32 (& s_gc .dialog );
@@ -118,9 +117,6 @@ int sip_dialog_release(struct sip_dialog_t* dialog)
118117 if (0 != atomic_decrement32 (& dialog -> ref ))
119118 return 0 ;
120119
121- if (dialog -> ondestroy )
122- dialog -> ondestroy (dialog -> ondestroyparam );
123-
124120 sip_uri_free (& dialog -> local .target );
125121 sip_contact_free (& dialog -> local .uri );
126122 sip_uri_free (& dialog -> remote .target );
@@ -139,13 +135,6 @@ int sip_dialog_addref(struct sip_dialog_t* dialog)
139135 return r ;
140136}
141137
142- int sip_dialog_ondestroy (struct sip_dialog_t * dialog , void (* ondestroy )(void * param ), void * param )
143- {
144- dialog -> ondestroy = ondestroy ;
145- dialog -> ondestroyparam = param ;
146- return 0 ;
147- }
148-
149138int sip_dialog_setlocaltag (struct sip_dialog_t * dialog , const struct cstring_t * tag )
150139{
151140 const char * end ;
@@ -194,136 +183,24 @@ static int sip_dialog_match(const struct sip_dialog_t* dialog, const struct cstr
194183 return cstreq (callid , & dialog -> callid ) && cstreq (local , & dialog -> local .uri .tag ) && cstreq (remote , & dialog -> remote .uri .tag ) ? 1 : 0 ;
195184}
196185
197- static struct sip_dialog_t * sip_dialog_find (struct sip_agent_t * sip , const struct cstring_t * callid , const struct cstring_t * local , const struct cstring_t * remote )
198- {
199- struct list_head * pos , * next ;
200- struct sip_dialog_t * dialog ;
201-
202- list_for_each_safe (pos , next , & sip -> dialogs )
203- {
204- dialog = list_entry (pos , struct sip_dialog_t , link );
205- if (sip_dialog_match (dialog , callid , local , remote ))
206- return dialog ;
207- }
208-
209- return NULL ;
210- }
211-
212- struct sip_dialog_t * sip_dialog_fetch (struct sip_agent_t * sip , const struct cstring_t * callid , const struct cstring_t * local , const struct cstring_t * remote )
213- {
214- struct sip_dialog_t * dialog ;
215- locker_lock (& sip -> locker );
216- dialog = sip_dialog_find (sip , callid , local , remote );
217- if (dialog )
218- sip_dialog_addref (dialog );
219- locker_unlock (& sip -> locker );
220- return dialog ;
221- }
222-
223- int sip_dialog_add (struct sip_agent_t * sip , struct sip_dialog_t * dialog )
224- {
225- locker_lock (& sip -> locker );
226- if (NULL != sip_dialog_find (sip , & dialog -> callid , & dialog -> local .uri .tag , & dialog -> remote .uri .tag ))
227- {
228- assert (0 );
229- locker_unlock (& sip -> locker );
230- return -1 ; // exist
231- }
232-
233- // link to tail
234- assert (1 == dialog -> ref );
235- list_insert_after (& dialog -> link , sip -> dialogs .prev );
236- locker_unlock (& sip -> locker );
237- sip_dialog_addref (dialog );
238- return 0 ;
239- }
240-
241- int sip_dialog_remove (struct sip_agent_t * sip , struct sip_dialog_t * dialog )
186+ int sip_dialog_id (struct cstring_t * id , const struct sip_dialog_t * dialog , char * ptr , int len )
242187{
243- // unlink dialog
244- locker_lock (& sip -> locker );
245- //assert(1 == dialog->ref);
246- if (dialog -> link .next == NULL )
247- {
248- // fix remove twice
249- locker_unlock (& sip -> locker );
250- return -1 ;
251- }
252-
253- list_remove (& dialog -> link );
254- locker_unlock (& sip -> locker );
255- sip_dialog_release (dialog );
256- return 0 ;
257- }
258-
259- int sip_dialog_remove2 (struct sip_agent_t * sip , const struct cstring_t * callid , const struct cstring_t * local , const struct cstring_t * remote )
260- {
261- struct sip_dialog_t * dialog ;
262- locker_lock (& sip -> locker );
263- dialog = sip_dialog_find (sip , callid , local , remote );
264- if (dialog && dialog -> link .next )
265- list_remove (& dialog -> link );
266- locker_unlock (& sip -> locker );
267-
268- if (dialog )
269- {
270- sip_dialog_release (dialog );
271- return 0 ;
272- }
273- return -1 ; // not found
274- }
275-
276- int sip_dialog_remove_early (struct sip_agent_t * sip , const struct cstring_t * callid )
277- {
278- struct sip_dialog_t * early ;
279- struct sip_dialog_t * dialog ;
280- struct list_head * pos , * next ;
281-
282- early = NULL ;
283- locker_lock (& sip -> locker );
284- list_for_each_safe (pos , next , & sip -> dialogs )
285- {
286- dialog = list_entry (pos , struct sip_dialog_t , link );
287- if (cstreq (callid , & dialog -> callid ) && DIALOG_ERALY == dialog -> state )
288- {
289- //assert(0 == sip_contact_compare(&t->req->from, &dialog->local.uri));
290- list_remove (& dialog -> link );
291- early = dialog ;
292- break ;
293- }
294- }
295-
296- locker_unlock (& sip -> locker );
297- if (early )
298- {
299- sip_dialog_release (early );
300- return 0 ;
301- }
302- return -1 ; // not found
188+ int r ;
189+ r = dialog ? snprintf (ptr , len , "%.*s@%.*s@%.*s" , (int )dialog -> callid .n , dialog -> callid .p , (int )dialog -> local .uri .tag .n , dialog -> local .uri .tag .p , (int )dialog -> remote .uri .tag .n , dialog -> remote .uri .tag .p ) : 0 ;
190+ id -> p = ptr ;
191+ id -> n = r > 0 && r < sizeof (id ) ? r : 0 ;
192+ return r ;
303193}
304194
305- // MUST ADD LOCK !!!!! internal use only !!!!!!!!!
306- struct sip_dialog_t * sip_dialog_internal_fetch (struct sip_agent_t * sip , const struct sip_message_t * msg , int uac , int * added )
195+ int sip_dialog_id_with_message (struct cstring_t * id , const struct sip_message_t * msg , char * ptr , int len )
307196{
308- struct sip_dialog_t * dialog ;
309-
310- * added = 0 ;
311- dialog = sip_dialog_find (sip , & msg -> callid , uac ? & msg -> from .tag : & msg -> to .tag , uac ? & msg -> to .tag : & msg -> from .tag );
312- if (!dialog )
313- {
314- dialog = sip_dialog_create ();
315- if (!dialog || 0 != (uac ? sip_dialog_init_uac (dialog , msg ) : sip_dialog_init_uas (dialog , msg )))
316- {
317- sip_dialog_release (dialog );
318- return NULL ;
319- }
320-
321- // link to sip dialogs(add ref later)
322- list_insert_after (& dialog -> link , sip -> dialogs .prev );
323- assert (dialog -> ref == 1 );
324- * added = 1 ;
325- }
326-
327- sip_dialog_addref (dialog ); // for sip link dialog / fetch
328- return dialog ;
197+ int r ;
198+ if (msg -> mode == SIP_MESSAGE_REQUEST )
199+ r = snprintf (ptr , len , "%.*s@%.*s@%.*s" , (int )msg -> callid .n , msg -> callid .p , (int )msg -> to .tag .n , msg -> to .tag .p , (int )msg -> from .tag .n , msg -> from .tag .p );
200+ else
201+ r = snprintf (ptr , len , "%.*s@%.*s@%.*s" , (int )msg -> callid .n , msg -> callid .p , (int )msg -> from .tag .n , msg -> from .tag .p , (int )msg -> to .tag .n , msg -> to .tag .p );
202+
203+ id -> p = ptr ;
204+ id -> n = r > 0 && r < sizeof (id ) ? r : 0 ;
205+ return r ;
329206}
0 commit comments