Asterisk - The Open Source Telephony Project  18.5.0
sip_api.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012, Digium, Inc.
5  *
6  * Mark Michelson <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 #include "asterisk.h"
19 
20 #include "asterisk/sip_api.h"
21 #include "asterisk/logger.h"
22 
23 static const struct ast_sip_api_tech *api_provider;
24 
25 int ast_sipinfo_send(struct ast_channel *chan,
26  struct ast_variable *headers,
27  const char *content_type,
28  const char *content,
29  const char *useragent_filter)
30 {
31  if (!api_provider) {
32  ast_log(LOG_WARNING, "Unable to send custom SIP INFO. No API provider registered\n");
33  return -1;
34  }
35 
36  return api_provider->sipinfo_send(chan, headers, content_type, content, useragent_filter);
37 }
38 
40 {
41  if (api_provider) {
42  ast_log(LOG_WARNING, "SIP provider %s has already registered. Not registering provider %s\n",
43  api_provider->name, provider->name);
44  return -1;
45  }
46 
47  if (provider->version != AST_SIP_API_VERSION) {
48  ast_log(LOG_WARNING, "SIP API provider version mismatch: Current version is %d but provider "
49  "uses version %d\n", AST_SIP_API_VERSION, provider->version);
50  return -1;
51  }
52 
53  api_provider = provider;
54  return 0;
55 }
56 
58 {
59  api_provider = NULL;
60 }
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
int(* sipinfo_send)(struct ast_channel *chan, struct ast_variable *headers, const char *content_type, const char *content, const char *useragent_filter)
Definition: sip_api.h:33
#define LOG_WARNING
Definition: logger.h:274
Structure for variables, used for configurations and for channel variables.
int ast_sip_api_provider_register(const struct ast_sip_api_tech *provider)
Register a SIP API provider.
Definition: sip_api.c:39
const int version
Definition: sip_api.h:31
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define AST_SIP_API_VERSION
Definition: sip_api.h:28
Support for logging to various files, console and syslog Configuration in file logger.conf.
void ast_sip_api_provider_unregister(void)
Unregister a SIP API provider.
Definition: sip_api.c:57
int ast_sipinfo_send(struct ast_channel *chan, struct ast_variable *headers, const char *content_type, const char *content, const char *useragent_filter)
Send a customized SIP INFO request.
Definition: sip_api.c:25
static struct prometheus_metrics_provider provider
Definition: bridges.c:178
static const struct ast_sip_api_tech * api_provider
Definition: sip_api.c:23
const char * name
Definition: sip_api.h:32