25e38e29f031a00bf0d4a8d9894bcb9fe3099a95
[asterisk/asterisk.git] / include / asterisk / file.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Generic File Format Support.
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #ifndef _ASTERISK_FILE_H
15 #define _ASTERISK_FILE_H
16
17 #include <asterisk/channel.h>
18 #include <asterisk/frame.h>
19 #include <fcntl.h>
20
21
22 #if defined(__cplusplus) || defined(c_plusplus)
23 extern "C" {
24 #endif
25
26
27 /* Convenient for waiting */
28 #define AST_DIGIT_ANY "0123456789#*"
29
30 /* Defined by individual formats.  First item MUST be a
31    pointer for use by the stream manager */
32 struct ast_filestream;
33
34 /* Register a new file format capability */
35 int ast_format_register(char *name, char *exts, int format,
36                                                 struct ast_filestream * (*open)(int fd),
37                                                 struct ast_filestream * (*rewrite)(int fd, char *comment),
38                                                 int (*apply)(struct ast_channel *, struct ast_filestream *),
39                                                 int (*write)(struct ast_filestream *, struct ast_frame *),
40                                                 struct ast_frame * (*read)(struct ast_filestream *),
41                                                 void (*close)(struct ast_filestream *),
42                                                 char * (*getcomment)(struct ast_filestream *));
43         
44 int ast_format_unregister(char *name);
45
46 /* Start streaming a file, in the preferred language if possible */
47 int ast_streamfile(struct ast_channel *c, char *filename, char *preflang);
48
49 /* Stop playback of a stream */
50 int ast_stopstream(struct ast_channel *c);
51
52 /* See if a given file exists in a given format.  If fmt is NULL,  any format is accepted.*/
53 int ast_fileexists(char *filename, char *fmt, char *preflang);
54
55 /* Rename a given file in a given format, or if fmt is NULL, then do so for all */
56 int ast_filerename(char *oldname, char *newname, char *fmt);
57
58 /* Delete a given file in a given format, or if fmt is NULL, then do so for all */
59 int ast_filedelete(char *filename, char *fmt);
60
61 /* Wait for a stream to stop or for any one of a given digit to arrive,  Returns
62    0 if the stream finishes, the character if it was interrupted, and -1 on error */
63 char ast_waitstream(struct ast_channel *c, char *breakon);
64
65 /* Create an outgoing file stream.  oflags are flags for the open() command, and
66    if check is non-zero, then it will not write a file if there are any files that
67    start with that name and have an extension */
68 struct ast_filestream *ast_writefile(char *filename, char *type, char *comment, int oflags, int check, mode_t mode);
69
70 /* Send a frame to a filestream -- note: does NOT free the frame, call ast_frfree manually */
71 int ast_writestream(struct ast_filestream *fs, struct ast_frame *f);
72
73 /* Close a playback or recording stream */
74 int ast_closestream(struct ast_filestream *f);
75
76 #define AST_RESERVED_POINTERS 4
77
78 #if defined(__cplusplus) || defined(c_plusplus)
79 }
80 #endif
81
82
83
84 #endif