summaryrefslogtreecommitdiffstats
path: root/plugins/omoracle/omoracle.c
blob: 6077594fb1514b3e28919b9ac22dfd0ce605ad5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/** omoracle.c

    This is an output module feeding directly to an Oracle
    database. It uses Oracle Call Interface, a propietary module
    provided by Oracle.

    Author: Luis Fernando Muñoz Mejías
    <Luis.Fernando.Munoz.Mejias@cern.ch>

    This file is part of rsyslog.
*/
#include "config.h"
#include "rsyslog.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oci.h>
#include <errno.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>
#include <assert.h>
#include "dirty.h"
#include "syslogd-types.h"
#include "srUtils.h"
#include "template.h"
#include "module-template.h"
#include "errmsg.h"
#include "cfsysline.h"
#include "omoracle.h"

MODULE_TYPE_OUTPUT

/**  */
DEF_OMOD_STATIC_DATA
DEFobjCurrIf(errmsg)

typedef struct _instanceData {
	OCIEnv* environment;
	OCISession* session;
	OCIError* error;
	OCIServer* server;
	OCIStmt* statement;
	OCISvcCtx* service;
	OCIAuthInfo* authinfo;
	OCIBind* binding;
} instanceData;

/** Generic function for handling errors from OCI.

    It will be called only inside CHECKERR and CHECKENV macros.

    Arguments: handle The error or environment handle to check.
    htype: OCI_HTYPE_* constant, usually OCI_HTYPE_ERROR or
    OCI_HTYPE_ENV
    status: status code to check, usually the return value of an OCI
    function.

    Returns OCI_SUCCESS on success, OCI_ERROR otherwise.
*/
static int oci_errors(void* handle, ub4 htype, sword status)
{
	sb4 errcode;
	unsigned char buf[MAX_BUFSIZE];
	
	switch (status) {
	case OCI_SUCCESS:
		return OCI_SUCCESS;
		break;
	case OCI_SUCCESS_WITH_INFO:
		printf ("OCI SUCCESS - With info\n");
		break;
	case OCI_NEED_DATA:
		printf ("OCI NEEDS MORE DATA\n");
		break;
	case OCI_ERROR:
		printf ("OCI GENERAL ERROR\n");
		if (handle) {
			OCIErrorGet(handle, 1, NULL, &errcode, buf,
				    sizeof buf, htype);
			printf ("Error message: %s", buf);
		} else
			printf ("NULL handle\n"
				"Unable to extract further information");
		break;
	case OCI_INVALID_HANDLE:
		printf ("OCI INVALID HANDLE\n");
		break;
	case OCI_STILL_EXECUTING:
		printf ("Still executing...\n");
		break;
	case OCI_CONTINUE:
		printf ("OCI CONTINUE\n");
		break;
	}
	return OCI_ERROR;
}


/* Resource allocation */
BEGINcreateInstance
CODESTARTcreateInstance
CHECKENV(pData->environment,
	 OCIEnvCreate((void*) &(pData->environment), OCI_DEFAULT,
		      NULL, NULL, NULL, NULL, 0, NULL));
CHECKENV(pData->environment,
	 OCIHandleAlloc(pData->environment, (void*) &(pData->error),
			OCI_HTYPE_ERROR, 0, NULL));
CHECKENV(pData->environment,
	 OCIHandleAlloc(pData->environment, (void*) &(pData->server),
			OCI_HTYPE_SERVER, 0, NULL));
CHECKENV(pData->environment,
	 OCIHandleAlloc(pData->environment, (void*) &(pData->service),
			OCI_HTYPE_SVCCTX, 0, NULL));
CHECKENV(pData->environment,
	 OCIHandleAlloc(pData->environment, (void*) &(pData->authinfo),
			OCI_HTYPE_AUTHINFO, 0, NULL));
finalize_it:
ENDcreateInstance

/** Free any resources allocated by createInstance. */
BEGINfreeInstance
CODESTARTfreeInstance

OCIHandleFree(pData->environment, OCI_HTYPE_ENV);
OCIHandleFree(pData->error, OCI_HTYPE_ERROR);
OCIHandleFree(pData->server, OCI_HTYPE_SERVER);
OCIHandleFree(pData->service, OCI_HTYPE_SVCCTX);
OCIHandleFree(pData->authinfo, OCI_HTYPE_AUTHINFO);

RETiRet;

ENDfreeInstance


BEGINtryResume
CODESTARTtryResume
ENDtryResume

BEGINisCompatibleWithFeature
CODESTARTisCompatibleWithFeature
/* Right now, this module is compatible with nothing. */
ENDisCompatibleWithFeature

BEGINparseSelectorAct
CODESTARTparseSelectorAct
CODE_STD_STRING_REQUESTparseSelectorAct(1);
CODE_STD_FINALIZERparseSelectorAct
ENDparseSelectorAct

BEGINdoAction
CODESTARTdoAction
ENDdoAction

BEGINmodExit
CODESTARTmodExit
ENDmodExit

BEGINdbgPrintInstInfo
CODESTARTdbgPrintInstInfo
ENDdbgPrintInstInfo


BEGINqueryEtryPt
CODESTARTqueryEtryPt
CODEqueryEtryPt_STD_OMOD_QUERIES
ENDqueryEtryPt

BEGINmodInit()
CODESTARTmodInit
	*ipIFVersProvided = CURR_MOD_IF_VERSION;
CODEmodInit_QueryRegCFSLineHdlr
	CHKiRet(objUse(errmsg, CORE_COMPONENT));
ENDmodInit