summaryrefslogtreecommitdiff
path: root/include/asterisk/app_voicemail.h
blob: 8a42bd7bb6c954f2c1032d700c6de8baba7d24f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2011, Digium, Inc.
 *
 * David Vossel <dvossel@digium.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

/*! \file
 * \brief Voice Mail API
 * \author David Vossel <dvossel@digium.com>
 */

#ifndef _ASTERISK_VM_H
#define _ASTERISK_VM_H

#include "asterisk/stringfields.h"
#include "asterisk/linkedlists.h"

#define AST_VM_FOLDER_NUMBER 12

enum ast_vm_snapshot_sort_val {
	AST_VM_SNAPSHOT_SORT_BY_ID = 0,
	AST_VM_SNAPSHOT_SORT_BY_TIME,
};

struct ast_vm_msg_snapshot {
	AST_DECLARE_STRING_FIELDS(
		AST_STRING_FIELD(msg_id);
		AST_STRING_FIELD(callerid);
		AST_STRING_FIELD(callerchan);
		AST_STRING_FIELD(exten);
		AST_STRING_FIELD(origdate);
		AST_STRING_FIELD(origtime);
		AST_STRING_FIELD(duration);
		AST_STRING_FIELD(folder_name);
		AST_STRING_FIELD(flag);
	);
	unsigned int msg_number;

	AST_LIST_ENTRY(ast_vm_msg_snapshot) msg;
};

struct ast_vm_mailbox_snapshot {
	int total_msg_num;
	AST_LIST_HEAD_NOLOCK(, ast_vm_msg_snapshot) snapshots[AST_VM_FOLDER_NUMBER];
};

/*
 * \brief Create a snapshot of a mailbox which contains information about every msg.
 *
 * \param mailbox, the mailbox to look for
 * \param context, the context to look for the mailbox in
 * \param folder, OPTIONAL.  When not NULL only msgs from the specified folder will be included.
 * \param desending, list the msgs in descending order rather than ascending order.
 * \param combine_INBOX_and_OLD, When this argument is set, The OLD folder will be represented
 *        in the INBOX folder of the snapshot. This allows the snapshot to represent the
 *        OLD and INBOX messages in sorted order merged together.
 *
 * \retval snapshot on success
 * \retval NULL on failure
 */
struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_create(const char *mailbox,
	const char *context,
	const char *folder,
	int descending,
	enum ast_vm_snapshot_sort_val sort_val,
	int combine_INBOX_and_OLD);

/*
 * \brief destroy a snapshot
 *
 * \param mailbox_snapshot The snapshot to destroy.
 * \retval NULL
 */
struct ast_vm_mailbox_snapshot *ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot);

/*!
 * \brief Move messages from one folder to another
 *
 * \param mailbox The mailbox to which the folders belong
 * \param context The voicemail context for the mailbox
 * \param num_msgs The number of messages to move
 * \param oldfolder The folder from where messages should be moved
 * \param old_msg_nums The message IDs of the messages to move
 * \param newfolder The folder to which messages should be moved
 * \param new_msg_ids[out] An array of message IDs for the messages as they are in the
 * new folder. This array must be num_msgs sized.
 *
 * \retval -1 Failure
 * \retval 0 Success
 */
int ast_vm_msg_move(const char *mailbox,
	const char *context,
	size_t num_msgs,
	const char *oldfolder,
	const char *old_msg_ids [],
	const char *newfolder);

/*!
 * \brief Remove/delete messages from a mailbox folder.
 *
 * \param mailbox The mailbox from which to delete messages
 * \param context The voicemail context for the mailbox
 * \param num_msgs The number of messages to delete
 * \param folder The folder from which to remove messages
 * \param msgs The message IDs of the messages to delete
 * 
 * \retval -1 Failure
 * \retval 0 Success
 */
int ast_vm_msg_remove(const char *mailbox,
	const char *context,
	size_t num_msgs,
	const char *folder,
	const char *msgs []);

/*!
 * \brief forward a message from one mailbox to another.
 *
 * \brief from_mailbox The original mailbox the message is being forwarded from
 * \brief from_context The voicemail context of the from_mailbox
 * \brief from_folder The folder from which the message is being forwarded
 * \brief to_mailbox The mailbox to forward the message to
 * \brief to_context The voicemail context of the to_mailbox
 * \brief to_folder The voicemail folder to forward the message to
 * \brief num_msgs The number of messages being forwarded
 * \brief msg_ids The message IDs of the messages in from_mailbox to forward
 * \brief delete_old If non-zero, the forwarded messages are also deleted from from_mailbox.
 * Otherwise, the messages will remain in the from_mailbox.
 *
 * \retval -1 Failure
 * \retval 0 Success
 */
int ast_vm_msg_forward(const char *from_mailbox,
	const char *from_context,
	const char *from_folder,
	const char *to_mailbox,
	const char *to_context,
	const char *to_folder,
	size_t num_msgs,
	const char *msg_ids [],
	int delete_old);

/*!
 * \brief Voicemail playback callback function definition
 *
 * \param channel to play the file back on.
 * \param location of file on disk
 * \param duration of file in seconds. This will be zero if msg is very short or
 * has an unknown duration.
 */
typedef void (ast_vm_msg_play_cb)(struct ast_channel *chan, const char *playfile, int duration);

/*!
 * \brief Play a voicemail msg back on a channel.
 *
 * \param mailbox msg is in.
 * \param context of mailbox.
 * \param voicemail folder to look in.
 * \param message number in the voicemailbox to playback to the channel.
 *
 * \retval 0 success
 * \retval -1 failure
 */
int ast_vm_msg_play(struct ast_channel *chan,
	const char *mailbox,
	const char *context,
	const char *folder,
	const char *msg_id,
	ast_vm_msg_play_cb cb);

/*!
 * \brief Get the name of a folder given its numeric index
 *
 * \param index The integer value of the mailbox.
 * \retval "" Invalid index provided
 * \retval other The name of the mailbox
 */
const char *ast_vm_index_to_foldername(unsigned int index);

#ifdef TEST_FRAMEWORK
/*!
 * \brief Add a user to the voicemail system for test purposes
 * \param context The context of the mailbox
 * \param mailbox The mailbox for the user
 * \retval 0 success
 * \retval other failure
 */
int ast_vm_test_create_user(const char *context, const char *mailbox);

/*!
 * \brief Dispose of a user.  This should be used to destroy a user that was
 * previously created using ast_vm_test_create_user
 * \param context The context of the mailbox
 * \param mailbox The mailbox for the user to destroy
 */
int ast_vm_test_destroy_user(const char *context, const char *mailbox);

#endif

#endif