/* * bronx_route_file.c -- File route handling. * * Copyright (C) 2007 Groundwork Open Source * Written by Daniel Emmanuel Feinsmith * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301, USA. * * Change Log: * DEF Created on September 17, 2007, 1:00 PM */ #include "bronx.h" #include "bronx_route.h" #include "bronx_log.h" /* * Functionality. */ apr_status_t route_file_init(route_definition *route) { FILE *fp; // Okay, just need to open a file for write. bronx_logprintf(BRONX_LOGGING_NORMAL, "{file route: %s} Opening file '%s'", route->route_name, route->output_pathname); route->fp = NULL; fp = fopen(route->output_pathname, "a"); if (fp == NULL) { bronx_logprintf(BRONX_LOGGING_NORMAL, "{file route: %s} Error opening file for append.", route->route_name); route->is_connected = 1; return(ERROR); } else { route->fp = fp; route->is_connected = 1; return(APR_SUCCESS); } } apr_status_t assert_file_connect(route_definition *route) { apr_status_t rv; if(route->fp == NULL) { rv = route_file_init(route); if(rv != APR_SUCCESS) bronx_logprintf(BRONX_LOGGING_NORMAL, "{assert_tcp_connect} (route: %s) Unable to Establish File Connection.", route->route_name); else bronx_logprintf(BRONX_LOGGING_DEBUG, "{assert_tcp_connect} (route: %s) File Connection Established", route->route_name); } else rv = APR_SUCCESS; return(rv); } apr_status_t route_message_file(route_definition *route, char *marshalled_msg) { apr_status_t rv; if ((rv = assert_file_connect(route)) == APR_SUCCESS) { fputs(marshalled_msg, route->fp); fflush(route->fp); bronx_logprintf(BRONX_LOGGING_DEBUG, "{route_message_file} {route: %s} Message routed to file '%s', size of message=%d.", route->route_name, route->output_pathname, strlen(marshalled_msg)); return(APR_SUCCESS); } else bronx_logprintf(BRONX_LOGGING_NORMAL, "{route_message_tcp} (route: %s) File Connection Assert Failed", route->route_name); return(ERROR); }