<s2sport>5269</s2sport>
<listen_address>10.0.0.3</listen_address>
<loglevel>3</loglevel>
- <logfile>/openils/var/log/jabber.log</logfile>
+ <logfile>syslog</logfile>
+ <syslog>local2</syslog>
</chopchop>
libstack/osrf_transgroup.o \
libstack/osrf_list.o \
libstack/osrf_hash.o \
- libstack/osrf_log.o \
utils/socket_bundle.o \
utils/string_array.o \
utils/utils.o \
- utils/logging.o \
+ utils/log.o \
utils/md5.o \
utils/sha.o \
libstack/osrf_application.h \
libstack/osrf_cache.h \
libstack/xml_utils.h \
- libstack/osrf_log.h \
libstack/osrf_transgroup.h \
libstack/osrf_list.h \
libstack/osrf_hash.h \
utils/socket_bundle.h \
utils/string_array.h \
utils/utils.h \
- utils/logging.h \
+ utils/log.h \
utils/md5.h \
utils/sha.h \
#include "opensrf/osrf_app_session.h"
#include "opensrf/osrf_application.h"
#include "objson/object.h"
-#include "opensrf/osrf_log.h"
+#include "opensrf/log.h"
#define MODULENAME "opensrf.dbmath"
#include "opensrf/osrf_app_session.h"
#include "opensrf/osrf_application.h"
#include "objson/object.h"
-#include "opensrf/osrf_log.h"
+#include "opensrf/log.h"
#define MODULENAME "opensrf.math"
OSRF_METHOD_VERIFY_CONTEXT(ctx); /* see osrf_application.h */
- osrfLog( OSRF_DEBUG, "Running opensrf.math %s", ctx->method->name );
-
/* collect the request params */
jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
if( a && b ) {
+ osrfLogActivity( "Running opensrf.math %s [ %s : %s ]",
+ ctx->method->name, a, b );
+
/* construct a new params object to send to dbmath */
jsonObject* newParams = jsonParseString( "[ %s, %s ]", a, b );
free(a); free(b);
#include "opensrf/osrf_application.h"
#include "objson/object.h"
#include "opensrf/utils.h"
-#include "opensrf/osrf_log.h"
+#include "opensrf/log.h"
#define OSRF_VERSION_CACHE_TIME 300
free(json);
if( cachedmd5 ) {
- osrfLog( OSRF_DEBUG, "Found %s object in cache, returning....", cachedmd5 );
+ osrfLogDebug( "Found %s object in cache, returning....", cachedmd5 );
jsonObject* resp = jsonNewObject(cachedmd5);
osrfAppRespondComplete( ctx, resp );
jsonObjectFree(resp);
osrfAppRespondComplete( ctx, resp );
jsonObjectFree(resp);
osrfAppSessionFree(ses);
- osrfLog(OSRF_DEBUG, "Found version string %s, caching and returning...", resultmd5 );
+ osrfLogDebug("Found version string %s, caching and returning...", resultmd5 );
osrfCachePutString( paramsmd5, resultmd5, OSRF_VERSION_CACHE_TIME );
free(resultmd5);
free(paramsmd5);
cfg = ils_gateway_config_file;
#endif
- if( ! osrf_system_bootstrap_client( cfg, CONFIG_CONTEXT) )
- fatal_handler("Unable to load gateway config file...");
+ if( ! osrf_system_bootstrap_client( cfg, CONFIG_CONTEXT) ) {
+ osrfLogError("Unable to load gateway config file...");
+ return;
+ }
fprintf(stderr, "Bootstrapping %d\n", getpid() );
fflush(stderr);
}
/* verify we are connected */
if(!osrf_system_get_transport_client()) {
- fatal_handler("Bootstrap Failed, no transport client");
+ osrfLogError("Bootstrap Failed, no transport client");
return HTTP_INTERNAL_SERVER_ERROR;
}
ap_setup_client_block(r,REQUEST_CHUNKED_DECHUNK);
if(! ap_should_client_block(r)) {
- warning_handler("No Post Body");
+ osrfLogWarning("No Post Body");
}
char body[1025];
buffer = buffer_init(1025);
while(ap_get_client_block(r, body, 1024)) {
- debug_handler("Apache read POST block data: %s\n", body);
+ osrfLogDebug("Apache read POST block data: %s\n", body);
buffer_add( buffer, body );
memset(body,0,1025);
}
}
- debug_handler("params args are %s", arg);
+ osrfLogDebug("params args are %s", arg);
if( ! arg || !arg[0] ) { /* we received no request */
- warning_handler("No Args");
+ osrfLogWarning("No Args");
return OK;
}
}
- info_handler("\nPerforming(%d): service %s | method %s |",
+ osrfLogInfo("\nPerforming(%d): service %s | method %s |",
getpid(), service, method );
int k;
for( k = 0; k!= sarray->size; k++ ) {
- info_handler( "param %s", string_array_get_string(sarray,k));
+ osrfLogInfo( "param %s", string_array_get_string(sarray,k));
}
osrf_app_session* session = osrf_app_client_session_init(service);
- debug_handler("MOD session service: %s", session->remote_service );
+ osrfLogDebug("MOD session service: %s", session->remote_service );
int req_id = osrf_app_session_make_req( session, NULL, method, 1, sarray );
string_array_destroy(sarray);
jsonObjectSetKey(exception, "is_err", json_parse_string("1"));
jsonObjectSetKey(exception, "err_msg", jsonNewObject(exc_buffer->buf) );
- warning_handler("*** Looks like we got a "
+ osrfLogWarning("*** Looks like we got a "
"server exception\n%s", exc_buffer->buf );
buffer_free(exc_buffer);
buffer_free(result_data);
if(content) {
- info_handler( "APACHE writing data to web client: %s", content );
+ osrfLogInfo( "APACHE writing data to web client: %s", content );
ap_rputs(content,r);
free(content);
}
osrf_app_session_request_finish( session, req_id );
- debug_handler("gateway process message successfully");
-
+ osrfLogDebug("gateway process message successfully");
osrf_app_session_destroy(session);
return OK;
#include "osrf_chat.h"
#include <string.h>
#include <stdio.h>
+#include <time.h>
int __osrfChatXMLErrorOcurred = 0;
int __osrfChatClientSentDisconnect = 0;
node->to, node->resource, node->username, node->domain, node->authkey, node->type );
}
- debug_handler("DEBUG:\n%s", buf->buf );
+ osrfLogDebug("DEBUG:\n%s", buf->buf );
buffer_free(buf);
osrfListIteratorFree(itr);
}
if(!server) return -1;
while(1) {
if(socket_wait_all(server->mgr, -1) < 0)
- warning_handler( "jserver_wait(): socket_wait_all() returned error");
+ osrfLogWarning( "jserver_wait(): socket_wait_all() returned error");
}
return -1;
}
osrfChatNode* node = osrfListGetIndex( server->nodeList, sockid );
if(node)
- debug_handler("Found node for sockid %d with state %d", sockid, node->state);
+ osrfLogDebug("Found node for sockid %d with state %d", sockid, node->state);
if(!node) {
- debug_handler("Adding new connection for sockid %d", sockid );
+ osrfLogDebug("Adding new connection for sockid %d", sockid );
node = osrfChatAddNode( server, sockid );
}
if(node) {
if( (osrfChatPushData( server, node, data ) == -1) ) {
- warning_handler("Node at socket %d received bad XML, disconnecting...", sockid );
+ osrfLogWarning("Node at socket %d received bad XML, disconnecting...", sockid );
osrfChatSendRaw( node, OSRF_CHAT_PARSE_ERROR );
osrfChatRemoveNode( server, node );
}
if( eq( dombuf, cs->domain ) ) { /* this is to a user we host */
- info_handler("Sending message on local connection\nfrom: %s\nto: %s", fromAddr, toAddr );
+ osrfLogInfo("Sending message on local connection\nfrom: %s\nto: %s", fromAddr, toAddr );
osrfChatNode* tonode = osrfHashGet(cs->nodeHash, toAddr);
if(tonode) {
osrfChatSendRaw( tonode, msgXML );
} else {
/* send an error message saying we don't have this connection */
- warning_handler("We have no connection for %s", toAddr);
+ osrfLogWarning("We have no connection for %s", toAddr);
char* xml = va_list_to_string( OSRF_CHAT_NO_RECIPIENT, toAddr, fromAddr );
osrfChatSendRaw( node, xml );
free(xml);
osrfChatNode* tonode = osrfHashGet(cs->nodeHash, dombuf);
if(tonode) {
if( tonode->state == OSRF_CHAT_STATE_CONNECTED ) {
- debug_handler("Routing message to server %s", dombuf);
+ osrfLogDebug("Routing message to server %s", dombuf);
osrfChatSendRaw( tonode, msgXML );
} else {
- info_handler("Received s2s message and we're still trying to connect...caching");
+ osrfLogInfo("Received s2s message and we're still trying to connect...caching");
osrfListPush( tonode->msgs, strdup(msgXML) );
}
} else {
if( osrfChatInitS2S( cs, dombuf, toAddr, msgXML ) != 0 ) {
- warning_handler("We are unable to connect to remote server %s for recipient %s", dombuf, toAddr);
+ osrfLogWarning("We are unable to connect to remote server %s for recipient %s", dombuf, toAddr);
char* xml = va_list_to_string( OSRF_CHAT_NO_RECIPIENT, toAddr, fromAddr );
osrfChatSendRaw( node, xml );
free(xml);
osrfChatS2SMessage* msg = safe_malloc(sizeof(osrfChatS2SMessage));
msg->toAddr = strdup(toAddr);
msg->msgXML = strdup(msgXML);
- info_handler("Pushing client message onto s2s queue waiting for connect... ");
+ osrfLogInfo("Pushing client message onto s2s queue waiting for connect... ");
osrfListPush( snode->msgs, msgXML );
}
*/
int osrfChatInitS2S( osrfChatServer* cs, char* remote, char* toAddr, char* msgXML ) {
if(!(cs && remote && toAddr && msgXML)) return -1;
- info_handler("Initing server2server connection to domain %s", remote );
+ osrfLogInfo("Initing server2server connection to domain %s", remote );
osrfChatNode* snode = osrfNewChatS2SNode( cs->domain, remote );
snode->parent = cs;
/* try to connect to the remote site */
snode->sockid = socket_open_tcp_client(cs->mgr, cs->s2sport, remote);
if(snode->sockid < 1) {
- warning_handler("Unable to connect to remote server at %s", remote );
+ osrfLogWarning("Unable to connect to remote server at %s", remote );
return -1;
}
/* send the initial s2s request */
osrfChatSendRaw( snode, OSRF_CHAT_S2S_INIT );
- debug_handler("Added new s2s node...");
+ osrfLogDebug("Added new s2s node...");
chatdbg(cs);
return 0;
chatdbg(server);
- debug_handler("pushing data into xml parser for node %d with state %d:\n%s",
+ osrfLogDebug("pushing data into xml parser for node %d with state %d:\n%s",
node->sockid, node->state, data);
node->inparse = 1;
xmlParseChunk(node->parserCtx, data, strlen(data), 0);
void osrfChatStartStream( void* blob ) {
- debug_handler("Starting new client stream...");
+ osrfLogDebug("Starting new client stream...");
}
int status = -1;
char* nm = (char*) name;
- debug_handler("Starting element %s with namespace %s and node state %d",
+ osrfLogDebug("Starting element %s with namespace %s and node state %d",
nm, xmlSaxAttr(atts, "xmlns"), node->state );
switch( node->state ) {
case OSRF_CHAT_STATE_NONE:
status = osrfChatHandleNewConnection( node, nm, atts );
- debug_handler("After NewConnection we have state %d", node->state);
+ osrfLogDebug("After NewConnection we have state %d", node->state);
break;
case OSRF_CHAT_STATE_CONNECTING:
osrfChatParseError( node, "We don't know how to handle the XML data received" );
}
-#define CHAT_CHECK_VARS(x,y,z) if(!(x && y)) return -1; if(z) debug_handler(z);
+#define CHAT_CHECK_VARS(x,y,z) if(!(x && y)) return -1; if(z) osrfLogDebug(z);
char* from = (char*) xmlGetProp(xmlDocGetRootElement(doc), BAD_CAST "from");
char* to = (char*) xmlGetProp(xmlDocGetRootElement(doc), BAD_CAST "to");
osrfChatSend( node->parent, node, to, from, xml );
- debug_handler("Sending cached message from %s to %s", from, to);
+ osrfLogDebug("Sending cached message from %s to %s", from, to);
xmlFree(to); xmlFree(from);
xmlFreeDoc(doc);
}
}
if(status == 0) {
- info_handler("Successfully made S2S connection to %s", node->remote );
+ osrfLogInfo("Successfully made S2S connection to %s", node->remote );
node->state = OSRF_CHAT_STATE_CONNECTED;
node->xmlstate = 0;
}
if(!domain) return -1;
if(!eq(domain, node->domain)) {
- warning_handler("Client attempting to connect to invalid domain");
+ osrfLogWarning("Client attempting to connect to invalid domain");
return -1;
}
char* buf = va_list_to_string( OSRF_CHAT_START_STREAM, domain, node->authkey );
node->state = OSRF_CHAT_STATE_CONNECTING;
- debug_handler("Server node %d setting state to OSRF_CHAT_STATE_CONNECTING[%d]",
+ osrfLogDebug("Server node %d setting state to OSRF_CHAT_STATE_CONNECTING[%d]",
node->sockid, node->state );
- debug_handler("Server responding to connect message with\n%s\n", buf );
+ osrfLogDebug("Server responding to connect message with\n%s\n", buf );
osrfChatSendRaw( node, buf );
free(buf);
return 0;
/* server to server init */
if(eq(ns, "jabber:server")) { /* client connection */
- info_handler("We received a new server 2 server connection, generating auth key...");
+ osrfLogInfo("We received a new server 2 server connection, generating auth key...");
char* xml = va_list_to_string( OSRF_CHAT_S2S_CHALLENGE, node->authkey );
osrfChatSendRaw( node, xml );
free(xml);
int osrfChatHandleConnecting( osrfChatNode* node, const char* name, const xmlChar** atts ) {
CHAT_CHECK_VARS(node, name, "osrfChatHandleConnecting()");
- debug_handler("Handling connect node %s", name );
+ osrfLogDebug("Handling connect node %s", name );
if(eq(name, "iq")) node->xmlstate |= OSRF_CHAT_STATE_INIQ;
else if(eq(name,"username")) node->xmlstate |= OSRF_CHAT_STATE_INUSERNAME;
/* takes s2s secret, hashdomain, and the s2s auth token */
static char* osrfChatGenerateS2SKey( char* secret, char* hashdomain, char* authtoken ) {
if(!(secret && hashdomain && authtoken)) return NULL;
- info_handler("Generating s2s key with auth token: %s", authtoken );
+ osrfLogInfo("Generating s2s key with auth token: %s", authtoken );
char* a = shahash(secret);
- debug_handler("S2S secret hash: %s", a);
+ osrfLogDebug("S2S secret hash: %s", a);
char* b = va_list_to_string("%s%s", a, hashdomain);
char* c = shahash(b);
- debug_handler("S2S intermediate hash: %s", c);
+ osrfLogDebug("S2S intermediate hash: %s", c);
char* d = va_list_to_string("%s%s", c, authtoken);
char* e = strdup(shahash(d));
free(b); free(d);
/* we use our domain in the s2s challenge hash */
char* d = osrfChatGenerateS2SKey(node->parent->secret, node->domain, id );
char* e = va_list_to_string(OSRF_CHAT_S2S_RESPONSE, node->remote, node->domain, d );
- info_handler("Answering s2s challenge with key: %s", e );
+ osrfLogInfo("Answering s2s challenge with key: %s", e );
osrfChatSendRaw( node, e );
free(d); free(e);
node->state = OSRF_CHAT_STATE_S2S_VERIFY;
char* string = xmlDocToString(node->msgDoc, 0 );
char* from = (char*) xmlGetProp(msg, BAD_CAST "from");
- debug_handler( "Routing message to %s\n%s\n", node->to, from, string );
+ osrfLogDebug( "Routing message to %s\n%s\n", node->to, from, string );
osrfChatSend( node->parent, node, node->to, from, string );
xmlFree(from);
free(string);
node->remote = va_list_to_string(
"%s@%s/%s", node->username, node->domain, node->resource );
- info_handler("%s successfully logged in", node->remote );
+ osrfLogInfo("%s successfully logged in", node->remote );
- debug_handler("Setting remote address to %s", node->remote );
+ osrfLogDebug("Setting remote address to %s", node->remote );
osrfChatSendRaw( node, OSRF_CHAT_LOGIN_OK );
if(osrfHashGet( node->parent->nodeHash, node->remote ) ) {
- warning_handler("New node replaces existing node for remote id %s", node->remote);
+ osrfLogWarning("New node replaces existing node for remote id %s", node->remote);
osrfHashRemove(node->parent->nodeHash, node->remote);
}
osrfHashSet( node->parent->nodeHash, node, node->remote );
osrfChatNode* node = (osrfChatNode*) blob;
/*
- debug_handler("Char Handler: state %d, xmlstate %d, chardata %s",
+ osrfLogDebug("Char Handler: state %d, xmlstate %d, chardata %s",
node->state, node->xmlstate, (char*) ch );
*/
(node->xmlstate & OSRF_CHAT_STATE_INS2SRESULT) ) {
char* key = strndup((char*) ch, len);
- debug_handler("Got s2s key from %s : %s", node->remote, key );
+ osrfLogDebug("Got s2s key from %s : %s", node->remote, key );
char* e = osrfChatGenerateS2SKey(node->parent->secret, node->remote, node->authkey );
- info_handler("\nReceived s2s key from server: %s\nKey should be: %s", key, e );
+ osrfLogInfo("\nReceived s2s key from server: %s\nKey should be: %s", key, e );
if(eq(key, e)) {
char* msg = va_list_to_string(OSRF_CHAT_S2S_VERIFY_REQUEST,
node->xmlstate = 0;
} else {
- warning_handler("Server2Server keys do not match!");
+ osrfLogWarning("Server2Server keys do not match!");
}
/* do the hash dance again */
#include "opensrf/utils.h"
#include "opensrf/osrf_hash.h"
#include "opensrf/osrf_list.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include "opensrf/xml_utils.h"
#include "opensrf/socket_bundle.h"
#include "opensrf/sha.h"
#include "osrf_chat.h"
#include "opensrf/osrfConfig.h"
#include <stdio.h>
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
+#include <syslog.h>
int main( int argc, char* argv[] ) {
int port = atoi(sport);
int s2port = atoi(s2sport);
int level = atoi(llevel);
- log_init(level, lfile);
+ //log_init(level, lfile);
+ osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "chopchop", level);
+ osrfLogSetSyslogFacility(LOG_LOCAL2);
fprintf(stderr, "Attempting to launch ChopChop with:\n"
"domain: %s\nport: %s\nlisten address: %s\nlog level: %s\nlog file: %s\n",
osrfChatServer* server = osrfNewChatServer(domain, secret, s2port);
- if( osrfChatServerConnect( server, port, s2port, listenaddr ) != 0 )
- return fatal_handler("ChopChop unable to bind to port %d on %s", port, listenaddr);
+ if( osrfChatServerConnect( server, port, s2port, listenaddr ) != 0 ) {
+ osrfLogError("ChopChop unable to bind to port %d on %s", port, listenaddr);
+ return -1;
+ }
daemonize();
osrfChatServerWait( server );
osrfChatServerFree( server );
- log_free();
osrfConfigFree(cfg);
return 0;
osrfConfig.o \
osrf_application.o \
osrf_cache.o \
- osrf_log.o \
osrf_transgroup.o \
osrf_list.o \
osrf_hash.o \
osrfConfig.h \
osrf_application.h \
osrf_cache.h \
- osrf_log.h \
osrf_transgroup.h \
osrf_list.h \
osrf_hash.h \
osrfConfig.o: osrfConfig.c osrfConfig.h xml_utils.o
osrf_application.o: osrf_application.c osrf_application.h
osrf_cache.o: osrf_cache.c osrf_cache.h
-osrf_log.o: osrf_log.c osrf_log.h
osrf_list.o: osrf_list.c osrf_list.h
osrf_hash.o: osrf_hash.c osrf_hash.h
xmlDocPtr doc = xmlParseFile(configFile);
if(!doc) {
- warning_handler( "Unable to parse XML config file %s", configFile);
+ osrfLogWarning( "Unable to parse XML config file %s", configFile);
return NULL;
}
xmlFreeDoc(doc);
if(!cfg->config) {
- warning_handler("xmlDocToJSON failed for config %s", configFile);
+ osrfLogWarning("xmlDocToJSON failed for config %s", configFile);
return NULL;
}
if(!path) return NULL;
if(!cfg) cfg = __osrfConfigDefault;
- if(!cfg) { warning_handler("No Confif object!"); return NULL; }
+ if(!cfg) { osrfLogWarning("No Confif object!"); return NULL; }
VA_LIST_TO_STRING(path);
if(!arr || !path) return 0;
if(!cfg) cfg = __osrfConfigDefault;
- if(!cfg) { return warning_handler("No Config object!"); }
+ if(!cfg) { osrfLogWarning("No Config object!"); return -1;}
VA_LIST_TO_STRING(path);
/** Pushes the given message onto the list of 'responses' to this request */
void _osrf_app_request_push_queue( osrf_app_request* req, osrf_message* result ){
if(req == NULL || result == NULL) return;
- debug_handler( "App Session pushing request [%d] onto request queue", result->thread_trace );
+ osrfLogDebug( "App Session pushing request [%d] onto request queue", result->thread_trace );
if(req->result == NULL)
req->result = result;
else {
void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id ) {
if(session == NULL) return;
- debug_handler("Resetting request timeout %d", req_id );
+ osrfLogDebug("Resetting request timeout %d", req_id );
osrf_app_request* req = osrfListGetIndex( session->request_queue, req_id );
if(req == NULL) return;
req->reset_timeout = 1;
while( remaining >= 0 ) {
/* tell the session to wait for stuff */
- debug_handler( "In app_request receive with remaining time [%d]", (int) remaining );
+ osrfLogDebug( "In app_request receive with remaining time [%d]", (int) remaining );
osrf_app_session_queue_wait( req->session, 0 );
if( req->result != NULL ) { /* if we received anything */
/* pop off the first message in the list */
- debug_handler( "app_request_recv received a message, returning it");
+ osrfLogDebug( "app_request_recv received a message, returning it");
osrf_message* ret_msg = req->result;
osrf_message* tmp_msg = ret_msg->next;
req->result = tmp_msg;
if( req->result != NULL ) { /* if we received anything */
/* pop off the first message in the list */
- debug_handler( "app_request_recv received a message, returning it");
+ osrfLogDebug( "app_request_recv received a message, returning it");
osrf_message* ret_msg = req->result;
osrf_message* tmp_msg = ret_msg->next;
req->result = tmp_msg;
if(req->reset_timeout) {
remaining = (time_t) timeout;
req->reset_timeout = 0;
- debug_handler("Recevied a timeout reset");
+ osrfLogDebug("Recevied a timeout reset");
} else {
remaining -= (int) (time(NULL) - start);
}
}
- debug_handler("Returning NULL from app_request_recv after timeout");
+ osrfLogDebug("Returning NULL from app_request_recv after timeout");
return NULL;
}
int _osrf_app_request_resend( osrf_app_request* req ) {
if(req == NULL) return 0;
if(!req->complete) {
- debug_handler( "Resending request [%d]", req->request_id );
+ osrfLogDebug( "Resending request [%d]", req->request_id );
return _osrf_app_session_send( req->session, req->payload );
}
return 1;
session->transport_handle = osrf_system_get_transport_client();
if( session->transport_handle == NULL ) {
- warning_handler("No transport client for service 'client'");
+ osrfLogWarning("No transport client for service 'client'");
return NULL;
}
#ifdef ASSUME_STATELESS
session->stateless = 1;
- debug_handler("%s session is stateless", remote_service );
+ osrfLogDebug("%s session is stateless", remote_service );
#else
session->stateless = 0;
- debug_handler("%s session is NOT stateless", remote_service );
+ osrfLogDebug("%s session is NOT stateless", remote_service );
#endif
/* build a chunky, random session id */
sprintf(id, "%lf.%d%d", get_timestamp_millis(), (int)time(NULL), getpid());
session->session_id = strdup(id);
- debug_handler( "Building a new client session with id [%s] [%s]",
+ osrfLogDebug( "Building a new client session with id [%s] [%s]",
session->remote_service, session->session_id );
session->thread_trace = 0;
osrf_app_session* osrf_app_server_session_init(
char* session_id, char* our_app, char* remote_id ) {
- info_handler("Initing server session with session id %s, service %s,"
+ osrfLogInfo("Initing server session with session id %s, service %s,"
" and remote_id %s", session_id, our_app, remote_id );
osrf_app_session* session = osrf_app_session_find_session( session_id );
session->transport_handle = osrf_system_get_transport_client();
if( session->transport_handle == NULL ) {
- warning_handler("No transport client for service '%s'", our_app );
+ osrfLogWarning("No transport client for service '%s'", our_app );
return NULL;
}
osrf_app_request* req = _osrf_app_request_init( session, req_msg );
if(_osrf_app_session_send( session, req_msg ) ) {
- warning_handler( "Error sending request message [%d]", session->thread_trace );
+ osrfLogWarning( "Error sending request message [%d]", session->thread_trace );
return -1;
}
- debug_handler( "Pushing [%d] onto requeust queue for session [%s] [%s]",
+ osrfLogDebug( "Pushing [%d] onto requeust queue for session [%s] [%s]",
req->request_id, session->remote_service, session->session_id );
osrfListSet( session->request_queue, req, req->request_id );
return req->request_id;
return;
free(session->remote_id);
- debug_handler( "App Session [%s] [%s] resetting remote id to %s",
+ osrfLogDebug( "App Session [%s] [%s] resetting remote id to %s",
session->remote_service, session->session_id, session->orig_remote_id );
session->remote_id = strdup(session->orig_remote_id);
int timeout = 5; /* XXX CONFIG VALUE */
- debug_handler( "AppSession connecting to %s", session->remote_id );
+ osrfLogDebug( "AppSession connecting to %s", session->remote_id );
/* defaulting to protocol 1 for now */
osrf_message* con_msg = osrf_message_init( CONNECT, session->thread_trace, 1 );
}
if(session->state == OSRF_SESSION_CONNECTED)
- debug_handler(" * Connected Successfully to %s", session->remote_service );
+ osrfLogDebug(" * Connected Successfully to %s", session->remote_service );
if(session->state != OSRF_SESSION_CONNECTED)
return 0;
return 1;
if(session->stateless && session->state != OSRF_SESSION_CONNECTED) {
- debug_handler(
+ osrfLogDebug(
"Exiting disconnect on stateless session %s",
session->session_id);
return 1;
}
- debug_handler( "AppSession disconnecting from %s", session->remote_id );
+ osrfLogDebug( "AppSession disconnecting from %s", session->remote_id );
osrf_message* dis_msg = osrf_message_init( DISCONNECT, session->thread_trace, 1 );
session->state = OSRF_SESSION_DISCONNECTED;
transport_message* t_msg = message_init(
string, "", session->session_id, session->remote_id, NULL );
- debug_handler("Session [%s] [%s] sending to %s \nData: %s",
+ osrfLogDebug("Session [%s] [%s] sending to %s \nData: %s",
session->remote_service, session->session_id, t_msg->recipient, string );
retval = client_send_message( session->transport_handle, t_msg );
int osrf_app_session_queue_wait( osrf_app_session* session, int timeout ){
if(session == NULL) return 0;
int ret_val = 0;
- debug_handler( "AppSession in queue_wait with timeout %d", timeout );
+ osrfLogDebug( "AppSession in queue_wait with timeout %d", timeout );
ret_val = osrf_stack_entry_point(session->transport_handle, timeout);
return ret_val;
}
void osrf_app_session_destroy( osrf_app_session* session ){
if(session == NULL) return;
- debug_handler( "AppSession [%s] [%s] destroying self and deleting requests",
+ osrfLogDebug( "AppSession [%s] [%s] destroying self and deleting requests",
session->remote_service, session->session_id );
if(session->type == OSRF_SESSION_CLIENT
&& session->state != OSRF_SESSION_DISCONNECTED ) { /* disconnect if we're a client */
#include "osrf_application.h"
-#include "osrf_log.h"
#include "objson/object.h"
//osrfApplication* __osrfAppList = NULL;
if(!__osrfAppHash) __osrfAppHash = osrfNewHash();
- info_handler("Registering application %s with file %s", appName, soFile );
+ osrfLogInfo("Registering application %s with file %s", appName, soFile );
osrfApplication* app = safe_malloc(sizeof(osrfApplication));
app->handle = dlopen (soFile, RTLD_NOW);
if(!app->handle) {
- warning_handler("Failed to dlopen library file %s: %s", soFile, dlerror() );
+ osrfLogWarning("Failed to dlopen library file %s: %s", soFile, dlerror() );
dlerror(); /* clear the error */
free(app);
return -1;
*(void **) (&init) = dlsym(app->handle, "osrfAppInitialize");
if( (error = dlerror()) != NULL ) {
- warning_handler("! Unable to locate method symbol [osrfAppInitialize] for app %s: %s", appName, error );
+ osrfLogWarning("! Unable to locate method symbol [osrfAppInitialize] for app %s: %s", appName, error );
} else {
/* run the method */
int ret;
if( (ret = (*init)()) ) {
- warning_handler("Application %s returned non-zero value from "
+ osrfLogWarning("Application %s returned non-zero value from "
"'osrfAppInitialize', not registering...", appName );
//free(app->name); /* need a method to remove an application from the list */
//free(app);
__osrfAppRegisterSysMethods(appName);
- info_handler("Application %s registered successfully", appName );
+ osrfLogInfo("Application %s registered successfully", appName );
- osrfLogInit(appName);
+ osrfLogSetAppname(appName);
return 0;
}
if( !appName || ! methodName ) return -1;
osrfApplication* app = _osrfAppFindApplication(appName);
- if(!app) return warning_handler("Unable to locate application %s", appName );
+ if(!app) {
+ osrfLogWarning("Unable to locate application %s", appName );
+ return -1;
+ }
- debug_handler("Registering method %s for app %s", methodName, appName );
+ osrfLogDebug("Registering method %s for app %s", methodName, appName );
osrfMethod* method = _osrfAppBuildMethod(
methodName, symbolName, notes, argc, options );
/* this is the method we're gonna run */
int (*meth) (osrfMethodContext*);
- info_handler("Running method [%s] for app [%s] with request id %d and "
+ osrfLogInfo("Running method [%s] for app [%s] with request id %d and "
"thread trace %s", methodName, appName, reqId, ses->session_id );
if( !(app = _osrfAppFindApplication(appName)) )
if(!(ctx && ctx->method)) return -1;
if( ctx->method->options & OSRF_METHOD_ATOMIC ) {
- osrfLog( OSRF_DEBUG,
+ osrfLogDebug(
"Adding responses to stash for atomic method %s", ctx->method );
if( ctx->responses == NULL )
int __osrfAppPostProcess( osrfMethodContext* ctx, int retcode ) {
if(!(ctx && ctx->method)) return -1;
- osrfLog( OSRF_DEBUG, "Postprocessing method %s with retcode %d",
+ osrfLogDebug( "Postprocessing method %s with retcode %d",
ctx->method->name, retcode );
if(ctx->responses) { /* we have cached responses to return (no responses have been sent) */
if(!ses) return -1;
if(!msg) msg = "";
VA_LIST_TO_STRING(msg);
- osrfLog( OSRF_WARN, "Returning method exception with message: %s", VA_BUF );
+ osrfLogWarning( "Returning method exception with message: %s", VA_BUF );
osrfAppSessionStatus( ses, OSRF_STATUS_NOTFOUND, "osrfMethodException", request, VA_BUF );
return 0;
}
#include <stdio.h>
#include <dlfcn.h>
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include "objson/object.h"
#include "osrf_app_session.h"
#include "osrf_hash.h"
This macro verifies methods receive the correct parameters */
#define _OSRF_METHOD_VERIFY_CONTEXT(d) \
if(!d) return -1; \
- if(!d->session) { osrfLog( OSRF_ERROR, "Session is NULL in app reqeust" ); return -1; }\
- if(!d->method) { osrfLog( OSRF_ERROR, "Method is NULL in app reqeust" ); return -1; }\
- if(!d->params) { osrfLog( OSRF_ERROR, "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
+ if(!d->session) { osrfLogError( "Session is NULL in app reqeust" ); return -1; }\
+ if(!d->method) { osrfLogError( "Method is NULL in app reqeust" ); return -1; }\
+ if(!d->params) { osrfLogError( "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
if( d->params->type != JSON_ARRAY ) { \
- osrfLog( OSRF_ERROR, "'params' is not a JSON array for method %s", d->method->name);\
+ osrfLogError( "'params' is not a JSON array for method %s", d->method->name);\
return -1; }\
- if( !d->method->name ) { osrfLog(OSRF_ERROR, "Method name is NULL"); return -1; }
+ if( !d->method->name ) { osrfLogError( "Method name is NULL"); return -1; }
#ifdef OSRF_LOG_PARAMS
#define OSRF_METHOD_VERIFY_CONTEXT(d) \
_OSRF_METHOD_VERIFY_CONTEXT(d); \
char* __j = jsonObjectToJSON(d->params);\
if(__j) { \
- osrfLog( OSRF_INFO, "%s %s - %s", d->session->remote_service, d->method->name, __j);\
+ osrfLogInfo( "%s %s - %s", d->session->remote_service, d->method->name, __j);\
free(__j); \
}
#else
#define OSRF_METHOD_VERIFY_DESCRIPTION(app, d) \
if(!app) return -1; \
if(!d) return -1;\
- if(!d->name) { osrfLog( OSRF_ERROR, "No method name provided in description" ), return -1; } \
- if(!d->symbol) { osrfLog( OSRF_ERROR, "No method symbol provided in description" ), return -1; } \
+ if(!d->name) { osrfLogError( "No method name provided in description" ), return -1; } \
+ if(!d->symbol) { osrfLogError( "No method symbol provided in description" ), return -1; } \
if(!d->notes) d->notes = ""; \
if(!d->paramNotes) d->paramNotes = "";\
if(!d->returnNotes) d->returnNotes = "";
int osrfLogInit(char* appname) {
if( !appname ) return -1;
- info_handler("Initing application log for app %s", appname );
+ osrfLogInfo("Initing application log for app %s", appname );
char* dir = osrf_settings_host_value("/dirs/log");
- if(!dir) return warning_handler("No '/dirs/log' setting in host config");
+ if(!dir) return osrfLogWarning("No '/dirs/log' setting in host config");
char* level = osrfConfigGetValue(NULL, "/loglevel");
if(level) { __osrfLogLevel = atoi(level); free(level); }
free(filename);
if(!file) {
- warning_handler("Unable to open application log file %s\n", filename);
+ osrfLogWarning("Unable to open application log file %s\n", filename);
return;
}
if(!msg || !o) return;
if(o->type != JSON_ARRAY) {
- warning_handler("passing non-array to osrf_message_set_params(), fixing...");
+ osrfLogWarning("passing non-array to osrf_message_set_params(), fixing...");
jsonObject* clone = jsonObjectClone(o);
o = jsonNewObject(NULL);
jsonObjectPush(o, clone);
void osrf_message_set_status_info(
osrf_message* msg, char* status_name, char* status_text, int status_code ) {
-
- if( msg == NULL )
- fatal_handler( "Bad params to osrf_message_set_status_info()" );
+ if(!msg) return;
if( status_name != NULL )
msg->status_name = strdup( status_name );
void osrf_message_set_result_content( osrf_message* msg, char* json_string ) {
- if( msg == NULL || json_string == NULL)
- warning_handler( "Bad params to osrf_message_set_result_content()" );
-
+ if( msg == NULL || json_string == NULL) return;
msg->result_string = strdup(json_string);
if(json_string) msg->_result_content = jsonParseString(json_string);
}
jsonObject* json = jsonParseString(string);
if(!json) {
- warning_handler(
+ osrfLogWarning(
"osrf_message_deserialize() unable to parse data: \n%s\n", string);
return 0;
}
#include "opensrf/string_array.h"
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include "objson/object.h"
#include "objson/json_parser.h"
int osrf_prefork_run(char* appname) {
- if(!appname) fatal_handler("osrf_prefork_run requires an appname to run!");
+ if(!appname) {
+ osrfLogError("osrf_prefork_run requires an appname to run!");
+ return -1;
+ }
set_proc_title( "OpenSRF Listener [%s]", appname );
int maxc = 10;
int minc = 3;
- info_handler("Loading config in osrf_forker for app %s", appname);
+ osrfLogInfo("Loading config in osrf_forker for app %s", appname);
jsonObject* max_req = osrf_settings_host_value_object("/apps/%s/unix_config/max_requests", appname);
jsonObject* min_children = osrf_settings_host_value_object("/apps/%s/unix_config/min_children", appname);
jsonObject* max_children = osrf_settings_host_value_object("/apps/%s/unix_config/max_children", appname);
- if(!max_req) warning_handler("Max requests not defined, assuming 1000");
+ if(!max_req) osrfLogWarning("Max requests not defined, assuming 1000");
else maxr = (int) jsonObjectGetNumber(max_req);
- if(!min_children) warning_handler("Min children not defined, assuming 3");
+ if(!min_children) osrfLogWarning("Min children not defined, assuming 3");
else minc = (int) jsonObjectGetNumber(min_children);
- if(!max_children) warning_handler("Max children not defined, assuming 10");
+ if(!max_children) osrfLogWarning("Max children not defined, assuming 10");
else maxc = (int) jsonObjectGetNumber(max_children);
jsonObjectFree(max_req);
char* resc = va_list_to_string("%s_listener", appname);
- if(!osrf_system_bootstrap_client_resc( NULL, NULL, resc ))
- fatal_handler("Unable to bootstrap client for osrf_prefork_run()");
+ if(!osrf_system_bootstrap_client_resc( NULL, NULL, resc )) {
+ osrfLogError("Unable to bootstrap client for osrf_prefork_run()");
+ free(resc);
+ return -1;
+ }
+
free(resc);
prefork_simple* forker = prefork_simple_init(
forker->appname = strdup(appname);
- if(forker == NULL)
- fatal_handler("osrf_prefork_run() failed to create prefork_simple object");
+ if(forker == NULL) {
+ osrfLogError("osrf_prefork_run() failed to create prefork_simple object");
+ return -1;
+ }
prefork_launch_children(forker);
osrf_prefork_register_routers(appname);
- info_handler("Launching osrf_forker for app %s", appname);
+ osrfLogInfo("Launching osrf_forker for app %s", appname);
prefork_run(forker);
- warning_handler("prefork_run() retuned - how??");
+ osrfLogWarning("prefork_run() retuned - how??");
prefork_free(forker);
return 0;
char* routerName = osrfConfigGetValue( NULL, "/router_name" );
transport_client* client = osrfSystemGetTransportClient();
- info_handler("router name is %s and we have %d routers to connect to", routerName, c );
+ osrfLogInfo("router name is %s and we have %d routers to connect to", routerName, c );
while( c ) {
char* domain = osrfStringArrayGetString(arr, --c);
if(domain) {
char* jid = va_list_to_string( "%s@%s/router", routerName, domain );
- info_handler("Registering with router %s", jid );
+ osrfLogInfo("Registering with router %s", jid );
transport_message* msg = message_init("registering", NULL, NULL, jid, NULL );
message_set_router_info( msg, NULL, NULL, appname, "register", 0 );
void prefork_child_init_hook(prefork_child* child) {
if(!child) return;
- info_handler("Child init hook for child %d", child->pid);
+ osrfLogInfo("Child init hook for child %d", child->pid);
char* resc = va_list_to_string("%s_drone",child->appname);
- if(!osrf_system_bootstrap_client_resc( NULL, NULL, resc))
- fatal_handler("Unable to bootstrap client for osrf_prefork_run()");
+
+ if(!osrf_system_bootstrap_client_resc( NULL, NULL, resc)) {
+ osrfLogError("Unable to bootstrap client for osrf_prefork_run()");
+ free(resc);
+ return;
+ }
+
free(resc);
set_proc_title( "OpenSRF Drone [%s]", child->appname );
/* keepalive loop for stateful sessions */
- debug_handler("Entering keepalive loop for session %s", session->session_id );
+ osrfLogDebug("Entering keepalive loop for session %s", session->session_id );
}
prefork_simple* prefork_simple_init( transport_client* client,
int max_requests, int min_children, int max_children ) {
- if( min_children > max_children )
- fatal_handler( "min_children (%d) is greater "
+ if( min_children > max_children ) {
+ osrfLogError( "min_children (%d) is greater "
"than max_children (%d)", min_children, max_children );
+ return NULL;
+ }
- if( max_children > ABS_MAX_CHILDREN )
- fatal_handler( "max_children (%d) is greater than ABS_MAX_CHILDREN (%d)",
+ if( max_children > ABS_MAX_CHILDREN ) {
+ osrfLogError( "max_children (%d) is greater than ABS_MAX_CHILDREN (%d)",
max_children, ABS_MAX_CHILDREN );
+ return NULL;
+ }
/* flesh out the struct */
prefork_simple* prefork = (prefork_simple*) safe_malloc(sizeof(prefork_simple));
int status_fd[2];
/* Set up the data pipes and add the child struct to the parent */
- if( pipe(data_fd) < 0 ) /* build the data pipe*/
- fatal_handler( "Pipe making error" );
+ if( pipe(data_fd) < 0 ) { /* build the data pipe*/
+ osrfLogError( "Pipe making error" );
+ return NULL;
+ }
- if( pipe(status_fd) < 0 ) /* build the status pipe */
- fatal_handler( "Pipe making error" );
+ if( pipe(status_fd) < 0 ) {/* build the status pipe */
+ osrfLogError( "Pipe making error" );
+ return NULL;
+ }
- debug_handler( "Pipes: %d %d %d %d", data_fd[0], data_fd[1], status_fd[0], status_fd[1] );
+ osrfLogDebug( "Pipes: %d %d %d %d", data_fd[0], data_fd[1], status_fd[0], status_fd[1] );
prefork_child* child = prefork_child_init( forker->max_requests, data_fd[0],
data_fd[1], status_fd[0], status_fd[1] );
add_prefork_child( forker, child );
- if( (pid=fork()) < 0 ) fatal_handler( "Forking Error" );
+ if( (pid=fork()) < 0 ) {
+ osrfLogError( "Forking Error" );
+ return NULL;
+ }
if( pid > 0 ) { /* parent */
(forker->current_num_children)++;
child->pid = pid;
- info_handler( "Parent launched %d", pid );
+ osrfLogInfo( "Parent launched %d", pid );
/* *no* child pipe FD's can be closed or the parent will re-use fd's that
the children are currently using */
return child;
else { /* child */
- debug_handler("I am new child with read_data_fd = %d and write_status_fd = %d",
+ osrfLogDebug("I am new child with read_data_fd = %d and write_status_fd = %d",
child->read_data_fd, child->write_status_fd );
child->pid = getpid();
while(1) {
if( forker->first_child == NULL ) {/* no more children */
- warning_handler("No more children..." );
+ osrfLogWarning("No more children..." );
return;
}
- debug_handler("Forker going into wait for data...");
+ osrfLogDebug("Forker going into wait for data...");
cur_msg = client_recv( forker->connection, -1 );
//fprintf(stderr, "Got Data %f\n", get_timestamp_millis() );
check_children( forker );
- debug_handler( "Server received inbound data" );
+ osrfLogDebug( "Server received inbound data" );
int k;
prefork_child* cur_child = forker->first_child;
/* Look for an available child */
for( k = 0; k < forker->current_num_children; k++ ) {
- debug_handler("Searching for available child. cur_child->pid = %d", cur_child->pid );
- debug_handler("Current num children %d and loop %d", forker->current_num_children, k);
+ osrfLogDebug("Searching for available child. cur_child->pid = %d", cur_child->pid );
+ osrfLogDebug("Current num children %d and loop %d", forker->current_num_children, k);
if( cur_child->available ) {
- debug_handler( "sending data to %d", cur_child->pid );
+ osrfLogDebug( "sending data to %d", cur_child->pid );
message_prepare_xml( cur_msg );
char* data = cur_msg->msg_xml;
if( ! data || strlen(data) < 1 ) break;
cur_child->available = 0;
- debug_handler( "Writing to child fd %d", cur_child->write_data_fd );
+ osrfLogDebug( "Writing to child fd %d", cur_child->write_data_fd );
int written = 0;
//fprintf(stderr, "Writing Data %f\n", get_timestamp_millis() );
if( (written = write( cur_child->write_data_fd, data, strlen(data) + 1 )) < 0 ) {
- warning_handler("Write returned error %d", errno);
+ osrfLogWarning("Write returned error %d", errno);
cur_child = cur_child->next;
continue;
}
/* if none available, add a new child if we can */
if( ! honored ) {
- debug_handler("Not enough children, attempting to add...");
+ osrfLogDebug("Not enough children, attempting to add...");
if( forker->current_num_children < forker->max_children ) {
- debug_handler( "Launching new child with current_num = %d",
+ osrfLogDebug( "Launching new child with current_num = %d",
forker->current_num_children );
prefork_child* new_child = launch_child( forker );
char* data = cur_msg->msg_xml;
if( ! data || strlen(data) < 1 ) break;
new_child->available = 0;
- debug_handler( "sending data to %d", new_child->pid );
- debug_handler( "Writing to new child fd %d", new_child->write_data_fd );
+ osrfLogDebug( "sending data to %d", new_child->pid );
+ osrfLogDebug( "Writing to new child fd %d", new_child->write_data_fd );
write( new_child->write_data_fd, data, strlen(data) + 1 );
forker->first_child = new_child->next;
honored = 1;
}
if( !honored ) {
- warning_handler( "No children available, sleeping and looping..." );
+ osrfLogWarning( "No children available, sleeping and looping..." );
usleep( 50000 ); /* 50 milliseconds */
}
FD_CLR(0,&read_set);/* just to be sure */
if( (select_ret=select( max_fd + 1 , &read_set, NULL, NULL, &tv)) == -1 ) {
- warning_handler( "Select returned error %d on check_children", errno );
+ osrfLogWarning( "Select returned error %d on check_children", errno );
}
if( select_ret == 0 )
if( FD_ISSET( cur_child->read_status_fd, &read_set ) ) {
//printf( "Server received status from a child %d\n", cur_child->pid );
- debug_handler( "Server received status from a child %d", cur_child->pid );
+ osrfLogDebug( "Server received status from a child %d", cur_child->pid );
num_handled++;
char buf[64];
memset( buf, 0, 64);
if( (n=read(cur_child->read_status_fd, buf, 63)) < 0 ) {
- warning_handler("Read error afer select in child status read with errno %d", errno);
+ osrfLogWarning("Read error afer select in child status read with errno %d", errno);
}
- debug_handler( "Read %d bytes from status buffer: %s", n, buf );
+ osrfLogDebug( "Read %d bytes from status buffer: %s", n, buf );
cur_child->available = 1;
}
cur_child = cur_child->next;
}
if( n < 0 ) {
- warning_handler( "Child read returned error with errno %d", errno );
+ osrfLogWarning( "Child read returned error with errno %d", errno );
break;
}
buffer_free(gbuf);
- debug_handler("Child exiting...[%d]", getpid() );
+ osrfLogDebug("Child exiting...[%d]", getpid() );
exit(0);
}
if( forker->first_child == NULL ) { return; }
(forker->current_num_children)--;
- debug_handler("Deleting Child: %d", pid );
+ osrfLogDebug("Deleting Child: %d", pid );
prefork_child* start_child = forker->first_child; /* starting point */
prefork_child* cur_child = start_child; /* current pointer */
int prefork_free( prefork_simple* prefork ) {
while( prefork->first_child != NULL ) {
- info_handler( "Killing children and sleeping 1 to reap..." );
+ osrfLogInfo( "Killing children and sleeping 1 to reap..." );
kill( 0, SIGKILL );
sleep(1);
}
osrf_app_session_request_finish( session, req_id );
osrf_app_session_destroy( session );
- if(!config)
- return fatal_handler("Unable to load config for host %s", hostname);
+ if(!config) {
+ osrfLogError("Unable to load config for host %s", hostname);
+ return -1;
+ }
}
return 0;
#include <time.h>
#include <stdarg.h>
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include "opensrf/utils.h"
#include "objson/object.h"
#include "objson/json_parser.h"
transport_message* msg = NULL;
while( (msg = client_recv( client, timeout )) ) {
- debug_handler( "Received message from transport code from %s", msg->sender );
+ osrfLogDebug( "Received message from transport code from %s", msg->sender );
osrf_stack_transport_handler( msg, NULL );
timeout = 0;
}
if(!msg) return NULL;
- debug_handler( "Transport handler received new message \nfrom %s "
+ osrfLogDebug( "Transport handler received new message \nfrom %s "
"to %s with body \n\n%s\n", msg->sender, msg->recipient, msg->body );
if( msg->is_error && ! msg->thread ) {
- warning_handler("!! Received jabber layer error for %s ... exiting\n", msg->sender );
+ osrfLogWarning("!! Received jabber layer error for %s ... exiting\n", msg->sender );
message_free( msg );
return NULL;
}
if(! msg->thread && ! msg->is_error ) {
- warning_handler("Received a non-error message with no thread trace... dropping");
+ osrfLogWarning("Received a non-error message with no thread trace... dropping");
message_free( msg );
return NULL;
}
if( !session ) return NULL;
if(!msg->is_error)
- debug_handler("Session [%s] found or built", session->session_id );
+ osrfLogDebug("Session [%s] found or built", session->session_id );
osrf_app_session_set_remote( session, msg->sender );
osrf_message* arr[OSRF_MAX_MSGS_PER_PACKET];
memset(arr, 0, OSRF_MAX_MSGS_PER_PACKET );
int num_msgs = osrf_message_deserialize(msg->body, arr, OSRF_MAX_MSGS_PER_PACKET);
- debug_handler( "We received %d messages from %s", num_msgs, msg->sender );
+ osrfLogDebug( "We received %d messages from %s", num_msgs, msg->sender );
int i;
for( i = 0; i != num_msgs; i++ ) {
someone who no longer exists) and we're not talking to the original
remote id for this server, consider it a redirect and pass it up */
if(msg->is_error) {
- warning_handler( " !!! Received Jabber layer error message" );
+ osrfLogWarning( " !!! Received Jabber layer error message" );
if(strcmp(session->remote_id,session->orig_remote_id)) {
- warning_handler( "Treating jabber error as redirect for tt [%d] "
+ osrfLogWarning( "Treating jabber error as redirect for tt [%d] "
"and session [%s]", arr[i]->thread_trace, session->session_id );
arr[i]->m_type = STATUS;
arr[i]->status_code = OSRF_STATUS_REDIRECTED;
} else {
- warning_handler(" * Jabber Error is for top level remote id [%s], no one "
+ osrfLogWarning(" * Jabber Error is for top level remote id [%s], no one "
"to send my message too!!!", session->remote_id );
}
}
}
message_free( msg );
- debug_handler("after msg delete");
+ osrfLogDebug("after msg delete");
return session;
}
ret_msg= _do_server( session, msg );
if(ret_msg) {
- debug_handler("passing message %d / session %s to app handler",
+ osrfLogDebug("passing message %d / session %s to app handler",
msg->thread_trace, session->session_id );
osrf_stack_application_handler( session, ret_msg );
} else
switch( msg->status_code ) {
case OSRF_STATUS_OK:
- debug_handler("We connected successfully");
+ osrfLogDebug("We connected successfully");
session->state = OSRF_SESSION_CONNECTED;
- debug_handler( "State: %x => %s => %d", session, session->session_id, session->state );
+ osrfLogDebug( "State: %x => %s => %d", session, session->session_id, session->state );
return NULL;
case OSRF_STATUS_COMPLETE:
new_msg = osrf_message_init( RESULT, msg->thread_trace, msg->protocol );
osrf_message_set_status_info( new_msg,
msg->status_name, msg->status_text, msg->status_code );
- warning_handler("The stack doesn't know what to do with "
+ osrfLogWarning("The stack doesn't know what to do with "
"the provided message code: %d, name %s. Passing UP.",
msg->status_code, msg->status_name );
new_msg->is_exception = 1;
if(session == NULL || msg == NULL) return NULL;
- debug_handler("Server received message of type %d", msg->m_type );
+ osrfLogDebug("Server received message of type %d", msg->m_type );
switch( msg->m_type ) {
case REQUEST:
- debug_handler("server passing message %d to application handler "
+ osrfLogDebug("server passing message %d to application handler "
"for session %s", msg->thread_trace, session->session_id );
return msg;
default:
- warning_handler("Server cannot handle message of type %d", msg->m_type );
+ osrfLogWarning("Server cannot handle message of type %d", msg->m_type );
return NULL;
}
char* servers[cacheServers->size];
for( i = 0; i != cacheServers->size; i++ ) {
servers[i] = jsonObjectGetString( jsonObjectGetIndex(cacheServers, i) );
- info_handler("Adding cache server %s", servers[i]);
+ osrfLogInfo("Adding cache server %s", servers[i]);
}
osrfCacheInit( servers, cacheServers->size, atoi(maxCache) );
} else {
char* servers[] = { jsonObjectGetString(cacheServers) };
- info_handler("Adding cache server %s", servers[0]);
+ osrfLogInfo("Adding cache server %s", servers[0]);
osrfCacheInit( servers, 1, atoi(maxCache) );
}
} else {
- fatal_handler( "Missing config value for /cache/global/servers/server _or_ "
+ osrfLogError( "Missing config value for /cache/global/servers/server _or_ "
"/cache/global/max_cache_time");
}
/* first we grab the settings */
if(!osrfSystemBootstrapClientResc(configfile, contextNode, "settings_grabber" )) {
- return fatal_handler("Unable to bootstrap");
+ osrfLogError("Unable to bootstrap");
+ return -1;
}
osrf_settings_retrieve(hostname);
char* libfile = osrf_settings_host_value("/apps/%s/implementation", appname);
if(! (appname && libfile) ) {
- warning_handler("Missing appname / libfile in settings config");
+ osrfLogWarning("Missing appname / libfile in settings config");
continue;
}
- info_handler("Launching application %s with implementation %s", appname, libfile);
+ osrfLogInfo("Launching application %s with implementation %s", appname, libfile);
int pid;
if( (pid = fork()) ) {
// storage pid in local table for re-launching dead children...
- info_handler("Launched application child %d", pid);
+ osrfLogInfo("Launched application child %d", pid);
} else {
if( osrfAppRegisterApplication( appname, libfile ) == 0 )
osrf_prefork_run(appname);
- debug_handler("Server exiting for app %s and library %s", appname, libfile );
+ osrfLogDebug("Server exiting for app %s and library %s", appname, libfile );
exit(0);
}
} // language == c
int osrf_system_bootstrap_client_resc( char* config_file, char* contextnode, char* resource ) {
- if( !( config_file && contextnode ) && ! osrfConfigHasDefaultConfig() )
- return fatal_handler("No Config File Specified\n" );
+ if( !( config_file && contextnode ) && ! osrfConfigHasDefaultConfig() ) {
+ osrfLogError("No Config File Specified\n" );
+ return -1;
+ }
if( config_file ) {
osrfConfigCleanup();
char* password = osrfConfigGetValue( NULL, "/passwd" );
char* port = osrfConfigGetValue( NULL, "/port" );
char* unixpath = osrfConfigGetValue( NULL, "/unixpath" );
+ char* facility = osrfConfigGetValue( NULL, "/syslog" );
char* domain = strdup(osrfStringArrayGetString( arr, 0 )); /* just the first for now */
osrfStringArrayFree(arr);
if(port) iport = atoi(port);
if(log_level) llevel = atoi(log_level);
- log_init( llevel, log_file );
+ if(!log_file) { fprintf(stderr, "Log file needed\n"); return -1; }
+
+ if(!strcmp(log_file, "syslog")) {
+ osrfLogInit( OSRF_LOG_TYPE_SYSLOG, contextnode, llevel );
+ osrfLogSetSyslogFacility(osrfLogFacilityToInt(facility));
+
+ } else {
+ osrfLogInit( OSRF_LOG_TYPE_FILE, contextnode, llevel );
+ osrfLogSetFile( log_file );
+ }
- info_handler("Bootstrapping system with domain %s, port %d, and unixpath %s", domain, iport, unixpath );
+ osrfLogInfo("Bootstrapping system with domain %s, port %d, and unixpath %s", domain, iport, unixpath );
transport_client* client = client_init( domain, iport, unixpath, 0 );
__osrfGlobalTransportClient = client;
}
+ free(facility);
free(log_level);
free(log_file);
free(username);
osrfConfigCleanup();
osrf_system_disconnect_client();
osrf_settings_free_host_config(NULL);
- log_free();
return 1;
}
int status;
while( (pid = waitpid(-1, &status, WNOHANG)) > 0) {
- warning_handler("We lost child %d", pid);
+ osrfLogWarning("We lost child %d", pid);
}
/** relaunch the server **/
#include "opensrf/transport_client.h"
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include "osrf_settings.h"
#include "osrfConfig.h"
#include "osrf_cache.h"
for( i = 0; i != count; i++ ) {
if(!(nodes[i] && nodes[i]->domain) ) return NULL;
osrfHashSet( grp->nodes, nodes[i], nodes[i]->domain );
- debug_handler("Adding domain %s to TransportGroup", nodes[i]->domain);
+ osrfLogDebug("Adding domain %s to TransportGroup", nodes[i]->domain);
}
return grp;
osrfHashIteratorReset(grp->itr);
while( (node = osrfHashIteratorNext(grp->itr)) ) {
- info_handler("TransportGroup attempting to connect to domain %s",
+ osrfLogInfo("TransportGroup attempting to connect to domain %s",
node->connection->session->server);
if(client_connect( node->connection, node->username,
node->password, node->resource, 10, AUTH_DIGEST )) {
node->active = 1;
active++;
- info_handler("TransportGroup successfully connected to domain %s",
+ osrfLogInfo("TransportGroup successfully connected to domain %s",
node->connection->session->server);
} else {
- warning_handler("TransportGroup unable to connect to domain %s",
+ osrfLogWarning("TransportGroup unable to connect to domain %s",
node->connection->session->server);
}
}
osrfHashIteratorReset(grp->itr);
while( (node = osrfHashIteratorNext(grp->itr)) ) {
- info_handler("TransportGroup disconnecting from domain %s",
+ osrfLogInfo("TransportGroup disconnecting from domain %s",
node->connection->session->server);
client_disconnect(node->connection);
node->active = 0;
return 0;
}
- return warning_handler("Error sending message to domain %s", domain );
+ osrfLogWarning("Error sending message to domain %s", domain );
+ return -1;
}
int osrfTransportGroupSend( osrfTransportGroup* grp, transport_message* msg ) {
} else {
if(!strcmp(firstdomain, node->domain)) { /* we've made a full loop */
- return warning_handler("We've tried to send to all domains.. giving up");
+ osrfLogWarning("We've tried to send to all domains.. giving up");
+ return -1;
}
}
int main( int argc, char** argv ) {
if( argc < 5 ) {
- fatal_handler( "Usage: %s <username> <host> <resource> <recipient> \n", argv[0] );
+ osrfLogError( "Usage: %s <username> <host> <resource> <recipient> \n", argv[0] );
return 99;
}
// try to connect, allow 15 second connect timeout
if( client_connect( client, argv[1], "jkjkasdf", argv[3], 15, AUTH_DIGEST ) )
- info_handler("Connected...\n");
- else
- fatal_handler( "NOT Connected...\n" );
+ osrfLogInfo("Connected...\n");
+ else {
+ osrfLogError( "NOT Connected...\n" );
+ return -1;
+ }
if( (pid=fork()) ) { /* parent */
if( argc < 5 ) {
- fatal_handler( "Usage: %s <server> <port> <name> <secret>", argv[0] );
+ osrfLogError( "Usage: %s <server> <port> <name> <secret>", argv[0] );
+ return -1;
}
int port = atoi(argv[2]);
// try to connect, allow 15 second connect timeout
if( client_connect( client, argv[3], argv[4], "", 15, 1 ) )
- info_handler("Connected...\n");
- else
- fatal_handler( "NOT Connected...\n" );
+ osrfLogInfo("Connected...\n");
+ else {
+ osrfLogError( "NOT Connected...\n" );
+ return -1;
+ }
transport_message* recv;
while( (recv=client_recv( client, -1)) ) {
if(client->session == NULL) {
- fatal_handler( "client_init(): Out of Memory");
+ osrfLogError( "client_init(): Out of Memory");
return NULL;
}
client->session->message_callback = client_message_handler;
// if( ! session_wait( client->session, -1 ) ) {
int x;
if( (x = session_wait( client->session, -1 )) ) {
- warning_handler("session_wait returned failure code %d\n", x);
+ osrfLogWarning("session_wait returned failure code %d\n", x);
return NULL;
}
}
#include "transport_session.h"
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include <time.h>
msg->subject == NULL || msg->recipient == NULL ||
msg->sender == NULL ) {
- fatal_handler( "message_init(): Out of Memory" );
+ osrfLogError( "message_init(): Out of Memory" );
return NULL;
}
encoded_body = strdup( (char*) xmlbuf );
if( encoded_body == NULL )
- fatal_handler("message_to_xml(): Out of Memory");
+ osrfLogError("message_to_xml(): Out of Memory");
xmlFree(xmlbuf);
xmlFreeDoc(msg_doc);
if( msg->router_from == NULL || msg->router_to == NULL ||
msg->router_class == NULL || msg->router_command == NULL )
- fatal_handler( "message_set_router_info(): Out of Memory" );
+ osrfLogError( "message_set_router_info(): Out of Memory" );
return;
}
xmlKeepBlanksDefault(0);
if( ! msg ) {
- warning_handler( "Passing NULL message to message_to_xml()");
+ osrfLogWarning( "Passing NULL message to message_to_xml()");
return 0;
}
encoded_body = strdup( (char*) xmlbuf );
- if( encoded_body == NULL )
- fatal_handler("message_to_xml(): Out of Memory");
+ if( encoded_body == NULL ) {
+ osrfLogError("message_to_xml(): Out of Memory");
+ return NULL;
+ }
xmlFree(xmlbuf);
xmlFreeDoc( doc );
#include <libxml/xmlmemory.h>
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#ifndef TRANSPORT_MESSAGE_H
#define TRANSPORT_MESSAGE_H
session->router_class_buffer == NULL || session->router_command_buffer == NULL ||
session->session_id == NULL ) {
- fatal_handler( "init_transport(): buffer_init returned NULL" );
+ osrfLogError( "init_transport(): buffer_init returned NULL" );
return 0;
}
if( ! session ) { return -1; }
if( ! session->state_machine->connected ) {
- warning_handler("State machine is not connected in send_msg()");
+ osrfLogWarning("State machine is not connected in send_msg()");
return -1;
}
int size2 = 0;
if( ! session ) {
- warning_handler( "session is null in connect" );
+ osrfLogWarning( "session is null in connect" );
return 0;
}
// if( ! tcp_send( session->sock_obj, stanza1 ) ) {
if( socket_send( session->sock_id, stanza1 ) ) {
- warning_handler("error sending");
+ osrfLogWarning("error sending");
return 0;
}
//if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
- warning_handler("error sending");
+ osrfLogWarning("error sending");
return 0;
}
}
session->state_machine->connecting = CONNECTING_1;
//if( ! tcp_send( session->sock_obj, stanza1 ) ) {
if( socket_send( session->sock_id, stanza1 ) ) {
- warning_handler("error sending");
+ osrfLogWarning("error sending");
return 0;
}
if( session->state_machine->connecting == CONNECTING_2 ) {
//if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
- warning_handler("error sending");
+ osrfLogWarning("error sending");
return 0;
}
}
if( session->state_machine->connecting == CONNECTING_2 ) {
//if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
- warning_handler("error sending");
+ osrfLogWarning("error sending");
return 0;
}
}
if( strcmp( name, "stream:error" ) == 0 ) {
ses->state_machine->in_error = 1;
- warning_handler( "Received <stream:error> message from Jabber server" );
+ osrfLogWarning( "Received <stream:error> message from Jabber server" );
return;
}
ses->state_machine->in_message_error = 1;
buffer_add( ses->message_error_type, get_xml_attr( atts, "type" ) );
ses->message_error_code = atoi( get_xml_attr( atts, "code" ) );
- warning_handler( "Received <error> message with type %s and code %s",
+ osrfLogWarning( "Received <error> message with type %s and code %s",
get_xml_attr( atts, "type"), get_xml_attr( atts, "code") );
return;
}
}
if( strcmp( get_xml_attr(atts, "type"), "error") == 0 ) {
- warning_handler( "Error connecting to jabber" );
+ osrfLogWarning( "Error connecting to jabber" );
return;
}
}
if( strcmp( name, "iq" ) == 0 ) {
ses->state_machine->in_iq = 0;
if( ses->message_error_code > 0 ) {
- warning_handler( "Error in IQ packet: code %d", ses->message_error_code );
- warning_handler( "Error 401 means not authorized" );
+ osrfLogWarning( "Error in IQ packet: code %d", ses->message_error_code );
+ osrfLogWarning( "Error 401 means not authorized" );
}
reset_session_buffers( session );
return;
if( ses->state_machine->in_error ) {
/* for now... */
- warning_handler( "ERROR Xml fragment: %s\n", ch );
+ osrfLogWarning( "ERROR Xml fragment: %s\n", ch );
}
}
#include "transport_message.h"
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include "opensrf/socket_bundle.h"
#include "sha.h"
int numhandled = 0;
if( (selectret = select(maxfd + 1, &set, NULL, NULL, NULL)) < 0 ) {
- warning_handler("Top level select call failed with errno %d", errno);
+ osrfLogWarning("Top level select call failed with errno %d", errno);
continue;
}
/* see if there is a top level router message */
if( FD_ISSET(routerfd, &set) ) {
- debug_handler("Top router socket is active: %d", routerfd );
+ osrfLogDebug("Top router socket is active: %d", routerfd );
numhandled++;
osrfRouterHandleIncoming( router );
}
if( classname && (class = osrfRouterFindClass( router, classname )) ) {
- debug_handler("Checking %s for activity...", classname );
+ osrfLogDebug("Checking %s for activity...", classname );
int sockfd = class->ROUTER_SOCKFD;
if(FD_ISSET( sockfd, &set )) {
- debug_handler("Socket is active: %d", sockfd );
+ osrfLogDebug("Socket is active: %d", sockfd );
numhandled++;
osrfRouterClassHandleIncoming( router, classname, class );
}
if(osrfStringArrayContains( router->trustedServers, domain))
osrfRouterHandleMessage( router, msg );
else
- warning_handler("Received message from un-trusted server domain %s", msg->sender);
+ osrfLogWarning("Received message from un-trusted server domain %s", msg->sender);
}
message_free(msg);
if(!(router && class)) return -1;
transport_message* msg;
- debug_handler("osrfRouterClassHandleIncoming()");
+ osrfLogDebug("osrfRouterClassHandleIncoming()");
if( (msg = client_recv( class->connection, 0 )) ) {
osrfRouterClassHandleMessage( router, class, msg );
} else {
- warning_handler("Received client message from untrusted client domain %s", domain );
+ osrfLogWarning("Received client message from untrusted client domain %s", domain );
}
}
if(!strcmp(msg->router_command, ROUTER_REGISTER)) {
class = osrfRouterFindClass( router, msg->router_class );
- info_handler("Registering class %s", msg->router_class );
+ osrfLogInfo("Registering class %s", msg->router_class );
if(!class) class = osrfRouterAddClass( router, msg->router_class );
} else if( !strcmp( msg->router_command, ROUTER_UNREGISTER ) ) {
if( msg->router_class && strcmp( msg->router_class, "") ) {
- info_handler("Unregistering router class %s", msg->router_class );
+ osrfLogInfo("Unregistering router class %s", msg->router_class );
osrfRouterClassRemoveNode( router, msg->router_class, msg->sender );
}
}
int osrfRouterClassAddNode( osrfRouterClass* rclass, char* remoteId ) {
if(!(rclass && rclass->nodes && remoteId)) return -1;
- info_handler("Adding router node for remote id %s", remoteId );
+ osrfLogInfo("Adding router node for remote id %s", remoteId );
osrfRouterNode* node = safe_malloc(sizeof(osrfRouterNode));
node->count = 0;
transport_message* osrfRouterClassHandleBounce(
osrfRouter* router, char* classname, osrfRouterClass* rclass, transport_message* msg ) {
- debug_handler("osrfRouterClassHandleBounce()");
+ osrfLogDebug("osrfRouterClassHandleBounce()");
- warning_handler("Received network layer error message from %s", msg->sender );
+ osrfLogWarning("Received network layer error message from %s", msg->sender );
osrfRouterNode* node = osrfRouterClassFindNode( rclass, msg->sender );
transport_message* lastSent = NULL;
if( node && osrfHashGetCount(rclass->nodes) == 1 ) { /* the last node is dead */
if( node->lastMessage ) {
- warning_handler("We lost the last node in the class, responding with error and removing...");
+ osrfLogWarning("We lost the last node in the class, responding with error and removing...");
transport_message* error = message_init(
node->lastMessage->body, node->lastMessage->subject,
} else {
if( node->lastMessage ) {
- debug_handler("Cloning lastMessage so next node can send it");
+ osrfLogDebug("Cloning lastMessage so next node can send it");
lastSent = message_init( node->lastMessage->body,
node->lastMessage->subject, node->lastMessage->thread, "", node->lastMessage->router_from );
message_set_router_info( lastSent, node->lastMessage->router_from, NULL, NULL, NULL, 0 );
osrfRouter* router, osrfRouterClass* rclass, transport_message* msg ) {
if(!(router && rclass && msg)) return -1;
- debug_handler("osrfRouterClassHandleMessage()");
+ osrfLogDebug("osrfRouterClassHandleMessage()");
osrfRouterNode* node = osrfHashIteratorNext( rclass->itr );
if(!node) {
msg->subject, msg->thread, node->remoteId, msg->sender );
message_set_router_info( new_msg, msg->sender, NULL, NULL, NULL, 0 );
- info_handler( "Routing message:\nfrom: [%s]\nto: [%s]",
+ osrfLogInfo( "Routing message:\nfrom: [%s]\nto: [%s]",
new_msg->router_from, new_msg->recipient );
message_free( node->lastMessage );
else {
message_prepare_xml(new_msg);
- warning_handler("Error sending message from %s to %s\n%s",
+ osrfLogWarning("Error sending message from %s to %s\n%s",
new_msg->sender, new_msg->recipient, new_msg->msg_xml );
}
int osrfRouterRemoveClass( osrfRouter* router, char* classname ) {
if(!(router && router->classes && classname)) return -1;
- info_handler("Removing router class %s", classname );
+ osrfLogInfo("Removing router class %s", classname );
osrfHashRemove( router->classes, classname );
return 0;
}
if(!(router && router->classes && classname && remoteId)) return 0;
- info_handler("Removing router node %s", remoteId );
+ osrfLogInfo("Removing router node %s", remoteId );
osrfRouterClass* class = osrfRouterFindClass( router, classname );
osrfMessage* success = osrf_message_init( STATUS, omsg->thread_trace, omsg->protocol );
- debug_handler("router recevied a CONNECT message from %s", msg->sender );
+ osrfLogDebug("router recevied a CONNECT message from %s", msg->sender );
osrf_message_set_status_info(
success, "osrfConnectStatus", "Connection Successful", OSRF_STATUS_OK );
if(!(router && msg && omsg && omsg->method_name)) return -1;
- info_handler("Router received app request: %s", omsg->method_name );
+ osrfLogInfo("Router received app request: %s", omsg->method_name );
jsonObject* jresponse = NULL;
if(!strcmp( omsg->method_name, ROUTER_REQUEST_CLASS_LIST )) {
osrf_message_set_result_content( oresponse, json);
char* data = osrf_message_serialize(oresponse);
- debug_handler( "Responding to client app request with data: \n%s\n", data );
+ osrfLogDebug( "Responding to client app request with data: \n%s\n", data );
transport_message* tresponse = message_init(
data, "", msg->thread, msg->sender, msg->recipient );
#include <stdio.h>
#include "opensrf/utils.h"
+#include "opensrf/log.h"
#include "opensrf/osrf_list.h"
#include "opensrf/osrf_hash.h"
#include "osrf_router.h"
#include "opensrf/osrfConfig.h"
#include "opensrf/utils.h"
-#include "opensrf/logging.h"
+#include "opensrf/log.h"
#include <signal.h>
osrfRouter* __osrfRouter = NULL;
void routerSignalHandler( int signal ) {
- warning_handler("Received signal [%d], cleaning up...", signal );
+ osrfLogWarning("Received signal [%d], cleaning up...", signal );
osrfConfigCleanup();
osrfRouterFree(__osrfRouter);
- log_free();
}
static int __setupRouter( char* config, char* context );
int main( int argc, char* argv[] ) {
if( argc < 3 ) {
- fatal_handler( "Usage: %s <path_to_config_file> <config_context>", argv[0] );
+ osrfLogError( "Usage: %s <path_to_config_file> <config_context>", argv[0] );
exit(0);
}
int llevel = 1;
if(level) llevel = atoi(level);
+ /*
if(!log_init( llevel, log_file ))
fprintf(stderr, "Unable to init logging, going to stderr...\n" );
+ */
+
+ osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "router", llevel ); /* XXX config option */
+ osrfLogSetSyslogFacility( LOG_LOCAL3 ); /* XXX config option */
free(level);
free(log_file);
- info_handler( "Router connecting as: server: %s port: %s "
+ osrfLogInfo( "Router connecting as: server: %s port: %s "
"user: %s resource: %s", server, port, username, resource );
int iport = 0;
int i;
for( i = 0; i != tservers->size; i++ )
- info_handler( "Router adding trusted server: %s", osrfStringArrayGetString( tservers, i ) );
+ osrfLogInfo( "Router adding trusted server: %s", osrfStringArrayGetString( tservers, i ) );
for( i = 0; i != tclients->size; i++ )
- info_handler( "Router adding trusted client: %s", osrfStringArrayGetString( tclients, i ) );
+ osrfLogInfo( "Router adding trusted client: %s", osrfStringArrayGetString( tclients, i ) );
- if( tclients->size == 0 || tservers->size == 0 )
- fatal_handler("We need trusted servers and trusted client to run the router...");
+ if( tclients->size == 0 || tservers->size == 0 ) {
+ osrfLogError("We need trusted servers and trusted client to run the router...");
+ return -1;
+ }
osrfRouter* router = osrfNewRouter( server,
username, resource, password, iport, tclients, tservers );
char fbuf[l];
memset(fbuf, 0, l);
sprintf(fbuf,"%s/.srfsh.xml",home);
+
+ //osrfLogInit( OSRF_LOG_TYPE_SYSLOG, "srfsh",
if(!access(fbuf, R_OK)) {
- if( ! osrf_system_bootstrap_client(fbuf, "srfsh") )
- fatal_handler( "Unable to bootstrap client for requests");
+ if( ! osrf_system_bootstrap_client(fbuf, "srfsh") ) {
+ osrfLogError( "Unable to bootstrap client for requests");
+ return -1;
+ }
} else {
- fatal_handler( "No Config file found at %s", fbuf );
+ osrfLogError( "No Config file found at %s", fbuf );
+ return -1;
}
if(argc > 1) {
/* for now.. the first arg is used as a script file for processing */
int f;
- if( (f = open(argv[1], O_RDONLY)) == -1 )
- fatal_handler("Unable to open file %s for reading, exiting...", argv[1]);
+ if( (f = open(argv[1], O_RDONLY)) == -1 ) {
+ osrfLogError("Unable to open file %s for reading, exiting...", argv[1]);
+ return -1;
+ }
- if(dup2(f, STDIN_FILENO) == -1)
- fatal_handler("Unable to duplicate STDIN, exiting...");
+ if(dup2(f, STDIN_FILENO) == -1) {
+ osrfLogError("Unable to duplicate STDIN, exiting...");
+ return -1;
+ }
close(f);
is_from_script = 1;
if( !strcmp(words[0],"router") )
ret_val = handle_router( words );
+ /*
else if( !strcmp(words[0],"time") )
ret_val = handle_time( words );
+ */
else if (!strcmp(words[0],"request"))
ret_val = handle_request( words, 0 );
osrf_app_session* session = osrf_app_client_session_init(server);
if(!osrf_app_session_connect(session)) {
- warning_handler( "Unable to connect to remote service %s\n", server );
+ osrfLogWarning( "Unable to connect to remote service %s\n", server );
return 1;
}
}
+/*
int handle_time( char* words[] ) {
if( ! words[1] ) {
return 0;
}
+*/
#include <sys/wait.h>
#include "utils.h"
-#include "logging.h"
+#include "log.h"
#include <signal.h>
-UTIL_HEADERS = md5.h logging.h utils.h socket_bundle.h sha.h string_array.h xml_utils.h
-UTIL_OBJECTS = md5.o logging.o utils.o socket_bundle.o sha.o string_array.o
+UTIL_HEADERS = md5.h log.h utils.h socket_bundle.h sha.h string_array.h xml_utils.h
+UTIL_OBJECTS = md5.o log.o utils.o socket_bundle.o sha.o string_array.o
all: $(UTIL_OBJECTS) copy
copy:
cp $(UTIL_HEADERS) $(TMPDIR)
-logging.o: logging.c logging.h
+log.o: log.c log.h
utils.o: utils.c utils.h
socket_bundle.o: socket_bundle.c socket_bundle.h
md5.o: md5.c md5.h
--- /dev/null
+#include "log.h"
+
+int __osrfLogType = -1;
+int __osrfLogFacility = LOG_LOCAL0;
+int __osrfLogActFacility = LOG_LOCAL1;
+char* __osrfLogFile = NULL;
+char* __osrfLogAppname = NULL;
+int __osrfLogLevel = OSRF_LOG_INFO;
+int __osrfLogActivityEnabled = 1;
+
+
+void osrfLogInit( int type, const char* appname, int maxlevel ) {
+ osrfLogSetType(type);
+ if(appname) osrfLogSetAppname(appname);
+ osrfLogSetLevel(maxlevel);
+ if( type == OSRF_LOG_TYPE_SYSLOG )
+ openlog(__osrfLogAppname, 0, __osrfLogFacility );
+}
+
+void osrfLogSetType( int logtype ) {
+ if( logtype != OSRF_LOG_TYPE_FILE &&
+ logtype != OSRF_LOG_TYPE_SYSLOG ) {
+ fprintf(stderr, "Unrecognized log type. Logging to stderr\n");
+ return;
+ }
+ __osrfLogType = logtype;
+}
+
+void osrfLogSetFile( const char* logfile ) {
+ if(!logfile) return;
+ if(__osrfLogFile) free(__osrfLogFile);
+ __osrfLogFile = strdup(logfile);
+}
+
+void osrfLogSetActivityEnabled( int enabled ) {
+ __osrfLogActivityEnabled = enabled;
+}
+
+void osrfLogSetAppname( const char* appname ) {
+ if(!appname) return;
+ if(__osrfLogAppname) free(__osrfLogAppname);
+ __osrfLogAppname = strdup(appname);
+
+ /* if syslogging, re-open the log with the appname */
+ if( __osrfLogType == OSRF_LOG_TYPE_SYSLOG) {
+ closelog();
+ openlog(__osrfLogAppname, 0, __osrfLogFacility);
+ }
+}
+
+void osrfLogSetSyslogFacility( int facility ) {
+ __osrfLogFacility = facility;
+}
+void osrfLogSetSyslogActFacility( int facility ) {
+ __osrfLogActFacility = facility;
+}
+
+void osrfLogSetLevel( int loglevel ) {
+ __osrfLogLevel = loglevel;
+}
+
+void osrfLogError( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_ERROR); }
+void osrfLogWarning( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_WARNING); }
+void osrfLogInfo( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_INFO); }
+void osrfLogDebug( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_DEBUG); }
+void osrfLogInternal( const char* msg, ... ) { OSRF_LOG_GO(msg, OSRF_LOG_DEBUG); }
+void osrfLogActivity( const char* msg, ... ) {
+ OSRF_LOG_GO(msg, OSRF_LOG_ACTIVITY);
+ /* activity log entries are also logged as info intries */
+ osrfLogDetail( OSRF_LOG_INFO, NULL, -1, NULL, VA_BUF );
+}
+
+void osrfLogDetail( int level, char* filename, int line, char* func, char* msg, ... ) {
+
+ if( level == OSRF_LOG_ACTIVITY && ! __osrfLogActivityEnabled ) return;
+ if( level > __osrfLogLevel ) return;
+ if(!msg) return;
+ if(!filename) filename = "";
+ if(!func) func = "";
+
+ char lb[8];
+ bzero(lb,8);
+ if(line >= 0) snprintf(lb,8,"%d", line);
+
+ char* l = "INFO"; /* level name */
+ int lvl = LOG_INFO; /* syslog level */
+ int fac = __osrfLogFacility;
+
+ switch( level ) {
+ case OSRF_LOG_ERROR:
+ l = "ERR ";
+ lvl = LOG_ERR;
+ break;
+
+ case OSRF_LOG_WARNING:
+ l = "WARN";
+ lvl = LOG_WARNING;
+ break;
+
+ case OSRF_LOG_INFO:
+ l = "INFO";
+ lvl = LOG_INFO;
+ break;
+
+ case OSRF_LOG_DEBUG:
+ l = "DEBG";
+ lvl = LOG_DEBUG;
+ break;
+
+ case OSRF_LOG_INTERNAL:
+ l = "INT ";
+ lvl = LOG_DEBUG;
+ break;
+
+ case OSRF_LOG_ACTIVITY:
+ l = "ACT";
+ lvl = LOG_INFO;
+ fac = __osrfLogActFacility;
+ break;
+ }
+
+ VA_LIST_TO_STRING(msg);
+
+ if(__osrfLogType == OSRF_LOG_TYPE_SYSLOG )
+ syslog( fac | lvl, "[%s:%d:%s:%s:%s] %s", l, getpid(), filename, lb, func, VA_BUF );
+
+ else if( __osrfLogType == OSRF_LOG_TYPE_FILE )
+ _osrfLogToFile("[%s:%d:%s:%d:%s] %s", l, getpid(), filename, lb, func, VA_BUF );
+}
+
+
+void _osrfLogToFile( char* msg, ... ) {
+
+ if(!msg) return;
+ if(!__osrfLogFile) return;
+ VA_LIST_TO_STRING(msg);
+
+ if(!__osrfLogAppname) __osrfLogAppname = strdup("osrf");
+ int l = strlen(VA_BUF) + strlen(__osrfLogAppname) + 24;
+ char buf[l];
+ bzero(buf,l);
+
+ char datebuf[24];
+ bzero(datebuf,24);
+ time_t t = time(NULL);
+ struct tm* tms = localtime(&t);
+ strftime(datebuf, 24, "%Y-%m-%d %h:%m:%s", tms);
+
+ FILE* file = fopen(__osrfLogFile, "a");
+ if(!file) {
+ fprintf(stderr, "Unable to fopen file %s for writing", __osrfLogFile);
+ return;
+ }
+
+ fprintf(file, "%s %s %s\n", __osrfLogAppname, datebuf, VA_BUF );
+ fclose(file);
+}
+
+
+int osrfLogFacilityToInt( char* facility ) {
+ if(!facility) return -1;
+ if(strlen(facility) < 6) return -1;
+ switch( facility[5] ) {
+ case 0: return LOG_LOCAL0;
+ case 1: return LOG_LOCAL1;
+ case 2: return LOG_LOCAL2;
+ case 3: return LOG_LOCAL3;
+ case 4: return LOG_LOCAL4;
+ case 5: return LOG_LOCAL5;
+ case 6: return LOG_LOCAL6;
+ case 7: return LOG_LOCAL7;
+ }
+ return -1;
+}
+
+
--- /dev/null
+#include <syslog.h>
+#include <stdio.h>
+#include "utils.h"
+#include <time.h>
+
+#ifndef OSRF_LOG_INCLUDED
+#define OSRF_LOG_INCLUDED
+
+/* log levels */
+#define OSRF_LOG_ERROR 1
+#define OSRF_LOG_WARNING 2
+#define OSRF_LOG_INFO 3
+#define OSRF_LOG_DEBUG 4
+#define OSRF_LOG_INTERNAL 5
+#define OSRF_LOG_ACTIVITY -1
+
+#define OSRF_LOG_TYPE_FILE 1
+#define OSRF_LOG_TYPE_SYSLOG 2
+
+
+#define OSRF_LOG_GO(m,l) \
+ if(!m) return; \
+ VA_LIST_TO_STRING(m); \
+ osrfLogDetail( l, NULL, -1, NULL, VA_BUF );
+
+
+
+/* Initializes the logger. */
+void osrfLogInit( int type, const char* appname, int maxlevel );
+/** Sets the type of logging to perform. See log types */
+void osrfLogSetType( int logtype );
+/** Sets the systlog facility for the regular logs */
+void osrfLogSetSyslogFacility( int facility );
+/** Sets the systlog facility for the activity logs */
+void osrfLogSetSyslogActFacility( int facility );
+/** Sets the log file to use if we're logging to a file */
+void osrfLogSetFile( const char* logfile );
+/* once we know which application we're running, call this method to
+ * set the appname so log lines can include the app name */
+void osrfLogSetAppname( const char* appname );
+/** Sets the global log level. Any log statements with a higher level
+ * than "level" will not be logged */
+void osrfLogSetLevel( int loglevel );
+/* Log an error message */
+void osrfLogError( const char* msg, ... );
+/* Log a warning message */
+void osrfLogWarning( const char* msg, ... );
+/* log an info message */
+void osrfLogInfo( const char* msg, ... );
+/* Log a debug message */
+void osrfLogDebug( const char* msg, ... );
+/* Log an internal debug message */
+void osrfLogInternal( const char* msg, ... );
+/* Log an activity message */
+void osrfLogActivity( const char* msg, ... );
+
+void osrfLogSetActivityEnabled( int enabled );
+
+/* Use this for logging detailed message containing the filename, line number
+ * and function name in addition to the usual level and message */
+void osrfLogDetail( int level, char* filename, int line, char* func, char* msg, ... );
+
+void _osrfLogToFile( char* msg, ... );
+
+int osrfLogFacilityToInt( char* facility );
+
+#endif
va_list args;
if( logging ) {
- if( log_level < LOG_ERROR )
+ if( log_level < OSRF_LOG_ERROR )
return -1;
log_file = fopen( lf, "a" );
pid_t pid = getpid();
va_list args;
- if( log_level < LOG_WARNING )
+ if( log_level < OSRF_LOG_WARNING )
return -1;
if(logging) {
pid_t pid = getpid();
va_list args;
- if( log_level < LOG_INFO )
+ if( log_level < OSRF_LOG_INFO )
return -1;
if(logging) {
pid_t pid = getpid();
va_list args;
- if( log_level < LOG_DEBUG )
+ if( log_level < OSRF_LOG_DEBUG )
return -1;
if(logging) {
#define LOGGING_H
-#define LOG_ERROR 1
-#define LOG_WARNING 2
-#define LOG_INFO 3
-#define LOG_DEBUG 4
+#define OSRF_LOG_ERROR 1
+#define OSRF_LOG_WARNING 2
+#define OSRF_LOG_INFO 3
+#define OSRF_LOG_DEBUG 4
+#define OSRF_LOG_INTERNAL 5
+#define OSRF_LOG_ACTIVITY 6
// ---------------------------------------------------------------------------------
// Error handling interface.
/*
-int debug_handler(char* msg, ...) {
+int osrfLogDebug(char* msg, ...) {
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
return -1;
}
-int warning_handler(char* msg, ...) {
+int osrfLogWarning(char* msg, ...) {
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
int endpoint, int addr_type, int sock_fd, int parent_id ) {
if(mgr == NULL) return NULL;
- debug_handler("Adding socket node with fd %d", sock_fd);
+ osrfLogDebug("Adding socket node with fd %d", sock_fd);
socket_node* new_node = safe_malloc(sizeof(socket_node));
new_node->endpoint = endpoint;
socket_type is one of INET or UNIX */
int socket_open_tcp_server(socket_manager* mgr, int port, char* listen_ip) {
- if( mgr == NULL ) return warning_handler("socket_open_tcp_server(): NULL mgr");
+ if( mgr == NULL ) {
+ osrfLogWarning("socket_open_tcp_server(): NULL mgr");
+ return -1;
+ }
int sock_fd;
struct sockaddr_in server_addr;
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
- if(sock_fd < 0)
- return warning_handler("tcp_server_connect(): Unable to create socket");
+ if(sock_fd < 0) {
+ osrfLogWarning("tcp_server_connect(): Unable to create socket");
+ return -1;
+ }
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
- if(bind( sock_fd, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0)
- return warning_handler("tcp_server_connect(): cannot bind to port %d", port );
+ if(bind( sock_fd, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0) {
+ osrfLogWarning("tcp_server_connect(): cannot bind to port %d", port );
+ return -1;
+ }
- if(listen(sock_fd, 20) == -1)
- return warning_handler("tcp_server_connect(): listen() returned error");
+ if(listen(sock_fd, 20) == -1) {
+ osrfLogWarning("tcp_server_connect(): listen() returned error");
+ return -1;
+ }
_socket_add_node(mgr, SERVER_SOCKET, INET, sock_fd, 0);
return sock_fd;
int socket_open_unix_server(socket_manager* mgr, char* path) {
if(mgr == NULL || path == NULL) return -1;
- debug_handler("opening unix socket at %s", path);
+ osrfLogDebug("opening unix socket at %s", path);
int sock_fd;
struct sockaddr_un server_addr;
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if(sock_fd < 0)
- return warning_handler("socket_open_unix_server(): socket() failed");
+ if(sock_fd < 0){
+ osrfLogWarning("socket_open_unix_server(): socket() failed");
+ return -1;
+ }
server_addr.sun_family = AF_UNIX;
strcpy(server_addr.sun_path, path);
if( bind(sock_fd, (struct sockaddr*) &server_addr,
sizeof(struct sockaddr_un)) < 0) {
- return warning_handler(
+ osrfLogWarning(
"socket_open_unix_server(): cannot bind to unix port %s", path );
+ return -1;
}
- if(listen(sock_fd, 20) == -1)
- return warning_handler("socket_open_unix_server(): listen() returned error");
+ if(listen(sock_fd, 20) == -1) {
+ osrfLogWarning("socket_open_unix_server(): listen() returned error");
+ return -1;
+ }
- debug_handler("unix socket successfully opened");
+ osrfLogDebug("unix socket successfully opened");
int i = 1;
/* causing problems with router for some reason ... */
- //debug_handler("Setting SO_REUSEADDR");
+ //osrfLogDebug("Setting SO_REUSEADDR");
//setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
- debug_handler("Setting TCP_NODELAY");
+ osrfLogDebug("Setting TCP_NODELAY");
setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, &i, sizeof(i));
_socket_add_node(mgr, SERVER_SOCKET, UNIX, sock_fd, 0);
}
+
+int socket_open_udp_server(
+ socket_manager* mgr, int port, char* listen_ip ) {
+
+ int sockfd;
+ struct sockaddr_in server_addr;
+
+ if( (sockfd = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) {
+ osrfLogWarning("Unable to create UDP socket");
+ return -1;
+ }
+
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = htons(port);
+ if(listen_ip) server_addr.sin_addr.s_addr = inet_addr(listen_ip);
+ else server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ if( (bind (sockfd, (struct sockaddr *) &server_addr,sizeof(server_addr))) ) {
+ osrfLogWarning("Unable to bind to UDP port %d", port);
+ return -1;
+ }
+
+ _socket_add_node(mgr, SERVER_SOCKET, INET, sockfd, 0);
+ return sockfd;
+}
+
+
int socket_open_tcp_client(socket_manager* mgr, int port, char* dest_addr) {
struct sockaddr_in remoteAddr, localAddr;
// Create the socket
// ------------------------------------------------------------------
if( (sock_fd = socket( AF_INET, SOCK_STREAM, 0 )) < 0 ) {
- warning_handler( "tcp_connect(): Cannot create socket" );
+ osrfLogWarning( "tcp_connect(): Cannot create socket" );
return -1;
}
int i = 1;
- debug_handler("Setting TCP_NODELAY");
+ osrfLogDebug("Setting TCP_NODELAY");
setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, &i, sizeof(i));
// Get the hostname
// ------------------------------------------------------------------
if( (hptr = gethostbyname( dest_addr ) ) == NULL ) {
- warning_handler( "tcp_connect(): Unknown Host => %s", dest_addr );
+ osrfLogWarning( "tcp_connect(): Unknown Host => %s", dest_addr );
return -1;
}
// Bind to a local port
// ------------------------------------------------------------------
if( bind( sock_fd, (struct sockaddr *) &localAddr, sizeof( localAddr ) ) < 0 ) {
- warning_handler( "tcp_connect(): Cannot bind to local port" );
+ osrfLogWarning( "tcp_connect(): Cannot bind to local port" );
return -1;
}
// Connect to server
// ------------------------------------------------------------------
if( connect( sock_fd, (struct sockaddr*) &remoteAddr, sizeof( struct sockaddr_in ) ) < 0 ) {
- warning_handler( "tcp_connect(): Cannot connect to server %s", dest_addr );
+ osrfLogWarning( "tcp_connect(): Cannot connect to server %s", dest_addr );
return -1;
}
}
+int socket_open_udp_client(
+ socket_manager* mgr, int port, char* dest_addr) {
+
+ int sockfd;
+ struct sockaddr_in client_addr, server_addr;
+ struct hostent* host;
+
+ if( (host = gethostbyname(dest_addr)) == NULL) {
+ osrfLogWarning("Unable to resolve host: %s", dest_addr);
+ return -1;
+ }
+
+ server_addr.sin_family = host->h_addrtype;
+ memcpy((char *) &server_addr.sin_addr.s_addr,
+ host->h_addr_list[0], host->h_length);
+ server_addr.sin_port = htons(port);
+
+ if( (sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0 ) {
+ osrfLogWarning("Unable to create UDP socket");
+ return -1;
+ }
+
+ client_addr.sin_family = AF_INET;
+ client_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ client_addr.sin_port = htons(0);
+
+ if( (bind(sockfd, (struct sockaddr *) &client_addr, sizeof(client_addr))) < 0 ) {
+ osrfLogWarning("Unable to bind UDP socket");
+ return -1;
+ }
+
+ _socket_add_node(mgr, CLIENT_SOCKET, INET, sockfd, -1 );
+
+ return sockfd;
+}
+
+
int socket_open_unix_client(socket_manager* mgr, char* sock_path) {
int sock_fd, len;
struct sockaddr_un usock;
- if( (sock_fd = socket( AF_UNIX, SOCK_STREAM, 0 )) < 0 )
- return warning_handler( "Cannot create socket" );
+ if( (sock_fd = socket( AF_UNIX, SOCK_STREAM, 0 )) < 0 ) {
+ osrfLogWarning( "Cannot create socket" );
+ return -1;
+ }
usock.sun_family = AF_UNIX;
strcpy( usock.sun_path, sock_path );
len = sizeof( usock.sun_family ) + strlen( usock.sun_path );
- if( connect( sock_fd, (struct sockaddr *) &usock, len ) < 0 )
- return warning_handler( "Error connecting to unix socket" );
+ if( connect( sock_fd, (struct sockaddr *) &usock, len ) < 0 ) {
+ osrfLogWarning( "Error connecting to unix socket" );
+ return -1;
+ }
_socket_add_node(mgr, CLIENT_SOCKET, UNIX, sock_fd, -1 );
if(mgr == NULL) return;
- debug_handler("removing socket %d", sock_fd);
+ osrfLogDebug("removing socket %d", sock_fd);
socket_node* head = mgr->socket;
socket_node* tail = head;
if(head->sock_fd == sock_fd) {
mgr->socket = head->next;
free(head);
- debug_handler("removing first socket in list");
+ osrfLogDebug("removing first socket in list");
return;
}
void _socket_print_list(socket_manager* mgr) {
if(mgr == NULL) return;
socket_node* node = mgr->socket;
- debug_handler("socket_node list: [");
+ osrfLogDebug("socket_node list: [");
while(node) {
- debug_handler("sock_fd: %d | parent_id: %d",
+ osrfLogDebug("sock_fd: %d | parent_id: %d",
node->sock_fd, node->parent_id);
node = node->next;
}
- debug_handler("]");
+ osrfLogDebug("]");
}
/* sends the given data to the given socket */
int socket_send(int sock_fd, const char* data) {
- debug_handler( "socket_bundle sending to %d data %s",
+ osrfLogDebug( "socket_bundle sending to %d data %s",
sock_fd, data);
- debug_handler("%d : Sending data at %lf\n", getpid(), get_timestamp_millis());
+ osrfLogDebug("%d : Sending data at %lf\n", getpid(), get_timestamp_millis());
signal(SIGPIPE, SIG_IGN); /* in case a unix socket was closed */
if( send( sock_fd, data, strlen(data), 0 ) < 0 ) {
- return warning_handler( "tcp_server_send(): Error sending data" );
+ osrfLogWarning( "tcp_server_send(): Error sending data" );
+ return -1;
}
return 0;
it from the socket set */
void socket_disconnect(socket_manager* mgr, int sock_fd) {
- debug_handler("Closing socket %d", sock_fd);
+ osrfLogDebug("Closing socket %d", sock_fd);
if( shutdown( sock_fd, SHUT_RDWR ) )
- warning_handler( "socket_disconnect(): Error shuting down socket, removing anyway" );
+ osrfLogWarning( "socket_disconnect(): Error shuting down socket, removing anyway" );
if( close( sock_fd ) == -1 )
- warning_handler( "socket_disconnect(): Error closing socket, removing anyway" );
+ osrfLogWarning( "socket_disconnect(): Error closing socket, removing anyway" );
if(mgr != NULL)
socket_remove_node(mgr, sock_fd);
// If timeout is -1, we block indefinitely
if( (retval = select( sock_fd + 1, &read_set, NULL, NULL, NULL)) == -1 ) {
- warning_handler("Sys Error: %s", strerror(errno));
- return warning_handler("Call to select interrupted");
+ osrfLogWarning("Sys Error: %s", strerror(errno));
+ osrfLogWarning("Call to select interrupted");
+ return -1;
}
} else if( timeout > 0 ) { /* timeout of 0 means don't block */
if( (retval = select( sock_fd + 1, &read_set, NULL, NULL, &tv)) == -1 ) {
- warning_handler("Sys Error: %s", strerror(errno));
- return warning_handler( "Call to select interrupted" );
+ osrfLogWarning("Sys Error: %s", strerror(errno));
+ osrfLogWarning( "Call to select interrupted" );
+ return -1;
}
}
- debug_handler("%d active sockets after select()", retval);
+ osrfLogDebug("%d active sockets after select()", retval);
return _socket_route_data_id(mgr, sock_fd);
}
int socket_wait_all(socket_manager* mgr, int timeout) {
- if(mgr == NULL) return warning_handler( "tcp_wait(): null mgr" );
+ if(mgr == NULL) {
+ osrfLogWarning( "tcp_wait(): null mgr" );
+ return -1;
+ }
int retval = 0;
fd_set read_set;
socket_node* node = mgr->socket;
int max_fd = 0;
while(node) {
- //debug_handler("Adding socket %d to select set",node->sock_fd);
+ //osrfLogDebug("Adding socket %d to select set",node->sock_fd);
FD_SET( node->sock_fd, &read_set );
if(node->sock_fd > max_fd) max_fd = node->sock_fd;
node = node->next;
// If timeout is -1, there is no timeout passed to the call to select
if( (retval = select( max_fd, &read_set, NULL, NULL, NULL)) == -1 ) {
- warning_handler("Sys Error: %s", strerror(errno));
- return warning_handler("Call to select interrupted");
+ osrfLogWarning("Sys Error: %s", strerror(errno));
+ osrfLogWarning("Call to select interrupted");
+ return -1;
}
} else if( timeout != 0 ) { /* timeout of 0 means don't block */
if( (retval = select( max_fd, &read_set, NULL, NULL, &tv)) == -1 ) {
- warning_handler("Sys Error: %s", strerror(errno));
- return warning_handler( "Call to select interrupted" );
+ osrfLogWarning("Sys Error: %s", strerror(errno));
+ osrfLogWarning( "Call to select interrupted" );
+ return -1;
}
}
- debug_handler("%d active sockets after select()", retval);
+ osrfLogDebug("%d active sockets after select()", retval);
return _socket_route_data(mgr, retval, &read_set);
}
if(last_failed_id != -1) {
/* in case it was not removed by our overlords */
- debug_handler("Attempting to remove last_failed_id of %d", last_failed_id);
+ osrfLogDebug("Attempting to remove last_failed_id of %d", last_failed_id);
socket_remove_node( mgr, last_failed_id );
last_failed_id = -1;
status = -1;
/* does this socket have data? */
if( FD_ISSET( sock_fd, read_set ) ) {
- debug_handler("Socket %d active", sock_fd);
+ osrfLogDebug("Socket %d active", sock_fd);
handled++;
FD_CLR(sock_fd, read_set);
us...start over with the first socket */
if(status == -1) {
last_failed_id = sock_fd;
- debug_handler("Backtracking back to start of loop because "
+ osrfLogDebug("Backtracking back to start of loop because "
"of -1 return code from _socket_handle_client_data()");
}
}
int new_sock_fd;
new_sock_fd = accept(node->sock_fd, NULL, NULL);
- if(new_sock_fd < 0)
- return warning_handler("_socket_route_data(): accept() failed");
+ if(new_sock_fd < 0) {
+ osrfLogWarning("_socket_route_data(): accept() failed");
+ return -1;
+ }
if(node->addr_type == INET) {
_socket_add_node(mgr, CLIENT_SOCKET, INET, new_sock_fd, node->sock_fd);
- debug_handler("Adding new INET client for %d", node->sock_fd);
+ osrfLogDebug("Adding new INET client for %d", node->sock_fd);
} else if(node->addr_type == UNIX) {
_socket_add_node(mgr, CLIENT_SOCKET, UNIX, new_sock_fd, node->sock_fd);
- debug_handler("Adding new UNIX client for %d", node->sock_fd);
+ osrfLogDebug("Adding new UNIX client for %d", node->sock_fd);
}
return 0;
memset(buf, 0, RBUFSIZE);
set_fl(sock_fd, O_NONBLOCK);
- debug_handler("Gathering client data for %d", node->sock_fd);
+ osrfLogDebug("Gathering client data for %d", node->sock_fd);
- debug_handler("%d : Received data at %lf\n", getpid(), get_timestamp_millis());
+ osrfLogDebug("%d : Received data at %lf\n", getpid(), get_timestamp_millis());
while( (read_bytes = recv(sock_fd, buf, RBUFSIZE-1, 0) ) > 0 ) {
- debug_handler("Socket %d Read %d bytes and data: %s", sock_fd, read_bytes, buf);
+ osrfLogDebug("Socket %d Read %d bytes and data: %s", sock_fd, read_bytes, buf);
if(mgr->data_received)
mgr->data_received(mgr->blob, mgr, sock_fd, buf, node->parent_id);
clr_fl(sock_fd, O_NONBLOCK);
if(read_bytes < 0) {
if( errno != EAGAIN )
- warning_handler( " * Error reading socket with errno %d", errno );
+ osrfLogWarning( " * Error reading socket with errno %d", errno );
}
} else { return -1; } /* inform the caller that this node has been tampered with */
#include <errno.h>
#include "utils.h"
-#include "logging.h"
+#include "log.h"
//---------------------------------------------------------------
// Unix headers
int socket_open_unix_server(socket_manager* mgr, char* path);
+int socket_open_udp_server( socket_manager* mgr, int port, char* listen_ip );
+
/* creates a client TCP socket and adds it to the socket set.
returns 0 on success. -1 on failure. */
int socket_open_tcp_client(socket_manager*, int port, char* dest_addr);
returns 0 on success. -1 on failure. */
int socket_open_unix_client(socket_manager*, char* sock_path);
+int socket_open_udp_client( socket_manager* mgr, int port, char* dest_addr);
+
/* returns the socket_node with the given sock_fd */
socket_node* socket_find_node(socket_manager*, int sock_fd);
string_array* init_string_array(int size) {
if(size > STRING_ARRAY_MAX_SIZE)
- fatal_handler("init_string_array size is too large");
+ osrfLogError("init_string_array size is too large");
string_array* arr =
(string_array*) safe_malloc(sizeof(string_array));
arr->size++;
if( arr->size > STRING_ARRAY_MAX_SIZE )
- fatal_handler("string_array_add size is too large");
+ osrfLogError("string_array_add size is too large");
/* if necessary, double capacity */
if(arr->size >= arr->arr_size) {
#include <stdio.h>
#include "utils.h"
-#include "logging.h"
+#include "log.h"
#define STRING_ARRAY_MAX_SIZE 1024