Lp 1901899: Remove References to Ubuntu 16.04
[OpenSRF.git] / src / c-apps / osrf_dbmath.c
index 07cf0f6..e97ab9b 100644 (file)
@@ -1,7 +1,9 @@
-#include "opensrf/osrf_app_session.h"
-#include "opensrf/osrf_application.h"
-#include "objson/object.h"
-#include "opensrf/osrf_log.h"
+#include <opensrf/osrf_app_session.h>
+#include <opensrf/osrf_application.h>
+#include <opensrf/osrf_json.h>
+#include <opensrf/log.h>
+
+#define MODULENAME "opensrf.dbmath"
 
 int osrfAppInitialize();
 int osrfAppChildInit();
@@ -9,11 +11,31 @@ int osrfMathRun( osrfMethodContext* );
 
 
 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 );
-       osrfAppRegisterMethod( "opensrf.dbmath", "div", "osrfMathRun", "send 2 numbers and I'll subtract them", 2 );
+
+       osrfAppRegisterMethod( 
+                       MODULENAME, 
+                       "add", 
+                       "osrfMathRun", 
+                       "Addss two numbers", 2, 0 );
+
+       osrfAppRegisterMethod( 
+                       MODULENAME, 
+                       "sub", 
+                       "osrfMathRun", 
+                       "Subtracts two numbers", 2, 0 );
+
+       osrfAppRegisterMethod( 
+                       MODULENAME, 
+                       "mult", 
+                       "osrfMathRun", 
+                       "Multiplies two numbers", 2, 0 );
+
+       osrfAppRegisterMethod( 
+                       MODULENAME, 
+                       "div", 
+                       "osrfMathRun", 
+                       "Divides two numbers", 2, 0 );
+
        return 0;
 }
 
@@ -22,11 +44,13 @@ int osrfAppChildInit() {
 }
 
 int osrfMathRun( osrfMethodContext* ctx ) {
+       if( osrfMethodVerifyContext( ctx ) ) {
+               osrfLogError( OSRF_LOG_MARK,  "Invalid method context" );
+               return -1;
+       }
 
-       OSRF_METHOD_VERIFY_CONTEXT(ctx);        
-
-       jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
-       jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
+       const jsonObject* x = jsonObjectGetIndex(ctx->params, 0);
+       const jsonObject* y = jsonObjectGetIndex(ctx->params, 1);
 
        if( x && y ) {
 
@@ -45,12 +69,16 @@ int osrfMathRun( osrfMethodContext* ctx ) {
                        if(!strcmp(ctx->method->name, "div"))   r = i / j;
 
                        jsonObject* resp = jsonNewNumberObject(r);
-                       osrfAppRequestRespondComplete( ctx->session, ctx->request, resp );
+                       osrfAppRespondComplete( ctx, resp );
                        jsonObjectFree(resp);
 
                        free(a); free(b);
                        return 0;
                }
+               else {
+                       if(a) free(a);
+                       if(b) free(b);
+               }
        }
 
        return -1;