pua_bla: clang-format
[kamailio] / src / modules / pua_bla / registrar_cb.c
1 /*
2  * pua_bla module - pua Bridged Line Appearance
3  *
4  * Copyright (C) 2007 Voice Sistem S.R.L.
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * Kamailio is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include "../../core/dprint.h"
27 #include "../pua/pua.h"
28 #include "registrar_cb.h"
29 #include "pua_bla.h"
30
31
32 void bla_cb(ucontact_t *c, int type, void *param)
33 {
34         subs_info_t subs;
35         str uri = STR_NULL;
36         char *at;
37         LM_DBG("start\n");
38         if(is_bla_aor == 0) {
39                 LM_DBG("Not a recognized BLA AOR\n");
40                 return;
41         }
42
43         if(type & UL_CONTACT_INSERT)
44                 LM_DBG("type= UL_CONTACT_INSERT\n");
45         else if(type & UL_CONTACT_UPDATE)
46                 LM_DBG("type= UL_CONTACT_UPDATE\n");
47         else if(type & UL_CONTACT_EXPIRE)
48                 LM_DBG("type= UL_CONTACT_EXPIRE\n");
49         else if(type & UL_CONTACT_DELETE)
50                 LM_DBG("type= UL_CONTACT_DELETE\n");
51
52         memset(&subs, 0, sizeof(subs_info_t));
53         subs.remote_target = &c->c;
54
55         subs.pres_uri = &reg_from_uri;
56
57         uri.s = (char *)pkg_malloc(
58                         sizeof(char) * (c->aor->len + default_domain.len + 6));
59         if(uri.s == NULL) {
60                 PKG_MEM_ERROR;
61                 goto error;
62         }
63
64         memcpy(uri.s, "sip:", 4);
65         uri.len = 4;
66
67         memcpy(uri.s + uri.len, c->aor->s, c->aor->len);
68         uri.len += c->aor->len;
69         at = memchr(c->aor->s, '@', c->aor->len);
70         if(!at) {
71                 uri.s[uri.len++] = '@';
72                 memcpy(uri.s + uri.len, default_domain.s, default_domain.len);
73                 uri.len += default_domain.len;
74         }
75
76         subs.watcher_uri = &uri;
77         if(type & UL_CONTACT_DELETE || type & UL_CONTACT_EXPIRE)
78                 subs.expires = 0;
79         else
80                 subs.expires = c->expires - (int)time(NULL);
81
82
83         subs.source_flag = BLA_SUBSCRIBE;
84         subs.event = BLA_EVENT;
85         subs.contact = &server_address;
86
87         if(bla_outbound_proxy.s && bla_outbound_proxy.len)
88                 subs.outbound_proxy = &bla_outbound_proxy;
89         else if(c->received.s && c->received.len)
90                 subs.outbound_proxy = &c->received;
91
92         if(type & UL_CONTACT_INSERT)
93                 subs.flag |= INSERT_TYPE;
94         else
95                 subs.flag |= UPDATE_TYPE;
96
97         if(pua_send_subscribe(&subs) < 0) {
98                 LM_ERR("while sending subscribe\n");
99         }
100         pkg_free(uri.s);
101 error:
102         is_bla_aor = 0;
103         return;
104 }