Asterisk - The Open Source Telephony Project  18.5.0
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ast_sip_pubsub_register_body_generator().

Referenced by unload_module().

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

◆ mwi_allocate_body()

static void* mwi_allocate_body ( void *  data)
static

Definition at line 41 of file res_pjsip_mwi_body_generator.c.

References ast_free, ast_malloc, ast_str_create, and NULL.

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 NULL
Definition: resample.c:96
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ mwi_destroy_body()

static void mwi_destroy_body ( void *  body)
static

Definition at line 80 of file res_pjsip_mwi_body_generator.c.

References ast_free.

81 {
82  struct ast_str **mwi = body;
83 
84  ast_free(*mwi);
85  ast_free(mwi);
86 }
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182

◆ 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.

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.

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 }
Message counter used for message-summary XML bodies.
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:1091
#define ast_strlen_zero(foo)
Definition: strings.h:52
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ 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.

References ast_str_buffer(), and ast_str_set().

74 {
75  struct ast_str **mwi = body;
76 
77  ast_str_set(str, 0, "%s", ast_str_buffer(*mwi));
78 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:1065
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 106 of file res_pjsip_mwi_body_generator.c.

References AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CHANNEL_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_sip_pubsub_unregister_body_generator(), ASTERISK_GPL_KEY, and load_module().

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

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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.