[asterisk-commits] tzafrir: branch tzafrir/monitor-rtp-14 r213886 - /team/tzafrir/monitor-rtp-14...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 24 18:00:49 CDT 2009
Author: tzafrir
Date: Mon Aug 24 18:00:46 2009
New Revision: 213886
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=213886
Log:
ast_writefd: write formatted data to a FD
Add a new internal function, ast_writefd() to file.c . Like
ast_writefile() it writes frames to a file considering their format.
Unlike ast_writefile() it uses an existing file descriptor provided by
the caller.
This is intended to allow the caller e.g. opening a socket and handing
over the resulting file descriptor to the Asterisk core.
Modified:
team/tzafrir/monitor-rtp-14/main/file.c
Modified: team/tzafrir/monitor-rtp-14/main/file.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tzafrir/monitor-rtp-14/main/file.c?view=diff&rev=213886&r1=213885&r2=213886
==============================================================================
--- team/tzafrir/monitor-rtp-14/main/file.c (original)
+++ team/tzafrir/monitor-rtp-14/main/file.c Mon Aug 24 18:00:46 2009
@@ -1019,6 +1019,47 @@
ast_log(LOG_WARNING, "No such format '%s'\n", type);
return fs;
+}
+
+static struct ast_filestream *ast_writefd(void *stateinfo, int fd, const char *type)
+{
+ struct ast_filestream *fs = NULL;
+ FILE *bfile = NULL;
+ struct ast_format *f;
+
+ ast_log(LOG_NOTICE, "%s: fd=%d type=%s\n", __FUNCTION__, fd, type);
+ if (AST_LIST_LOCK(&formats)) {
+ ast_log(LOG_WARNING, "Unable to lock format list\n");
+ return NULL;
+ }
+ AST_LIST_TRAVERSE(&formats, f, list) {
+ if (!exts_compare(f->exts, type))
+ continue;
+ bfile = fdopen(fd, "w");
+ if (!bfile) {
+ ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
+ }
+ errno = 0;
+ ast_log(LOG_NOTICE, "%s: calling get_filestream()\n", __FUNCTION__);
+ fs = get_filestream(f, bfile);
+ if (!fs) {
+ ast_log(LOG_WARNING, "get_filestream failed\n");
+ continue;
+ }
+ fs->trans = NULL;
+ fs->fmt = f;
+ fs->flags = 0;
+ fs->mode = 0;
+ fs->realfilename = NULL;
+ fs->filename = stateinfo;
+ fs->vfs = NULL;
+ }
+ AST_LIST_UNLOCK(&formats);
+ if (!fs)
+ ast_log(LOG_WARNING, "No such format '%s'\n", type);
+ ast_log(LOG_NOTICE, "%s: returning\n", __FUNCTION__);
+ return fs;
+
}
struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
More information about the asterisk-commits
mailing list