Skip to content
Snippets Groups Projects
Commit 5d66344b352a authored by jfp's avatar jfp
Browse files

rmqplus.c initial version

parent 554bd3733670
Branches
No related tags found
1 merge request!1rmqplus.c initial version
rmqplus.c 0 → 100644
/*****************************************************************************/
/*
This program is used in CGIplus environment.
Generate a json with all variables, RPC call using RabbitMQ
then return the result.
Use part of CGIplusDemo.c
This program to use 'struct' mode for passing the CGIplus variables.
VERSION HISTORY (update SOFTWAREVN as well!)
---------------
01-SEP-2020 JFP v1.0.0, initial development
*/
/*****************************************************************************/
#define SOFTWAREVN "1.0.0"
#define SOFTWARENM "RMQPLUS"
#if defined(__ALPHA)
#define SOFTWAREID SOFTWARENM " AXP-" SOFTWAREVN
#elif defined(__ia64)
#define SOFTWAREID SOFTWARENM " IA64-" SOFTWAREVN
#elif defined(__VAX)
#define SOFTWAREID SOFTWARENM " VAX-" SOFTWAREVN
#else
#define SOFTWAREID SOFTWARENM " UNKNOWN-" SOFTWAREVN
#endif
#ifndef __VAX
#pragma nomember_alignment
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <ssdef.h>
#include <cgilib.h>
#include <cJSON.h>
#include <amqp_tcp_socket.h>
#include <amqp.h>
#include <amqp_framing.h>
char Utility[] = "RMQPLUS";
int Debug,
IsCgiPlus,
UsageCounter;
char *CgiPlusEofPtr;
char FirstUsedDateTime[32],
NowDateTime[32];
unsigned long UnixTime;
struct tm *UnixTmPtr;
int rmqplus();
/*
* Main routine, just use an infinite loop calling rmqplus
*/
main() {
/*********/
/* begin */
/*********/
if (getenv("RMQPLUS$DBUG"))
Debug = 1;
CgiLibEnvironmentSetDebug(Debug);
time(&UnixTime);
UnixTmPtr = localtime(&UnixTime);
if (!strftime(FirstUsedDateTime, sizeof(FirstUsedDateTime),
"%a, %d %b %Y %T", UnixTmPtr))
strcpy(FirstUsedDateTime, "[error]");
for (;;) {
int s;
time(&UnixTime);
UnixTmPtr = localtime(&UnixTime);
if (!strftime(NowDateTime, sizeof(NowDateTime),
"%a, %d %b %Y %T", UnixTmPtr))
strcpy(NowDateTime, "[error]");
/* wait for the next request */
CgiLibVar("");
s = rmqplus();
CgiLibCgiPlusEOF ();
}
exit(SS$_NORMAL);
}
/*
*
*/
static cJSON *cjson_create_root(void) {
cJSON *root = cJSON_CreateObject();
cJSON *obj;
obj = cJSON_AddObjectToObject(root, "in");
obj = cJSON_AddObjectToObject(root, "out");
return root;
}
int rmqplus() {
cJSON *cjson_root, *cjson_in, *cjson_out;
char *cptr, *cname, *cvalue;
/*********/
/* begin */
/*********/
if (Debug)
fprintf(stdout, "rmqplus()\n");
cjson_root = cjson_create_root();
cjson_in = cJSON_GetObjectItem(cjson_root, "in");
cjson_out = cJSON_GetObjectItem(cjson_root, "out");
fprintf(stdout,
"Content-Type: application/json\n\
Expires: Thu, 01 Jan 1970 00:00:01 GMT\n\
\n\
");
/* list all CGIplus variables names and values one-by-one */
while (cptr = CgiLibVar("*")) {
cname = cptr;
cvalue = strchr(cptr, '=');
if (cvalue) {
*cvalue = '\0';
++cvalue;
if (! cJSON_AddItemToObject(cjson_in, cname, cJSON_CreateString(cvalue))) {
cJSON_Delete(cjson_root);
fputs("{\"status\": 0}\n", stdout);
return (0);
}
}
}
fputs(cJSON_PrintUnformatted(cjson_root), stdout);
fputs("\n", stdout);
cJSON_Delete(cjson_root);
return (1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment