export INCLUDEDIR = $(PREFIX)/include
export LDLIBS +=
-export LDFLAGS += -L $(TMPDIR) -L .
+export LDFLAGS += -L $(TMPDIR) -L . -L /opt/lib
export CFLAGS += -g -Wall -O2 -fPIC -I$(LIBXML2_HEADERS) -I$(APACHE2_HEADERS) \
-I$(LIBXML2_HEADERS)/libxml -I$(TMP) -I$(TMPDIR)
libstack/osrf_application.o \
libstack/osrf_cache.o \
libstack/xml_utils.o \
+ libstack/osrf_log.o \
utils/socket_bundle.o \
utils/string_array.o \
utils/utils.o \
libstack/osrf_application.h \
libstack/osrf_cache.h \
libstack/xml_utils.h \
+ libstack/osrf_log.h \
utils/socket_bundle.h \
utils/string_array.h \
utils/utils.h \
LDLIBS += -lobjson -lopensrf
+CFLAGS += -DOSRF_LOG_PARAMS
-
-all: osrf_math.so osrf_dbmath.so
+all: osrf_math.so osrf_dbmath.so osrf_version.so
osrf_math.o: osrf_math.c
osrf_dbmath.o: osrf_dbmath.c
+osrf_version.o: osrf_version.c
osrf_math.so: osrf_math.o
$(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) osrf_math.o -o $(TMPDIR)/osrf_math.so
osrf_dbmath.so: osrf_dbmath.o
$(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) osrf_dbmath.o -o $(TMPDIR)/osrf_dbmath.so
+osrf_version.so: osrf_version.o
+ $(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) osrf_version.o -o $(TMPDIR)/osrf_version.so
+
install:
cp $(TMPDIR)/osrf_math.so $(LIBDIR)/
cp $(TMPDIR)/osrf_dbmath.so $(LIBDIR)/
+ cp $(TMPDIR)/osrf_version.so $(LIBDIR)/
clean:
rm -f *.o *.so
#include "opensrf/osrf_app_session.h"
#include "opensrf/osrf_application.h"
#include "objson/object.h"
+#include "opensrf/osrf_log.h"
int osrfAppInitialize();
int osrfAppChildInit();
int osrfAppInitialize() {
+ osrfLogInit("opensrf.dbmath");
osrfAppRegisterMethod( "opensrf.dbmath", "add", "osrfMathRun", "send 2 numbers and I'll add them", 2 );
osrfAppRegisterMethod( "opensrf.dbmath", "sub", "osrfMathRun", "send 2 numbers and I'll divide them", 2 );
osrfAppRegisterMethod( "opensrf.dbmath", "mult", "osrfMathRun", "send 2 numbers and I'll multiply them", 2 );
return 0;
}
-int osrfMathRun( osrfMethodContext* d ) {
+int osrfMathRun( osrfMethodContext* ctx ) {
- OSRF_METHOD_VERIFY_CONTEXT(d);
+ OSRF_METHOD_VERIFY_CONTEXT(ctx);
- jsonObject* x = jsonObjectGetIndex(params, 0);
- jsonObject* y = jsonObjectGetIndex(params, 1);
+ jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
+ jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
if( x && y ) {
double j = strtod(b, NULL);
double r = 0;
- if(!strcmp(method->name, "add")) r = i + j;
- if(!strcmp(method->name, "sub")) r = i - j;
- if(!strcmp(method->name, "mult")) r = i * j;
- if(!strcmp(method->name, "div")) r = i / j;
+ if(!strcmp(ctx->method->name, "add")) r = i + j;
+ if(!strcmp(ctx->method->name, "sub")) r = i - j;
+ if(!strcmp(ctx->method->name, "mult")) r = i * j;
+ if(!strcmp(ctx->method->name, "div")) r = i / j;
jsonObject* resp = jsonNewNumberObject(r);
- osrfAppRequestRespondComplete( session, request, resp );
+ osrfAppRequestRespondComplete( ctx->session, ctx->request, resp );
jsonObjectFree(resp);
free(a); free(b);
#include "opensrf/osrf_app_session.h"
#include "opensrf/osrf_application.h"
#include "objson/object.h"
+#include "opensrf/osrf_log.h"
int osrfAppInitialize();
int osrfAppChildInit();
int osrfAppInitialize() {
-
+ osrfLogInit("opensrf.math");
/* tell the server about the methods we handle */
osrfAppRegisterMethod( "opensrf.math", "add", "osrfMathRun", "send 2 numbers and I'll add them", 2 );
osrfAppRegisterMethod( "opensrf.math", "sub", "osrfMathRun", "send 2 numbers and I'll divide them", 2 );
return 0;
}
-int osrfMathRun( osrfMethodContext* c ) {
+int osrfMathRun( osrfMethodContext* ctx ) {
+
+ OSRF_METHOD_VERIFY_CONTEXT(ctx); /* see osrf_application.h */
- OSRF_METHOD_VERIFY_CONTEXT(c); /* see osrf_application.h */
+ osrfLog( OSRF_DEBUG, "Running opensrf.math %s", ctx->method->name );
/* collect the request params */
- jsonObject* x = jsonObjectGetIndex(params, 0);
- jsonObject* y = jsonObjectGetIndex(params, 1);
+ jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
+ jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
if( x && y ) {
osrfAppSession* ses = osrfAppSessionClientInit("opensrf.dbmath");
/* dbmath uses the same method names that math does */
- int req_id = osrfAppSessionMakeRequest( ses, newParams, method->name, 1, NULL );
+ int req_id = osrfAppSessionMakeRequest( ses, newParams, ctx->method->name, 1, NULL );
osrfMessage* omsg = osrfAppSessionRequestRecv( ses, req_id, 60 );
if(omsg) {
-
/* return dbmath's response to the user */
- osrfAppRequestRespondComplete( session, request, osrfMessageGetResult(omsg) );
+ osrfAppRequestRespondComplete( ctx->session, ctx->request, osrfMessageGetResult(omsg) );
osrfMessageFree(omsg);
+ osrfAppSessionFree(ses);
return 0;
}
+
+ osrfAppSessionFree(ses);
}
}
--- /dev/null
+#include "opensrf/osrf_app_session.h"
+#include "opensrf/osrf_application.h"
+#include "objson/object.h"
+#include "opensrf/utils.h"
+#include "opensrf/osrf_log.h"
+
+#define OSRF_VERSION_CACHE_TIME 300
+
+int osrfAppInitialize();
+int osrfAppChildInit();
+int osrfVersion( osrfMethodContext* );
+
+
+int osrfAppInitialize() {
+ osrfLogInit("opensrf.version");
+ osrfAppRegisterMethod(
+ "opensrf.version",
+ "opensrf.version.verify",
+ "osrfVersion",
+ "Send the service, method, and params as paramters to this method "
+ "The data for this service/method/params combination will be retrieved "
+ "from the necessary server and the MD5 sum of the total values received "
+ "will be returned", 2 );
+
+ return 0;
+}
+
+int osrfAppChildInit() {
+ return 0;
+}
+
+int osrfVersion( osrfMethodContext* ctx ) {
+
+ OSRF_METHOD_VERIFY_CONTEXT(ctx);
+
+ /* First, see if the data is in the cache */
+ char* json = jsonObjectToJSON(ctx->params);
+ char* paramsmd5 = md5sum(json);
+ char* cachedmd5 = osrfCacheGetString(paramsmd5);
+ free(json);
+
+ if( cachedmd5 ) {
+ osrfLog( OSRF_DEBUG, "Found %s object in cache, returning....", cachedmd5 );
+ jsonObject* resp = jsonNewObject(cachedmd5);
+ osrfAppRequestRespondComplete( ctx->session, ctx->request, resp );
+ jsonObjectFree(resp);
+ free(paramsmd5);
+ free(cachedmd5);
+ return 0;
+ }
+
+ jsonObject* serv = jsonObjectGetIndex(ctx->params, 0);
+ jsonObject* meth = jsonObjectGetIndex(ctx->params, 1);
+ char* service = jsonObjectGetString(serv);
+ char* methd = jsonObjectGetString(meth);
+
+ if( service && methd ) {
+ /* shove the additional params into an array */
+ jsonObject* tmpArray = jsonNewObject(NULL);
+ int i;
+ for( i = 2; i != ctx->params->size; i++ )
+ jsonObjectPush( tmpArray, jsonObjectClone(jsonObjectGetIndex(ctx->params, i)));
+
+ osrfAppSession* ses = osrfAppSessionClientInit(service);
+ int reqid = osrfAppSessionMakeRequest( ses, tmpArray, methd, 1, NULL );
+ osrfMessage* omsg = osrfAppSessionRequestRecv( ses, reqid, 60 );
+ jsonObjectFree(tmpArray);
+
+ if( omsg ) {
+
+ jsonObject* result = osrfMessageGetResult( omsg );
+ char* resultjson = jsonObjectToJSON(result);
+ char* resultmd5 = md5sum(resultjson);
+ free(resultjson);
+ osrfMessageFree(omsg);
+
+ if( resultmd5 ) {
+ jsonObject* resp = jsonNewObject(resultmd5);
+ osrfAppRequestRespondComplete( ctx->session, ctx->request, resp );
+ jsonObjectFree(resp);
+ osrfAppSessionFree(ses);
+ osrfLog(OSRF_DEBUG, "Found version string %s, caching and returning...", resultmd5 );
+ osrfCachePutString( paramsmd5, resultmd5, OSRF_VERSION_CACHE_TIME );
+ free(resultmd5);
+ free(paramsmd5);
+ return 0;
+ }
+ }
+ osrfAppSessionFree(ses);
+ }
+
+ free(paramsmd5);
+
+ return -1;
+}
+
+
+
-CFLAGS += -DASSUME_STATELESS -rdynamic -fno-strict-aliasing
+CFLAGS += -DASSUME_STATELESS -rdynamic -fno-strict-aliasing
LDLIBS += -lxml2 -lobjson -ldl -lmemcache
TARGETS = osrf_message.o \
osrfConfig.o \
osrf_application.o \
osrf_cache.o \
+ osrf_log.o \
xml_utils.o
HEADERS = osrf_message.h \
osrfConfig.h \
osrf_application.h \
osrf_cache.h \
+ osrf_log.h \
xml_utils.h
all: xml_utils.o $(TARGETS) copy
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
clean:
/bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c
*/
free( req );
- debug_handler("after request free");
}
/** 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 [%d] onto request queue", result->thread_trace );
+ debug_handler( "App Session pushing request [%d] onto request queue", result->thread_trace );
if(req->result == NULL)
req->result = result;
else {
osrf_app_session* session, int req_id ){
if(session == NULL) return;
- debug_handler("Finishing request %d", req_id );
osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
if(req == NULL) return;
_osrf_app_session_remove_request( req->session, req );
void osrf_app_session_request_reset_timeout( osrf_app_session* session, int req_id ) {
if(session == NULL) return;
- debug_handler("Resetting timeout %d", req_id );
+ debug_handler("Resetting request timeout %d", req_id );
osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
if(req == NULL) return;
req->reset_timeout = 1;
if(req == NULL) return NULL;
if( req->result != NULL ) {
- debug_handler("app_request receive already has a message, returning it");
/* pop off the first message in the list */
osrf_message* tmp_msg = req->result;
req->result = req->result->next;
/** returns a session from the global session hash */
osrf_app_session* osrf_app_session_find_session( char* session_id ) {
osrf_app_session* ptr = app_session_cache;
- debug_handler("Searching for session in global cache with id [%s]", session_id );
while( ptr != NULL ) {
if( !strcmp(ptr->session_id,session_id) )
return ptr;
}
osrf_app_session* ptr = app_session_cache;
- debug_handler( "Pushing [%s] [%s] onto global session cache",
- session->remote_service, session->session_id );
while( ptr != NULL ) {
if( !strcmp(ptr->session_id, session->session_id) )
return;
#ifdef ASSUME_STATELESS
session->stateless = 1;
- debug_handler("session is stateless");
+ debug_handler("%s session is stateless", remote_service );
#else
session->stateless = 0;
- debug_handler("session is NOT stateless");
+ debug_handler("%s session is NOT stateless", remote_service );
#endif
/* build a chunky, random session id */
if(session == NULL)
return NULL;
- debug_handler( "App Session searching for request [%d] in request queue",request_id );
osrf_app_request* req = session->request_queue;
while( req != NULL ) {
if(req->request_id == request_id)
if(session == NULL || msg == NULL)
return 0;
- debug_handler( "AppSession pushing result for [%d] onto request payload queue",
- msg->thread_trace );
-
osrf_app_request* req = session->request_queue;
- if(req == NULL) {
- warning_handler( "app_session has no app_requests in its queue yet we have a result for [%d]", msg->thread_trace );
- return 0;
- }
+ if(req == NULL) return 0;
while( req != NULL ) {
if(req->request_id == msg->thread_trace) {
- debug_handler( "Found app_request for tt [%d]", msg->thread_trace );
_osrf_app_request_push_queue( req, msg );
return 1;
}
return 0;
if(session->state == OSRF_SESSION_CONNECTED) {
- debug_handler("Already Connected, returning");
return 1;
}
}
if(session->state == OSRF_SESSION_CONNECTED)
- debug_handler(" * Connected Successfully");
+ debug_handler(" * Connected Successfully to %s", session->remote_service );
if(session->state != OSRF_SESSION_CONNECTED)
return 0;
}
int osrf_app_session_request_resend( osrf_app_session* session, int req_id ) {
- debug_handler("In reqeust resend searching for resend-able messages");
osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
return _osrf_app_request_resend( req );
}
transport_message* t_msg = message_init(
string, "", session->session_id, session->remote_id, NULL );
- debug_handler("Session [%s] [%s] sending to %s \nXML:\n%s",
+ debug_handler("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 );
/** Disconnects (if client) and removes the given session from the global session cache
* ! This free's all attached app_requests !
*/
-void osrf_app_session_destroy ( osrf_app_session* session ){
+void osrfAppSessionFree( osrfAppSession* ses ) {
+ osrf_app_session_destroy( ses );
+}
+
+
+void osrf_app_session_destroy( osrf_app_session* session ){
if(session == NULL) return;
debug_handler( "AppSession [%s] [%s] destroying self and deleting requests",
}
//session->state = OSRF_SESSION_DISCONNECTED;
_osrf_app_session_remove_session(session->session_id);
- debug_handler("AppSession [%s] [%s] removed from cache",
- session->remote_service, session->session_id );
osrf_app_request* req;
while( session->request_queue != NULL ) {
osrf_app_session* session, int req_id, int timeout ) {
if(req_id < 0 || session == NULL)
return NULL;
- debug_handler("somebody callled recv");
osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
return _osrf_app_request_recv( req, timeout );
}
* session is completey done.
*/
void osrf_app_session_destroy ( osrf_app_session* );
+void osrfAppSessionFree( osrfAppSession* );
/**
This macro verifies methods receive the correct parameters
- It also creates local variables "session", "method",
- "params", and "request"
*/
-#define OSRF_METHOD_VERIFY_CONTEXT(__d) \
- if(!__d) return -1; \
- \
- osrfAppSession* session = __d->session; \
- osrfMethod* method = __d->method; \
- jsonObject* params = __d->params; \
- int request = __d->request; \
- \
- if( !(session && method && params) ) return -1; \
- if( !params->type == JSON_ARRAY ) return -1; \
- if( !method->name ) return -1; \
- \
- char* __j = jsonObjectToJSON(params);\
+#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->params->type != JSON_ARRAY ) { \
+ osrfLog( OSRF_ERROR, "'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; }
+
+
+#ifdef OSRF_LOG_PARAMS
+#define OSRF_METHOD_VERIFY_CONTEXT(d) \
+ _OSRF_METHOD_VERIFY_CONTEXT(d); \
+ char* __j = jsonObjectToJSON(d->params);\
if(__j) { \
- debug_handler("Service: %s | Params: %s", session->remote_service, __j);free(__j);}
+ osrfLog( OSRF_DEBUG, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\
+ free(__j); \
+ }
+#else
+#define OSRF_METHOD_VERIFY_CONTEXT(d) _OSRF_METHOD_VERIFY_CONTEXT(d);
+#endif
+
return 0;
}
-jsonObject* osrfCacheGetObject( char* key ) {
+jsonObject* osrfCacheGetObject( char* key, ... ) {
jsonObject* obj = NULL;
if( key ) {
- char* data = (char*) mc_aget( __osrfCache, key, strlen(key) );
+ VA_LIST_TO_STRING(key);
+ char* data = (char*) mc_aget( __osrfCache, VA_BUF, strlen(VA_BUF) );
if( data ) {
obj = jsonParseString( data );
return obj;
return NULL;
}
-char* osrfCacheGetString( char* key ) {
- if( key ) return (char*) mc_aget(__osrfCache, key, strlen(key) );
+char* osrfCacheGetString( char* key, ... ) {
+ if( key ) {
+ VA_LIST_TO_STRING(key);
+ return (char*) mc_aget(__osrfCache, VA_BUF, strlen(VA_BUF) );
+ }
return NULL;
}
-int osrfCacheRemove( char* key ) {
- if( key ) return mc_delete(__osrfCache, key, strlen(key), 0 );
+int osrfCacheRemove( char* key, ... ) {
+ if( key ) {
+ VA_LIST_TO_STRING(key);
+ return mc_delete(__osrfCache, VA_BUF, strlen(VA_BUF), 0 );
+ }
return -1;
}
@param key The cache key
@return The object (which must be freed) if it exists, otherwise returns NULL
*/
-jsonObject* osrfCacheGetObject( char* key );
+jsonObject* osrfCacheGetObject( char* key, ... );
/**
Grabs a string from the cache.
@param key The cache key
@return The string (which must be freed) if it exists, otherwise returns NULL
*/
-char* osrfCacheGetString( char* key );
+char* osrfCacheGetString( char* key, ... );
/**
Removes the item with the given key from the cache.
@return 0 on success, -1 on error.
*/
-int osrfCacheRemove( char* key );
+int osrfCacheRemove( char* key, ... );
--- /dev/null
+#include "osrf_log.h"
+#include <time.h>
+
+char* __osrfLogAppName = NULL;
+char* __osrfLogDir = NULL;
+int __osrfLogLevel = 1;
+
+int osrfLogInit(char* appname) {
+
+ if( !appname ) return -1;
+ info_handler("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");
+
+ char* level = osrfConfigGetValue(NULL, "/loglevel");
+ if(level) { __osrfLogLevel = atoi(level); free(level); }
+
+ __osrfLogAppName = strdup(appname);
+ __osrfLogDir = strdup(dir);
+ return 0;
+}
+
+
+void osrfLog( enum OSRF_LOG_LEVEL level, char* msg, ... ) {
+
+ if( !(__osrfLogDir && __osrfLogAppName) ) return;
+ if( level > __osrfLogLevel ) return;
+
+ time_t t = time(NULL);
+ struct tm* tms = localtime(&t);
+
+ char datebuf[24];
+ bzero(datebuf, 24);
+ strftime( datebuf, 23, "%d%m%Y", tms );
+
+ char timebuf[24];
+ bzero(timebuf, 24);
+ strftime( timebuf, 23, "%Y:%m:%d %H:%M:%S", tms );
+
+ char millis[12];
+ bzero(millis, 12);
+ double d = get_timestamp_millis();
+ d = d - (int) d;
+ sprintf(millis, "%.6f", d);
+
+
+ char* filename = va_list_to_string(
+ "%s/%s.%s.log", __osrfLogDir, __osrfLogAppName, datebuf);
+
+ FILE* file = fopen(filename, "a");
+ free(filename);
+
+ if(!file) {
+ warning_handler("Unable to open application log file %s\n", filename);
+ return;
+ }
+
+ VA_LIST_TO_STRING(msg);
+ fprintf(file, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF );
+ fclose(file);
+}
+
+
--- /dev/null
+#include "opensrf/utils.h"
+#include "osrf_settings.h"
+#include "osrfConfig.h"
+
+enum OSRF_LOG_LEVEL { OSRF_ERROR = 1, OSRF_WARN = 2, OSRF_INFO = 3, OSRF_DEBUG = 4 };
+
+int osrfLogInit(char* appname);
+void osrfLog( enum OSRF_LOG_LEVEL, char* msg, ... );
+
osrfAppSession* session = osrf_stack_transport_handler(msg, child->appname);
if(!session) return;
- if( session->stateless && session->state != OSRF_SESSION_CONNECTED ) return;
+ if( session->stateless && session->state != OSRF_SESSION_CONNECTED ) {
+ osrfAppSessionFree( session );
+ return;
+ }
/* keepalive loop for stateful sessions */
return NULL;
case DISCONNECT:
- osrf_app_session_destroy(session);
+ /* session will be freed by the forker */
return NULL;
case CONNECT:
jsonObject* params = msg->_params;
osrfAppRunMethod( app, method, session, msg->thread_trace, params );
+
+ osrfMessageFree(msg);
return 1;
osrfStringArray* arr = osrfNewStringArray(8);
_osrfSystemInitCache();
- return 0;
if(apps) {
int i = 0;
#
# --------------------------------------------------------------------
-OBJS = utils.o object.o json_parser.o
+OBJS = md5.o utils.o object.o json_parser.o
UTIL_DIR = ../utils
DEST_INCLUDE = objson
CFLAGS += -DSTRICT_JSON_WRITE #-DSTRICT_JSON_READ
cp $(UTIL_DIR)/utils.c .
$(CC) -c $(CFLAGS) utils.c -o $@
+md5.o: $(UTIL_DIR)/md5.h $(UTIL_DIR)/md5.c
+ cp $(UTIL_DIR)/md5.h .
+ cp $(UTIL_DIR)/md5.c .
+ $(CC) -c $(CFLAGS) md5.c -o $@
+
+
clean:
/bin/rm -f *.o *.so utils.c utils.h libobjson.so
return 0;
}
-char* md5sum( char* text ) {
-
- struct md5_ctx ctx;
- unsigned char digest[16];
-
- MD5_start (&ctx);
-
- int i;
- for ( i=0 ; i != strlen(text) ; i++ )
- MD5_feed (&ctx, text[i]);
-
- MD5_stop (&ctx, digest);
-
- char buf[16];
- memset(buf,0,16);
-
- char final[256];
- memset(final,0,256);
-
- for ( i=0 ; i<16 ; i++ ) {
- sprintf(buf, "%02x", digest[i]);
- strcat( final, buf );
- }
-
- return strdup(final);
-
-}
-
-
int handle_set( char* words[]) {
char* variable;
#include <sys/types.h>
#include <sys/wait.h>
-#include "md5.h"
#include "utils.h"
#include "logging.h"
int do_math( int count, int style );
int handle_introspect(char* words[]);
int handle_login( char* words[]);
-char* md5sum( char* text );
-UTIL_HEADERS = logging.h utils.h socket_bundle.h md5.h sha.h string_array.h xml_utils.h
-UTIL_OBJECTS = logging.o utils.o socket_bundle.o md5.o sha.o string_array.o
+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
all: $(UTIL_OBJECTS) copy
return data;
}
+
+char* md5sum( char* text ) {
+
+ struct md5_ctx ctx;
+ unsigned char digest[16];
+
+ MD5_start (&ctx);
+
+ int i;
+ for ( i=0 ; i != strlen(text) ; i++ )
+ MD5_feed (&ctx, text[i]);
+
+ MD5_stop (&ctx, digest);
+
+ char buf[16];
+ memset(buf,0,16);
+
+ char final[256];
+ memset(final,0,256);
+
+ for ( i=0 ; i<16 ; i++ ) {
+ sprintf(buf, "%02x", digest[i]);
+ strcat( final, buf );
+ }
+
+ return strdup(final);
+
+}
+
+
#include <string.h>
//#include <sys/timeb.h>
+#include "md5.h"
/* turns a va_list into a string */
#define VA_LIST_TO_STRING(x) \
char* INTSTR = __b;
+/*
+#define MD5SUM(s) \
+ struct md5_ctx ctx; \
+ unsigned char digest[16];\
+ MD5_start (&ctx);\
+ int i;\
+ for ( i=0 ; i != strlen(text) ; i++ ) MD5_feed (&ctx, text[i]);\
+ MD5_stop (&ctx, digest);\
+ char buf[16];\
+ memset(buf,0,16);\
+ char final[256];\
+ memset(final,0,256);\
+ for ( i=0 ; i<16 ; i++ ) {\
+ sprintf(buf, "%02x", digest[i]);\
+ strcat( final, buf );\
+ }\
+ char* MD5STR = final;
+ */
+
+
+/**
+ Calculates the md5 of the text provided.
+ The returned string must be freed by the caller.
+ */
+char* md5sum( char* text );
#endif