Asterisk - The Open Source Telephony Project GIT-master-a358458
Macros | Functions | Variables
res_pjsip_mwi_body_generator.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_pubsub.h"
#include "asterisk/res_pjsip_body_generator_types.h"
#include "asterisk/module.h"
#include "asterisk/strings.h"
Include dependency graph for res_pjsip_mwi_body_generator.c:

Go to the source code of this file.

Macros

#define MWI_SUBTYPE   "simple-message-summary"
 
#define MWI_TYPE   "application"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static void * mwi_allocate_body (void *data)
 
static void mwi_destroy_body (void *body)
 
static int mwi_generate_body_content (void *body, void *data)
 
static void mwi_to_string (void *body, struct ast_str **str)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP MWI resource" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjsip,res_pjsip_pubsub", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_sip_pubsub_body_generator mwi_generator
 

Macro Definition Documentation

◆ MWI_SUBTYPE

#define MWI_SUBTYPE   "simple-message-summary"

Definition at line 39 of file res_pjsip_mwi_body_generator.c.

◆ MWI_TYPE

#define MWI_TYPE   "application"

Definition at line 38 of file res_pjsip_mwi_body_generator.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 118 of file res_pjsip_mwi_body_generator.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 118 of file res_pjsip_mwi_body_generator.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 118 of file res_pjsip_mwi_body_generator.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 98 of file res_pjsip_mwi_body_generator.c.

99{
102 }
104}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_sip_pubsub_body_generator mwi_generator
int ast_sip_pubsub_register_body_generator(struct ast_sip_pubsub_body_generator *generator)
Register a body generator with the pubsub core.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sip_pubsub_register_body_generator(), and mwi_generator.

◆ mwi_allocate_body()

static void * mwi_allocate_body ( void *  data)
static

Definition at line 41 of file res_pjsip_mwi_body_generator.c.

42{
43 struct ast_str **mwi_str;
44
45 mwi_str = ast_malloc(sizeof(*mwi_str));
46 if (!mwi_str) {
47 return NULL;
48 }
49 *mwi_str = ast_str_create(128);
50 if (!*mwi_str) {
51 ast_free(mwi_str);
52 return NULL;
53 }
54 return mwi_str;
55}
#define ast_free(a)
Definition: astmm.h:180
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define NULL
Definition: resample.c:96
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
Support for dynamic strings.
Definition: strings.h:623

References ast_free, ast_malloc, ast_str_create, and NULL.

◆ mwi_destroy_body()

static void mwi_destroy_body ( void *  body)
static

Definition at line 80 of file res_pjsip_mwi_body_generator.c.

81{
82 struct ast_str **mwi = body;
83
84 ast_free(*mwi);
85 ast_free(mwi);
86}

References ast_free.

◆ mwi_generate_body_content()

static int mwi_generate_body_content ( void *  body,
void *  data 
)
static

Definition at line 57 of file res_pjsip_mwi_body_generator.c.

58{
59 struct ast_str **mwi = body;
60 struct ast_sip_message_accumulator *counter = data;
61
62 ast_str_append(mwi, 0, "Messages-Waiting: %s\r\n",
63 counter->new_msgs ? "yes" : "no");
64 if (!ast_strlen_zero(counter->message_account)) {
65 ast_str_append(mwi, 0, "Message-Account: %s\r\n", counter->message_account);
66 }
67 ast_str_append(mwi, 0, "Voice-Message: %d/%d (0/0)\r\n",
68 counter->new_msgs, counter->old_msgs);
69
70 return 0;
71}
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Message counter used for message-summary XML bodies.

References ast_str_append(), ast_strlen_zero(), ast_sip_message_accumulator::message_account, ast_sip_message_accumulator::new_msgs, and ast_sip_message_accumulator::old_msgs.

◆ mwi_to_string()

static void mwi_to_string ( void *  body,
struct ast_str **  str 
)
static

Definition at line 73 of file res_pjsip_mwi_body_generator.c.

74{
75 struct ast_str **mwi = body;
76
77 ast_str_set(str, 0, "%s", ast_str_buffer(*mwi));
78}
const char * str
Definition: app_jack.c:147
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113

References ast_str_buffer(), ast_str_set(), and str.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 106 of file res_pjsip_mwi_body_generator.c.

107{
109 return 0;
110}
void ast_sip_pubsub_unregister_body_generator(struct ast_sip_pubsub_body_generator *generator)
Unregister a body generator with the pubsub core.

References ast_sip_pubsub_unregister_body_generator(), and mwi_generator.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP MWI resource" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjsip,res_pjsip_pubsub", }
static

Definition at line 118 of file res_pjsip_mwi_body_generator.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 118 of file res_pjsip_mwi_body_generator.c.

◆ mwi_generator

struct ast_sip_pubsub_body_generator mwi_generator
static

Definition at line 88 of file res_pjsip_mwi_body_generator.c.

Referenced by load_module(), and unload_module().