blob: 670338428f15b6d3e551501ab7aa805b0c620bcb [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file sip/contact.c SIP contact functions
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6#include <string.h>
7#include <re_types.h>
8#include <re_fmt.h>
9#include <re_mbuf.h>
10#include <re_uri.h>
11#include <re_list.h>
12#include <re_sa.h>
13#include <re_msg.h>
14#include <re_sip.h>
15
16
17/**
18 * Set contact parameters
19 *
20 * @param contact SIP Contact object
21 * @param uri Username or URI
22 * @param addr IP-address and port
23 * @param tp SIP Transport
24 */
25void sip_contact_set(struct sip_contact *contact, const char *uri,
26 const struct sa *addr, enum sip_transp tp)
27{
28 if (!contact)
29 return;
30
31 contact->uri = uri;
32 contact->addr = addr;
33 contact->tp = tp;
34}
35
36
37/**
38 * Print contact header
39 *
40 * @param pf Print function
41 * @param contact SIP Contact object
42 *
43 * @return 0 for success, otherwise errorcode
44 */
45int sip_contact_print(struct re_printf *pf, const struct sip_contact *contact)
46{
47 if (!contact)
48 return 0;
49
50 if (contact->uri && strchr(contact->uri, ':'))
51 return re_hprintf(pf, "Contact: <%s>\r\n", contact->uri);
52 else
53 return re_hprintf(pf, "Contact: <sip:%s@%J%s>\r\n",
54 contact->uri,
55 contact->addr,
56 sip_transp_param(contact->tp));
57}