osip_contact.c
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <osipparser2/internal.h>
#include <osipparser2/osip_port.h>
#include <osipparser2/osip_message.h>
#include <osipparser2/osip_parser.h>
/* adds the contact header to message. */
/* INPUT : const char *hvalue | value of header. */
/* OUTPUT: osip_message_t *sip | structure to save results. */
/* returns -1 on error. */
int osip_message_set_contact(osip_message_t *sip, const char *hvalue) {
int i;
osip_contact_t *contact;
if (hvalue == NULL || hvalue[0] == '\0')
return OSIP_SUCCESS;
i = osip_contact_init(&contact);
if (i != 0)
return i;
i = osip_contact_parse(contact, hvalue);
if (i != 0) {
osip_contact_free(contact);
return i;
}
sip->message_property = 2;
osip_list_add(&sip->contacts, contact, -1);
return OSIP_SUCCESS; /* ok */
}
/* parses a contact header. */
/* INPUT : const char *string | pointer to a contact string.*/
/* OUTPUT: osip_contact_t *contact | structure to save results. */
/* returns -1 on error. */
int osip_contact_parse(osip_contact_t *contact, const char *hvalue) {
if (contact == NULL)
return OSIP_BADPARAMETER;
if (strncmp(hvalue, "*", 1) == 0) {
contact->displayname = osip_strdup(hvalue);
if (contact->displayname == NULL) {
return OSIP_NOMEM;
}
return OSIP_SUCCESS;
}
return osip_from_parse((osip_from_t *) contact, hvalue);
}
#ifndef MINISIZE
int osip_contact_init(osip_contact_t **contact) {
return osip_from_init((osip_from_t **) contact);
}
#endif
#ifndef MINISIZE
/* returns the pos of contact header. */
/* INPUT : int pos | pos of contact header. */
/* INPUT : osip_message_t *sip | sip message. */
/* OUTPUT: osip_contact_t *contact | structure to save results. */
/* returns -1 on error. */
int osip_message_get_contact(const osip_message_t *sip, int pos, osip_contact_t **dest) {
*dest = NULL;
if (sip == NULL)
return OSIP_BADPARAMETER;
if (osip_list_size(&sip->contacts) <= pos)
return OSIP_UNDEFINED_ERROR; /* does not exist */
*dest = (osip_contact_t *) osip_list_get(&sip->contacts, pos);
return pos;
}
#endif
/* returns the contact header as a string.*/
/* INPUT : osip_contact_t *contact | contact. */
/* returns null on error. */
int osip_contact_to_str(const osip_contact_t *contact, char **dest) {
if (contact == NULL)
return OSIP_BADPARAMETER;
if (contact->displayname != NULL) {
if (strncmp(contact->displayname, "*", 1) == 0) {
*dest = osip_strdup("*");
if (*dest == NULL)
return OSIP_NOMEM;
return OSIP_SUCCESS;
}
}
return osip_from_to_str((osip_from_t *) contact, dest);
}
#ifndef MINISIZE
/* deallocates a osip_contact_t structure. */
/* INPUT : osip_contact_t *| contact. */
void osip_contact_free(osip_contact_t *contact) {
osip_from_free((osip_from_t *) contact);
}
int osip_contact_clone(const osip_contact_t *contact, osip_contact_t **dest) {
return osip_from_clone((osip_from_t *) contact, (osip_from_t **) dest);
}
#endif