Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / libosip2 / src / osipparser2 / osip_message.c
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3   Copyright (C) 2001,2002,2003  Aymeric MOIZARD jack@atosc.org
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14   
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include <osipparser2/osip_port.h>
25 #include <osipparser2/osip_message.h>
26
27 /* enable logging of memory accesses */
28 #ifdef MEMORY_LEAKS
29 static int freesipcptr = 0;
30 #endif
31
32 const char *osip_protocol_version = "SIP/2.0";
33
34
35 int
36 osip_message_init (osip_message_t ** sip)
37 {
38 #ifdef MEMORY_LEAKS
39   static int comptr = 0;
40
41   comptr++;
42   freesipcptr++;
43 #endif
44   *sip = (osip_message_t *) osip_malloc (sizeof (osip_message_t));
45 #ifdef MEMORY_LEAKS
46   osip_trace (__FILE__, __LINE__, TRACE_LEVEL0, stdout,
47               "<msg_write.c> osip_message_init() = %i, malloc-free = %i, address = %x\n",
48               comptr, freesipcptr, *sip);
49   fflush (stdout);
50 #endif
51
52   (*sip)->sip_method = NULL;
53   (*sip)->sip_version = NULL;
54   (*sip)->status_code = 0;
55   (*sip)->reason_phrase = NULL;
56   (*sip)->req_uri = NULL;
57
58   (*sip)->accepts = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
59   osip_list_init ((*sip)->accepts);
60   (*sip)->accept_encodings =
61     (osip_list_t *) osip_malloc (sizeof (osip_list_t));
62   osip_list_init ((*sip)->accept_encodings);
63   (*sip)->accept_languages =
64     (osip_list_t *) osip_malloc (sizeof (osip_list_t));
65
66   osip_list_init ((*sip)->accept_languages);
67   (*sip)->alert_infos = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
68   osip_list_init ((*sip)->alert_infos);
69   (*sip)->allows = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
70   osip_list_init ((*sip)->allows);
71   (*sip)->authorizations = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
72   osip_list_init ((*sip)->authorizations);
73   (*sip)->call_id = NULL;
74   (*sip)->call_infos = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
75   osip_list_init ((*sip)->call_infos);
76   (*sip)->contacts = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
77   osip_list_init ((*sip)->contacts);
78
79   /* forget it: this field is not suported */
80   (*sip)->content_dispositions = NULL;
81
82   (*sip)->content_encodings =
83     (osip_list_t *) osip_malloc (sizeof (osip_list_t));
84   osip_list_init ((*sip)->content_encodings);
85   (*sip)->content_length = NULL;
86   (*sip)->content_type = NULL;
87   (*sip)->cseq = NULL;
88   (*sip)->error_infos = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
89   osip_list_init ((*sip)->error_infos);
90   (*sip)->from = NULL;
91   (*sip)->mime_version = NULL;
92   (*sip)->proxy_authenticates =
93     (osip_list_t *) osip_malloc (sizeof (osip_list_t));
94   osip_list_init ((*sip)->proxy_authenticates);
95   (*sip)->proxy_authorizations =
96     (osip_list_t *) osip_malloc (sizeof (osip_list_t));
97   osip_list_init ((*sip)->proxy_authorizations);
98   (*sip)->record_routes = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
99   osip_list_init ((*sip)->record_routes);
100   (*sip)->routes = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
101   osip_list_init ((*sip)->routes);
102   (*sip)->to = NULL;
103   (*sip)->vias = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
104   osip_list_init ((*sip)->vias);
105   (*sip)->www_authenticates =
106     (osip_list_t *) osip_malloc (sizeof (osip_list_t));
107   osip_list_init ((*sip)->www_authenticates);
108
109   (*sip)->bodies = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
110   osip_list_init ((*sip)->bodies);
111
112   (*sip)->headers = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
113   osip_list_init ((*sip)->headers);
114
115   (*sip)->message_property = 3;
116   (*sip)->message = NULL;       /* buffer to avoid calling osip_message_to_str many times (for retransmission) */
117   return 0;                     /* ok */
118 }
119
120
121 void
122 osip_message_set_reason_phrase (osip_message_t * sip, char *reason)
123 {
124   sip->reason_phrase = reason;
125 }
126
127 void
128 osip_message_set_status_code (osip_message_t * sip, int status_code)
129 {
130   sip->status_code = status_code;
131 }
132
133 void
134 osip_message_set_method (osip_message_t * sip, char *sip_method)
135 {
136   sip->sip_method = sip_method;
137 }
138
139 void
140 osip_message_set_version (osip_message_t * sip, char *sip_version)
141 {
142   sip->sip_version = sip_version;
143 }
144
145 void
146 osip_message_set_uri (osip_message_t * sip, osip_uri_t * url)
147 {
148   sip->req_uri = url;
149 }
150
151 void
152 osip_message_free (osip_message_t * sip)
153 {
154   int pos = 0;
155
156 #ifdef MEMORY_LEAKS
157   static int comptr = 0;
158
159   if (sip == NULL)
160     return;
161   comptr--;
162   freesipcptr--;
163   osip_trace (__FILE__, __LINE__, TRACE_LEVEL0, stdout,
164               "<msg_write.c> osip_message_free() = %i, malloc-free = %i, address = %x\n",
165               comptr, freesipcptr, sip);
166 #endif
167   if (sip == NULL)
168     return;
169
170   osip_free (sip->sip_method);
171   osip_free (sip->sip_version);
172   if (sip->req_uri != NULL)
173     {
174       osip_uri_free (sip->req_uri);
175     }
176   osip_free (sip->reason_phrase);
177
178   {
179     osip_accept_t *accept;
180
181     while (!osip_list_eol (sip->accepts, pos))
182       {
183         accept = (osip_accept_t *) osip_list_get (sip->accepts, pos);
184         osip_list_remove (sip->accepts, pos);
185         osip_accept_free (accept);
186       }
187     osip_free (sip->accepts);
188   }
189   {
190     osip_accept_encoding_t *accept_encoding;
191
192     while (!osip_list_eol (sip->accept_encodings, pos))
193       {
194         accept_encoding =
195           (osip_accept_encoding_t *) osip_list_get (sip->accept_encodings,
196                                                     pos);
197         osip_list_remove (sip->accept_encodings, pos);
198         osip_accept_encoding_free (accept_encoding);
199       }
200     osip_free (sip->accept_encodings);
201   }
202   {
203     osip_accept_language_t *accept_language;
204
205     while (!osip_list_eol (sip->accept_languages, pos))
206       {
207         accept_language =
208           (osip_accept_language_t *) osip_list_get (sip->accept_languages,
209                                                     pos);
210         osip_list_remove (sip->accept_languages, pos);
211         osip_accept_language_free (accept_language);
212       }
213     osip_free (sip->accept_languages);
214   }
215   {
216     osip_alert_info_t *alert_info;
217
218     while (!osip_list_eol (sip->alert_infos, pos))
219       {
220         alert_info =
221           (osip_alert_info_t *) osip_list_get (sip->alert_infos, pos);
222         osip_list_remove (sip->alert_infos, pos);
223         osip_alert_info_free (alert_info);
224       }
225     osip_free (sip->alert_infos);
226   }
227   {
228     osip_allow_t *al;
229
230     while (!osip_list_eol (sip->allows, pos))
231       {
232         al = (osip_allow_t *) osip_list_get (sip->allows, pos);
233         osip_list_remove (sip->allows, pos);
234         osip_allow_free (al);
235       }
236     osip_free (sip->allows);
237   }
238   {
239     osip_authorization_t *al;
240
241     while (!osip_list_eol (sip->authorizations, pos))
242       {
243         al =
244           (osip_authorization_t *) osip_list_get (sip->authorizations, pos);
245         osip_list_remove (sip->authorizations, pos);
246         osip_authorization_free (al);
247       }
248     osip_free (sip->authorizations);
249   }
250   if (sip->call_id != NULL)
251     {
252       osip_call_id_free (sip->call_id);
253     }
254   {
255     osip_call_info_t *call_info;
256
257     while (!osip_list_eol (sip->call_infos, pos))
258       {
259         call_info = (osip_call_info_t *) osip_list_get (sip->call_infos, pos);
260         osip_list_remove (sip->call_infos, pos);
261         osip_call_info_free (call_info);
262       }
263     osip_free (sip->call_infos);
264   }
265   {
266     osip_contact_t *contact;
267
268     while (!osip_list_eol (sip->contacts, pos))
269       {
270         contact = (osip_contact_t *) osip_list_get (sip->contacts, pos);
271         osip_list_remove (sip->contacts, pos);
272         osip_contact_free (contact);
273       }
274     osip_free (sip->contacts);
275   }
276   {
277     osip_content_encoding_t *ce;
278
279     while (!osip_list_eol (sip->content_encodings, pos))
280       {
281         ce =
282           (osip_content_encoding_t *) osip_list_get (sip->content_encodings,
283                                                      pos);
284         osip_list_remove (sip->content_encodings, pos);
285         osip_content_encoding_free (ce);
286       }
287     osip_free (sip->content_encodings);
288   }
289   if (sip->content_length != NULL)
290     {
291       osip_content_length_free (sip->content_length);
292     }
293   if (sip->content_type != NULL)
294     {
295       osip_content_type_free (sip->content_type);
296     }
297   if (sip->cseq != NULL)
298     {
299       osip_cseq_free (sip->cseq);
300     }
301   {
302     osip_error_info_t *error_info;
303
304     while (!osip_list_eol (sip->error_infos, pos))
305       {
306         error_info =
307           (osip_error_info_t *) osip_list_get (sip->error_infos, pos);
308         osip_list_remove (sip->error_infos, pos);
309         osip_error_info_free (error_info);
310       }
311     osip_free (sip->error_infos);
312   }
313   if (sip->from != NULL)
314     {
315       osip_from_free (sip->from);
316     }
317   if (sip->mime_version != NULL)
318     {
319       osip_mime_version_free (sip->mime_version);
320     }
321   {
322     osip_proxy_authenticate_t *al;
323
324     while (!osip_list_eol (sip->proxy_authenticates, pos))
325       {
326         al =
327           (osip_proxy_authenticate_t *) osip_list_get (sip->
328                                                        proxy_authenticates,
329                                                        pos);
330         osip_list_remove (sip->proxy_authenticates, pos);
331         osip_proxy_authenticate_free (al);
332       }
333     osip_free (sip->proxy_authenticates);
334   }
335   {
336     osip_proxy_authorization_t *proxy_authorization;
337
338     while (!osip_list_eol (sip->proxy_authorizations, pos))
339       {
340         proxy_authorization =
341           (osip_proxy_authorization_t *) osip_list_get (sip->
342                                                         proxy_authorizations,
343                                                         pos);
344         osip_list_remove (sip->proxy_authorizations, pos);
345         osip_proxy_authorization_free (proxy_authorization);
346       }
347     osip_free (sip->proxy_authorizations);
348   }
349   {
350     osip_record_route_t *record_route;
351
352     while (!osip_list_eol (sip->record_routes, pos))
353       {
354         record_route =
355           (osip_record_route_t *) osip_list_get (sip->record_routes, pos);
356         osip_list_remove (sip->record_routes, pos);
357         osip_record_route_free (record_route);
358       }
359     osip_free (sip->record_routes);
360   }
361   {
362     osip_route_t *route;
363
364     while (!osip_list_eol (sip->routes, pos))
365       {
366         route = (osip_route_t *) osip_list_get (sip->routes, pos);
367         osip_list_remove (sip->routes, pos);
368         osip_route_free (route);
369       }
370     osip_free (sip->routes);
371   }
372   if (sip->to != NULL)
373     {
374       osip_to_free (sip->to);
375     }
376   {
377     osip_via_t *via;
378
379     while (!osip_list_eol (sip->vias, pos))
380       {
381         via = (osip_via_t *) osip_list_get (sip->vias, pos);
382         osip_list_remove (sip->vias, pos);
383         osip_via_free (via);
384       }
385     osip_free (sip->vias);
386   }
387   {
388     osip_www_authenticate_t *al;
389
390     while (!osip_list_eol (sip->www_authenticates, pos))
391       {
392         al =
393           (osip_www_authenticate_t *) osip_list_get (sip->www_authenticates,
394                                                      pos);
395         osip_list_remove (sip->www_authenticates, pos);
396         osip_www_authenticate_free (al);
397       }
398     osip_free (sip->www_authenticates);
399   }
400
401   {
402     osip_header_t *header;
403
404     while (!osip_list_eol (sip->headers, pos))
405       {
406         header = (osip_header_t *) osip_list_get (sip->headers, pos);
407         osip_list_remove (sip->headers, pos);
408         osip_header_free (header);
409       }
410     osip_free (sip->headers);
411   }
412
413   {
414     osip_body_t *body;
415
416     while (!osip_list_eol (sip->bodies, pos))
417       {
418         body = (osip_body_t *) osip_list_get (sip->bodies, pos);
419         osip_list_remove (sip->bodies, pos);
420         osip_body_free (body);
421       }
422     osip_free (sip->bodies);
423   }
424   osip_free (sip->message);
425   osip_free (sip);
426 }
427
428
429 int
430 osip_message_clone (const osip_message_t * sip, osip_message_t ** dest)
431 {
432   osip_message_t *copy;
433   int pos = 0;
434   int i;
435
436   if (sip == NULL)
437     return -1;
438   *dest = NULL;
439
440   i = osip_message_init (&copy);
441   if (i != 0)
442     return -1;
443
444   copy->sip_method = osip_strdup (sip->sip_method);
445   copy->sip_version = osip_strdup (sip->sip_version);
446   copy->status_code = sip->status_code;
447   copy->reason_phrase = osip_strdup (sip->reason_phrase);
448   if (sip->req_uri != NULL)
449     {
450       i = osip_uri_clone (sip->req_uri, &(copy->req_uri));
451       if (i != 0)
452         goto mc_error1;
453     }
454
455   {
456     osip_accept_t *accept;
457     osip_accept_t *accept2;
458
459     pos = 0;
460     while (!osip_list_eol (sip->accepts, pos))
461       {
462         accept = (osip_accept_t *) osip_list_get (sip->accepts, pos);
463         i = osip_accept_clone (accept, &accept2);
464         if (i != 0)
465           goto mc_error1;
466         osip_list_add (copy->accepts, accept2, -1);     /* insert as last element */
467         pos++;
468       }
469   }
470   {
471     osip_accept_encoding_t *accept_encoding;
472     osip_accept_encoding_t *accept_encoding2;
473
474     pos = 0;
475     while (!osip_list_eol (sip->accept_encodings, pos))
476       {
477         accept_encoding =
478           (osip_accept_encoding_t *) osip_list_get (sip->accept_encodings,
479                                                     pos);
480         i = osip_accept_encoding_clone (accept_encoding, &accept_encoding2);
481         if (i != 0)
482           goto mc_error1;
483         osip_list_add (copy->accept_encodings, accept_encoding2, -1);
484         pos++;
485       }
486   }
487   {
488     osip_accept_language_t *accept_language;
489     osip_accept_language_t *accept_language2;
490
491     pos = 0;
492     while (!osip_list_eol (sip->accept_languages, pos))
493       {
494         accept_language =
495           (osip_accept_language_t *) osip_list_get (sip->accept_languages,
496                                                     pos);
497         i = osip_accept_language_clone (accept_language, &accept_language2);
498         if (i != 0)
499           goto mc_error1;
500         osip_list_add (copy->accept_languages, accept_language2, -1);
501         pos++;
502       }
503   }
504   {
505     osip_alert_info_t *alert_info;
506     osip_alert_info_t *alert_info2;
507
508     pos = 0;
509     while (!osip_list_eol (sip->alert_infos, pos))
510       {
511         alert_info =
512           (osip_alert_info_t *) osip_list_get (sip->alert_infos, pos);
513         i = osip_alert_info_clone (alert_info, &alert_info2);
514         if (i != 0)
515           goto mc_error1;
516         osip_list_add (copy->alert_infos, alert_info2, -1);
517         pos++;
518       }
519   }
520   {
521     osip_allow_t *allow;
522     osip_allow_t *allow2;
523
524     pos = 0;
525     while (!osip_list_eol (sip->allows, pos))
526       {
527         allow = (osip_allow_t *) osip_list_get (sip->allows, pos);
528         i = osip_allow_clone (allow, &allow2);
529         if (i != 0)
530           goto mc_error1;
531         osip_list_add (copy->allows, allow2, -1);
532         pos++;
533       }
534   }
535   {
536     osip_authorization_t *authorization;
537     osip_authorization_t *authorization2;
538
539     pos = 0;
540     while (!osip_list_eol (sip->authorizations, pos))
541       {
542         authorization =
543           (osip_authorization_t *) osip_list_get (sip->authorizations, pos);
544         i = osip_authorization_clone (authorization, &authorization2);
545         if (i != 0)
546           goto mc_error1;
547         osip_list_add (copy->authorizations, authorization2, -1);
548         pos++;
549       }
550   }
551   if (sip->call_id != NULL)
552     {
553       i = osip_call_id_clone (sip->call_id, &(copy->call_id));
554       if (i != 0)
555         goto mc_error1;
556     }
557   {
558     osip_call_info_t *call_info;
559     osip_call_info_t *call_info2;
560
561     pos = 0;
562     while (!osip_list_eol (sip->call_infos, pos))
563       {
564         call_info = (osip_call_info_t *) osip_list_get (sip->call_infos, pos);
565         i = osip_call_info_clone (call_info, &call_info2);
566         if (i != 0)
567           goto mc_error1;
568         osip_list_add (copy->call_infos, call_info2, -1);
569         pos++;
570       }
571   }
572   {
573     osip_contact_t *contact;
574     osip_contact_t *contact2;
575
576     pos = 0;
577     while (!osip_list_eol (sip->contacts, pos))
578       {
579         contact = (osip_contact_t *) osip_list_get (sip->contacts, pos);
580         i = osip_contact_clone (contact, &contact2);
581         if (i != 0)
582           goto mc_error1;
583         osip_list_add (copy->contacts, contact2, -1);
584         pos++;
585       }
586   }
587   {
588     osip_content_encoding_t *content_encoding;
589     osip_content_encoding_t *content_encoding2;
590
591     pos = 0;
592     while (!osip_list_eol (sip->content_encodings, pos))
593       {
594         content_encoding =
595           (osip_content_encoding_t *) osip_list_get (sip->content_encodings,
596                                                      pos);
597         i =
598           osip_content_encoding_clone (content_encoding, &content_encoding2);
599         if (i != 0)
600           goto mc_error1;
601         osip_list_add (copy->content_encodings, content_encoding2, -1);
602         pos++;
603       }
604   }
605   if (sip->content_length != NULL)
606     {
607       i =
608         osip_content_length_clone (sip->content_length,
609                                    &(copy->content_length));
610       if (i != 0)
611         goto mc_error1;
612     }
613   if (sip->content_type != NULL)
614     {
615       i = osip_content_type_clone (sip->content_type, &(copy->content_type));
616       if (i != 0)
617         goto mc_error1;
618     }
619   if (sip->cseq != NULL)
620     {
621       i = osip_cseq_clone (sip->cseq, &(copy->cseq));
622       if (i != 0)
623         goto mc_error1;
624     }
625   {
626     osip_error_info_t *error_info;
627     osip_error_info_t *error_info2;
628
629     pos = 0;
630     while (!osip_list_eol (sip->error_infos, pos))
631       {
632         error_info =
633           (osip_error_info_t *) osip_list_get (sip->error_infos, pos);
634         i = osip_error_info_clone (error_info, &error_info2);
635         if (i != 0)
636           goto mc_error1;
637         osip_list_add (copy->error_infos, error_info2, -1);
638         pos++;
639       }
640   }
641   if (sip->from != NULL)
642     {
643       i = osip_from_clone (sip->from, &(copy->from));
644       if (i != 0)
645         goto mc_error1;
646     }
647   if (sip->mime_version != NULL)
648     {
649       i = osip_mime_version_clone (sip->mime_version, &(copy->mime_version));
650       if (i != 0)
651         goto mc_error1;
652     }
653   {
654     osip_proxy_authenticate_t *proxy_authenticate;
655     osip_proxy_authenticate_t *proxy_authenticate2;
656
657     pos = 0;
658     while (!osip_list_eol (sip->proxy_authenticates, pos))
659       {
660         proxy_authenticate =
661           (osip_proxy_authenticate_t *) osip_list_get (sip->
662                                                        proxy_authenticates,
663                                                        pos);
664         i =
665           osip_proxy_authenticate_clone (proxy_authenticate,
666                                          &proxy_authenticate2);
667         if (i != 0)
668           goto mc_error1;
669         osip_list_add (copy->proxy_authenticates, proxy_authenticate2, -1);
670         pos++;
671       }
672   }
673   {
674     osip_proxy_authorization_t *proxy_authorization;
675     osip_proxy_authorization_t *proxy_authorization2;
676
677     pos = 0;
678     while (!osip_list_eol (sip->proxy_authorizations, pos))
679       {
680         proxy_authorization =
681           (osip_proxy_authorization_t *) osip_list_get (sip->
682                                                         proxy_authorizations,
683                                                         pos);
684         i =
685           osip_proxy_authorization_clone (proxy_authorization,
686                                           &proxy_authorization2);
687         if (i != 0)
688           goto mc_error1;
689         osip_list_add (copy->proxy_authorizations, proxy_authorization2, -1);
690         pos++;
691       }
692   }
693   {
694     osip_record_route_t *record_route;
695     osip_record_route_t *record_route2;
696
697     pos = 0;
698     while (!osip_list_eol (sip->record_routes, pos))
699       {
700         record_route =
701           (osip_record_route_t *) osip_list_get (sip->record_routes, pos);
702         i = osip_record_route_clone (record_route, &record_route2);
703         if (i != 0)
704           goto mc_error1;
705         osip_list_add (copy->record_routes, record_route2, -1);
706         pos++;
707       }
708   }
709   {
710     osip_route_t *route;
711     osip_route_t *route2;
712
713     pos = 0;
714     while (!osip_list_eol (sip->routes, pos))
715       {
716         route = (osip_route_t *) osip_list_get (sip->routes, pos);
717         i = osip_route_clone (route, &route2);
718         if (i != 0)
719           goto mc_error1;
720         osip_list_add (copy->routes, route2, -1);
721         pos++;
722       }
723   }
724   if (sip->to != NULL)
725     {
726       i = osip_to_clone (sip->to, &(copy->to));
727       if (i != 0)
728         goto mc_error1;
729     }
730   {
731     osip_via_t *via;
732     osip_via_t *via2;
733
734     pos = 0;
735     while (!osip_list_eol (sip->vias, pos))
736       {
737         via = (osip_via_t *) osip_list_get (sip->vias, pos);
738         i = osip_via_clone (via, &via2);
739         if (i != 0)
740           goto mc_error1;
741         osip_list_add (copy->vias, via2, -1);
742         pos++;
743       }
744   }
745   {
746     osip_www_authenticate_t *www_authenticate;
747     osip_www_authenticate_t *www_authenticate2;
748
749     pos = 0;
750     while (!osip_list_eol (sip->www_authenticates, pos))
751       {
752         www_authenticate =
753           (osip_www_authenticate_t *) osip_list_get (sip->www_authenticates,
754                                                      pos);
755         i =
756           osip_www_authenticate_clone (www_authenticate, &www_authenticate2);
757         if (i != 0)
758           goto mc_error1;
759         osip_list_add (copy->www_authenticates, www_authenticate2, -1);
760         pos++;
761       }
762   }
763
764   {
765     osip_header_t *header;
766     osip_header_t *header2;
767
768     pos = 0;
769     while (!osip_list_eol (sip->headers, pos))
770       {
771         header = (osip_header_t *) osip_list_get (sip->headers, pos);
772         i = osip_header_clone (header, &header2);
773         if (i != 0)
774           goto mc_error1;
775         osip_list_add (copy->headers, header2, -1);
776         pos++;
777       }
778   }
779
780   {
781     osip_body_t *body;
782     osip_body_t *body2;
783
784     pos = 0;
785     while (!osip_list_eol (sip->bodies, pos))
786       {
787         body = (osip_body_t *) osip_list_get (sip->bodies, pos);
788         i = osip_body_clone (body, &body2);
789         if (i != 0)
790           goto mc_error1;
791         osip_list_add (copy->bodies, body2, -1);
792         pos++;
793       }
794   }
795
796   copy->message = osip_strdup (sip->message);
797   copy->message_property = sip->message_property;
798
799   *dest = copy;
800   return 0;
801 mc_error1:
802   osip_message_free (copy);
803   return -1;
804
805 }