mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-13 04:50:41 +01:00
correct codestyle in rsyslog part 2
This commit is contained in:
parent
19133327cc
commit
c83e3ed216
4
action.c
4
action.c
@ -852,7 +852,7 @@ actionCheckAndCreateWrkrInstance(action_t * const pThis, const wti_t *const pWti
|
||||
pThis->pModData));
|
||||
pWti->actWrkrInfo[pThis->iActionNbr].pAction = pThis;
|
||||
setActionState(pWti, pThis, ACT_STATE_RDY); /* action is enabled */
|
||||
|
||||
|
||||
/* maintain worker data table -- only needed if wrkrHUP is requested! */
|
||||
|
||||
pthread_mutex_lock(&pThis->mutWrkrDataTable);
|
||||
@ -1401,7 +1401,7 @@ actionCommit(action_t *__restrict__ const pThis, wti_t *__restrict__ const pWti)
|
||||
}
|
||||
DBGPRINTF("actionCommit[%s]: processing...\n", pThis->pszName);
|
||||
|
||||
/* we now do one try at commiting the whole batch. Usually, this will
|
||||
/* we now do one try at commiting the whole batch. Usually, this will
|
||||
* succeed. If so, we are happy and done. If not, we dig into the details
|
||||
* of finding out if we have a non-temporary error and try to handle this
|
||||
* as well as retry processing. Due to this logic we do a bit more retries
|
||||
|
||||
@ -60,11 +60,11 @@
|
||||
#if defined (_AIX) /* Use ifaddrs_rsys instead of ifaddrs and ifreq instead of lifreq */
|
||||
int getallifaddrs(sa_family_t af, struct ifaddrs_rsys **ifap, int64_t flags);
|
||||
int getallifs(int s, sa_family_t af, struct ifreq **ifr, int *numifs,
|
||||
int64_t ifc_flags);
|
||||
int64_t ifc_flags);
|
||||
#else
|
||||
int getallifaddrs(sa_family_t af, struct ifaddrs **ifap, int64_t flags);
|
||||
int getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs,
|
||||
int64_t lifc_flags);
|
||||
int64_t lifc_flags);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -310,7 +310,7 @@ fail:
|
||||
*/
|
||||
int
|
||||
getallifs(int s, sa_family_t af, struct ifreq **ifr, int *iflen,
|
||||
int64_t ifc_flags)
|
||||
int64_t ifc_flags)
|
||||
{
|
||||
int ifsize;
|
||||
struct ifconf ifc;
|
||||
@ -488,7 +488,7 @@ fail:
|
||||
*/
|
||||
int
|
||||
getallifs(int s, sa_family_t af, struct lifreq **lifr, int *numifs,
|
||||
int64_t lifc_flags)
|
||||
int64_t lifc_flags)
|
||||
{
|
||||
struct lifnum lifn;
|
||||
struct lifconf lifc;
|
||||
|
||||
@ -19,6 +19,9 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
|
||||
tests/inputfilegen.c \
|
||||
tests/msleep.c \
|
||||
tests/testconfgen.c \
|
||||
tests/testbench.h \
|
||||
tests/uxsockrcvr.c \
|
||||
tests/tcpflood.c \
|
||||
plugins/imfile/imfile.c \
|
||||
plugins/imrelp/imrelp.c \
|
||||
plugins/omrelp/omrelp.c \
|
||||
@ -72,6 +75,11 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
|
||||
plugins/mmanon/mmanon.c \
|
||||
plugins/mmdblookup/mmdblookup.c \
|
||||
plugins/omudpspoof/omudpspoof.c \
|
||||
plugins/omsnmp/omsnmp.c \
|
||||
plugins/imuxsock/imuxsock.c \
|
||||
plugins/pmciscoios/pmciscoios.c \
|
||||
plugins/imgssapi/imgssapi.c \
|
||||
plugins/ommongodb/ommongodb.c \
|
||||
grammar/testdriver.c \
|
||||
runtime/netstrms.h \
|
||||
runtime/lib_ksi_queue.h \
|
||||
@ -149,6 +157,30 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
|
||||
runtime/tcpsrv.h \
|
||||
runtime/janitor.c \
|
||||
runtime/linkedlist.c \
|
||||
runtime/tcpsrv.c \
|
||||
runtime/gss-misc.c \
|
||||
runtime/obj.c \
|
||||
runtime/hashtable/hashtable_utility.c \
|
||||
runtime/conf.c \
|
||||
runtime/hashtable_itr.h \
|
||||
runtime/debug.c \
|
||||
runtime/parser.h \
|
||||
runtime/strmsrv.c \
|
||||
runtime/queue.c \
|
||||
runtime/lib_ksi_queue.c \
|
||||
runtime/typedefs.h \
|
||||
runtime/tcpclt.c \
|
||||
runtime/statsobj.c \
|
||||
runtime/dnscache.c \
|
||||
runtime/unlimited_select.h \
|
||||
runtime/srutils.c \
|
||||
runtime/nsd_ptcp.c \
|
||||
runtime/net.c \
|
||||
runtime/msg.c \
|
||||
runtime/hashtable_itr.c \
|
||||
runtime/librsksi_read.c \
|
||||
runtime/hashtable/tester.c \
|
||||
runtime/hashtable.c \
|
||||
contrib/mmkubernetes/mmkubernetes.c \
|
||||
contrib/mmrfc5424addhmac/mmrfc5424addhmac.c \
|
||||
contrib/mmcount/mmcount.c \
|
||||
@ -166,5 +198,24 @@ rsyslog_stylecheck -l 120 compat/ifaddrs.h \
|
||||
contrib/omhiredis/omhiredis.c \
|
||||
contrib/omczmq/omczmq.c \
|
||||
contrib/omrabbitmq/omrabbitmq.c \
|
||||
compat/getifaddrs.c \
|
||||
grammar/rainerscript.h \
|
||||
grammar/rainerscript.c \
|
||||
tools/omfile.c \
|
||||
tools/rsyslogd.c \
|
||||
tools/syncdemo.c \
|
||||
tools/syslogd.c \
|
||||
tools/logctl.c \
|
||||
tools/omfwd.c \
|
||||
tools/pmrfc3164.c \
|
||||
tools/rscryutil.c \
|
||||
tools/pmrfc5424.c \
|
||||
tools/ompipe.c \
|
||||
parse.c \
|
||||
parse.h \
|
||||
action.h
|
||||
action.h \
|
||||
template.h \
|
||||
threads.c \
|
||||
outchannel.c \
|
||||
action.c \
|
||||
template.c
|
||||
|
||||
@ -775,12 +775,12 @@ doGetSize(struct nvlst *valnode, struct cnfparamdescr *param,
|
||||
/* and now the "new" 1000-based definitions */
|
||||
case 'K': n *= 1000; break;
|
||||
case 'M': n *= 1000000; break;
|
||||
case 'G': n *= 1000000000; break;
|
||||
case 'G': n *= 1000000000; break;
|
||||
/* we need to use the multiplication below because otherwise
|
||||
* the compiler gets an error during constant parsing */
|
||||
case 'T': n *= (int64) 1000 * 1000000000; break; /* tera */
|
||||
case 'P': n *= (int64) 1000000 * 1000000000; break; /* peta */
|
||||
case 'E': n *= (int64) 1000000000 * 1000000000; break; /* exa */
|
||||
case 'T': n *= (int64) 1000 * 1000000000; break; /* tera */
|
||||
case 'P': n *= (int64) 1000000 * 1000000000; break; /* peta */
|
||||
case 'E': n *= (int64) 1000000000 * 1000000000; break; /* exa */
|
||||
default: --i; break; /* indicates error */
|
||||
}
|
||||
}
|
||||
@ -1478,7 +1478,7 @@ static rsRetVal
|
||||
doExtractFieldByChar(uchar *str, uchar delim, const int matchnbr, uchar **resstr)
|
||||
{
|
||||
int iCurrFld;
|
||||
int allocLen;
|
||||
int allocLen;
|
||||
int iLen;
|
||||
uchar *pBuf;
|
||||
uchar *pFld;
|
||||
@ -1512,7 +1512,7 @@ doExtractFieldByChar(uchar *str, uchar delim, const int matchnbr, uchar **resstr
|
||||
allocLen = iLen + 1;
|
||||
# ifdef VALGRIND
|
||||
allocLen += (3 - (iLen % 4));
|
||||
/*older versions of valgrind have a problem with strlen inspecting 4-bytes at a time*/
|
||||
/*older versions of valgrind have a problem with strlen inspecting 4-bytes at a time*/
|
||||
# endif
|
||||
CHKmalloc(pBuf = MALLOC(allocLen));
|
||||
/* now copy */
|
||||
@ -1699,24 +1699,24 @@ doFunc_exec_template(struct cnffunc *__restrict__ const func,
|
||||
|
||||
static es_str_t*
|
||||
doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restrict__ const findVal,
|
||||
struct svar *__restrict__ const replaceWithVal) {
|
||||
int freeOperand, freeFind, freeReplacement;
|
||||
es_str_t *str = var2String(operandVal, &freeOperand);
|
||||
es_str_t *findStr = var2String(findVal, &freeFind);
|
||||
es_str_t *replaceWithStr = var2String(replaceWithVal, &freeReplacement);
|
||||
uchar *find = es_getBufAddr(findStr);
|
||||
uchar *replaceWith = es_getBufAddr(replaceWithStr);
|
||||
uint lfind = es_strlen(findStr);
|
||||
uint lReplaceWith = es_strlen(replaceWithStr);
|
||||
uint lSrc = es_strlen(str);
|
||||
uint lDst = 0;
|
||||
uchar* src_buff = es_getBufAddr(str);
|
||||
uint i, j;
|
||||
for(i = j = 0; i <= lSrc; i++, lDst++) {
|
||||
if (j == lfind) {
|
||||
lDst = lDst - lfind + lReplaceWith;
|
||||
j = 0;
|
||||
}
|
||||
struct svar *__restrict__ const replaceWithVal) {
|
||||
int freeOperand, freeFind, freeReplacement;
|
||||
es_str_t *str = var2String(operandVal, &freeOperand);
|
||||
es_str_t *findStr = var2String(findVal, &freeFind);
|
||||
es_str_t *replaceWithStr = var2String(replaceWithVal, &freeReplacement);
|
||||
uchar *find = es_getBufAddr(findStr);
|
||||
uchar *replaceWith = es_getBufAddr(replaceWithStr);
|
||||
uint lfind = es_strlen(findStr);
|
||||
uint lReplaceWith = es_strlen(replaceWithStr);
|
||||
uint lSrc = es_strlen(str);
|
||||
uint lDst = 0;
|
||||
uchar* src_buff = es_getBufAddr(str);
|
||||
uint i, j;
|
||||
for(i = j = 0; i <= lSrc; i++, lDst++) {
|
||||
if (j == lfind) {
|
||||
lDst = lDst - lfind + lReplaceWith;
|
||||
j = 0;
|
||||
}
|
||||
if (i == lSrc) break;
|
||||
if (src_buff[i] == find[j]) {
|
||||
j++;
|
||||
@ -1725,16 +1725,16 @@ doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restric
|
||||
lDst -= (j - 1);
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
es_str_t *res = es_newStr(lDst);
|
||||
unsigned char* dest = es_getBufAddr(res);
|
||||
uint k, s;
|
||||
for(i = j = s = 0; i <= lSrc; i++, s++) {
|
||||
if (j == lfind) {
|
||||
s -= j;
|
||||
for (k = 0; k < lReplaceWith; k++, s++) dest[s] = replaceWith[k];
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
es_str_t *res = es_newStr(lDst);
|
||||
unsigned char* dest = es_getBufAddr(res);
|
||||
uint k, s;
|
||||
for(i = j = s = 0; i <= lSrc; i++, s++) {
|
||||
if (j == lfind) {
|
||||
s -= j;
|
||||
for (k = 0; k < lReplaceWith; k++, s++) dest[s] = replaceWith[k];
|
||||
j = 0;
|
||||
}
|
||||
if (i == lSrc) break;
|
||||
if (src_buff[i] == find[j]) {
|
||||
j++;
|
||||
@ -1746,15 +1746,15 @@ doFuncReplace(struct svar *__restrict__ const operandVal, struct svar *__restric
|
||||
}
|
||||
dest[s] = src_buff[i];
|
||||
}
|
||||
}
|
||||
if (j > 0) {
|
||||
for (k = 1; k <= j; k++) dest[s - k] = src_buff[i - k];
|
||||
}
|
||||
res->lenStr = lDst;
|
||||
if(freeOperand) es_deleteStr(str);
|
||||
if(freeFind) es_deleteStr(findStr);
|
||||
if(freeReplacement) es_deleteStr(replaceWithStr);
|
||||
return res;
|
||||
}
|
||||
if (j > 0) {
|
||||
for (k = 1; k <= j; k++) dest[s - k] = src_buff[i - k];
|
||||
}
|
||||
res->lenStr = lDst;
|
||||
if(freeOperand) es_deleteStr(str);
|
||||
if(freeFind) es_deleteStr(findStr);
|
||||
if(freeReplacement) es_deleteStr(replaceWithStr);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -83,11 +83,11 @@ struct objlst {
|
||||
};
|
||||
|
||||
struct nvlst {
|
||||
struct nvlst *next;
|
||||
es_str_t *name;
|
||||
struct svar val;
|
||||
unsigned char bUsed;
|
||||
/**< was this node used during config processing? If not, this
|
||||
struct nvlst *next;
|
||||
es_str_t *name;
|
||||
struct svar val;
|
||||
unsigned char bUsed;
|
||||
/**< was this node used during config processing? If not, this
|
||||
* indicates an error. After all, the user specified a setting
|
||||
* that the software does not know.
|
||||
*/
|
||||
@ -164,13 +164,13 @@ struct cnfstmt {
|
||||
struct cnfstmt *t_else;
|
||||
} s_propfilt;
|
||||
struct action_s *act;
|
||||
struct {
|
||||
struct {
|
||||
struct cnfitr *iter;
|
||||
struct cnfstmt *body;
|
||||
} s_foreach;
|
||||
struct {
|
||||
struct {
|
||||
lookup_ref_t *table;
|
||||
uchar *table_name;
|
||||
uchar *table_name;
|
||||
uchar *stub_value;
|
||||
} s_reload_lookup_table;
|
||||
} d;
|
||||
@ -183,8 +183,8 @@ struct cnfexpr {
|
||||
} __attribute__((aligned (8)));
|
||||
|
||||
struct cnfitr {
|
||||
char* var;
|
||||
struct cnfexpr* collection;
|
||||
char* var;
|
||||
struct cnfexpr* collection;
|
||||
} __attribute__((aligned (8)));
|
||||
|
||||
struct cnfnumval {
|
||||
|
||||
@ -199,7 +199,7 @@ finalize_it:
|
||||
struct outchannel *ochAddLine(char* pName, uchar** ppRestOfConfLine)
|
||||
{
|
||||
struct outchannel *pOch;
|
||||
uchar *p;
|
||||
uchar *p;
|
||||
|
||||
assert(pName != NULL);
|
||||
assert(ppRestOfConfLine != NULL);
|
||||
|
||||
8
parse.c
8
parse.c
@ -409,8 +409,8 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits)
|
||||
|
||||
/* now we have the string and must check/convert it to
|
||||
* an NetAddr structure.
|
||||
*/
|
||||
CHKiRet(cstrConvSzStrAndDestruct(&pCStr, &pszIP, 0));
|
||||
*/
|
||||
CHKiRet(cstrConvSzStrAndDestruct(&pCStr, &pszIP, 0));
|
||||
|
||||
if((*pIP = calloc(1, sizeof(struct NetAddr))) == NULL)
|
||||
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
||||
@ -442,7 +442,7 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits)
|
||||
free (*pIP);
|
||||
ABORT_FINALIZE(RS_RET_ERR);
|
||||
}
|
||||
|
||||
|
||||
if(*pC == '/') {
|
||||
/* mask bits follow, let's parse them! */
|
||||
++pThis->iCurrPos; /* eat slash */
|
||||
@ -478,7 +478,7 @@ rsRetVal parsAddrWithBits(rsParsObj *pThis, struct NetAddr **pIP, int *pBits)
|
||||
free (*pIP);
|
||||
ABORT_FINALIZE(RS_RET_ERR);
|
||||
}
|
||||
|
||||
|
||||
if(*pC == '/') {
|
||||
/* mask bits follow, let's parse them! */
|
||||
++pThis->iCurrPos; /* eat slash */
|
||||
|
||||
@ -510,7 +510,7 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t *pSess)
|
||||
ABORT_FINALIZE(RS_RET_OK); // TODO: define good error codes
|
||||
}
|
||||
|
||||
freeFdSet(pFds);
|
||||
freeFdSet(pFds);
|
||||
}
|
||||
|
||||
context = &pGSess->gss_context;
|
||||
@ -565,10 +565,10 @@ OnSessAcceptGSS(tcpsrv_t *pThis, tcps_sess_t *pSess)
|
||||
maj_stat = gss_display_name(&min_stat, client, &recv_tok, NULL);
|
||||
if (maj_stat != GSS_S_COMPLETE) {
|
||||
gssutil.display_status((char*)"displaying name", maj_stat, min_stat);
|
||||
} else {
|
||||
} else {
|
||||
dbgprintf("GSS-API Accepted connection from peer %s: %s\n", (char *)pszPeer,
|
||||
(char*) recv_tok.value);
|
||||
}
|
||||
}
|
||||
gss_release_name(&min_stat, &client);
|
||||
gss_release_buffer(&min_stat, &recv_tok);
|
||||
|
||||
@ -736,7 +736,7 @@ CODESTARTmodExit
|
||||
objRelease(glbl, CORE_COMPONENT);
|
||||
objRelease(netstrm, LM_NETSTRM_FILENAME);
|
||||
objRelease(net, LM_NET_FILENAME);
|
||||
objRelease(prop, CORE_COMPONENT);
|
||||
objRelease(prop, CORE_COMPONENT);
|
||||
ENDmodExit
|
||||
|
||||
|
||||
@ -770,7 +770,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
|
||||
}
|
||||
bPermitPlainTcp = 0;
|
||||
iTCPSessMax = 200;
|
||||
bKeepAlive = 0;
|
||||
bKeepAlive = 0;
|
||||
return RS_RET_OK;
|
||||
}
|
||||
|
||||
@ -787,7 +787,7 @@ CODEmodInit_QueryRegCFSLineHdlr
|
||||
CHKiRet(objUse(glbl, CORE_COMPONENT));
|
||||
CHKiRet(objUse(netstrm, LM_NETSTRM_FILENAME));
|
||||
CHKiRet(objUse(net, LM_NET_FILENAME));
|
||||
CHKiRet(objUse(prop, CORE_COMPONENT));
|
||||
CHKiRet(objUse(prop, CORE_COMPONENT));
|
||||
|
||||
/* register config file handlers */
|
||||
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverpermitplaintcp", 0, eCmdHdlrBinary,
|
||||
@ -798,7 +798,7 @@ CODEmodInit_QueryRegCFSLineHdlr
|
||||
NULL, &gss_listen_service_name, STD_LOADABLE_MODULE_ID));
|
||||
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssservermaxsessions", 0, eCmdHdlrInt,
|
||||
NULL, &iTCPSessMax, STD_LOADABLE_MODULE_ID));
|
||||
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverkeepalive", 0, eCmdHdlrBinary,
|
||||
CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputgssserverkeepalive", 0, eCmdHdlrBinary,
|
||||
NULL, &bKeepAlive, STD_LOADABLE_MODULE_ID));
|
||||
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
|
||||
resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
|
||||
|
||||
@ -1564,12 +1564,12 @@ CODESTARTafterRun
|
||||
}
|
||||
|
||||
/* Close the UNIX sockets. */
|
||||
for (i = 0; i < nfd; i++)
|
||||
for (i = 0; i < nfd; i++)
|
||||
if (listeners[i].fd != -1)
|
||||
close(listeners[i].fd);
|
||||
|
||||
/* Clean-up files. */
|
||||
for(i = startIndexUxLocalSockets; i < nfd; i++)
|
||||
/* Clean-up files. */
|
||||
for(i = startIndexUxLocalSockets; i < nfd; i++)
|
||||
if (listeners[i].sockName && listeners[i].fd != -1) {
|
||||
/* If systemd passed us a socket it is systemd's job to clean it up.
|
||||
* Do not unlink it -- we will get same socket (node) from systemd
|
||||
|
||||
@ -493,9 +493,9 @@ static bson_t *BSONFromJSONObject(struct json_object *json)
|
||||
return doc;
|
||||
|
||||
error:
|
||||
if(doc != NULL)
|
||||
bson_destroy(doc);
|
||||
return NULL;
|
||||
if(doc != NULL)
|
||||
bson_destroy(doc);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -564,7 +564,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
|
||||
|
||||
BEGINmodExit
|
||||
CODESTARTmodExit
|
||||
free(cs.pszTarget);
|
||||
free(cs.pszTarget);
|
||||
free(cs.pszCommunity);
|
||||
free(cs.pszEnterpriseOID);
|
||||
free(cs.pszSnmpTrapOID);
|
||||
|
||||
@ -219,19 +219,19 @@ CODESTARTparse2
|
||||
}
|
||||
/* Note: date parser strips ": ", so we cannot do the delimiter check here */
|
||||
|
||||
/* XR RSP (optional) */
|
||||
if(pInst->bXrPresent) {
|
||||
while( lenMsg > 1
|
||||
&& !(*p2parse == '%')) {
|
||||
--lenMsg;
|
||||
p2parse++;
|
||||
}
|
||||
/* delimiter check */
|
||||
if(lenMsg < 2) {
|
||||
DBGPRINTF("pmciscoios: fail after XR tag search: '%s'\n", p2parse);
|
||||
ABORT_FINALIZE(RS_RET_COULD_NOT_PARSE);
|
||||
}
|
||||
}
|
||||
/* XR RSP (optional) */
|
||||
if(pInst->bXrPresent) {
|
||||
while( lenMsg > 1
|
||||
&& !(*p2parse == '%')) {
|
||||
--lenMsg;
|
||||
p2parse++;
|
||||
}
|
||||
/* delimiter check */
|
||||
if(lenMsg < 2) {
|
||||
DBGPRINTF("pmciscoios: fail after XR tag search: '%s'\n", p2parse);
|
||||
ABORT_FINALIZE(RS_RET_COULD_NOT_PARSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* parse SYSLOG TAG. must always start with '%', else we have a field mismatch */
|
||||
if(lenMsg < 1 || *p2parse != '%') {
|
||||
|
||||
@ -626,7 +626,7 @@ BEGINAbstractObjClassInit(conf, 1, OBJ_IS_CORE_MODULE) /* class, version - CHANG
|
||||
CHKiRet(objUse(net, LM_NET_FILENAME)); /* TODO: make this dependcy go away! */
|
||||
CHKiRet(objUse(ruleset, CORE_COMPONENT));
|
||||
|
||||
/* These commands will NOT be supported -- the new v6.3 config system provides
|
||||
/* These commands will NOT be supported -- the new v6.3 config system provides
|
||||
* far better methods. We will remove the related code soon. -- rgerhards, 2012-01-09
|
||||
*/
|
||||
CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables,
|
||||
|
||||
@ -575,20 +575,20 @@ int dbgMutexLock(pthread_mutex_t *pmut, dbgFuncDB_t *pFuncDB, int ln, int iStack
|
||||
/* wrapper for pthread_mutex_trylock() */
|
||||
int dbgMutexTryLock(pthread_mutex_t *pmut, dbgFuncDB_t *pFuncDB, int ln, int iStackPtr)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
dbgRecordExecLocation(iStackPtr, ln);
|
||||
dbgMutexPreLockLog(pmut, pFuncDB, ln); // TODO : update this
|
||||
ret = pthread_mutex_trylock(pmut);
|
||||
if(ret == 0 || ret == EBUSY) {
|
||||
// TODO : update this
|
||||
dbgMutexLockLog(pmut, pFuncDB, ln);
|
||||
} else {
|
||||
dbgprintf("%s:%d:%s: ERROR: pthread_mutex_trylock() for mutex %p failed with error %d\n",
|
||||
pFuncDB->file, ln, pFuncDB->func, (void*)pmut, ret);
|
||||
}
|
||||
dbgRecordExecLocation(iStackPtr, ln);
|
||||
dbgMutexPreLockLog(pmut, pFuncDB, ln); // TODO : update this
|
||||
ret = pthread_mutex_trylock(pmut);
|
||||
if(ret == 0 || ret == EBUSY) {
|
||||
// TODO : update this
|
||||
dbgMutexLockLog(pmut, pFuncDB, ln);
|
||||
} else {
|
||||
dbgprintf("%s:%d:%s: ERROR: pthread_mutex_trylock() for mutex %p failed with error %d\n",
|
||||
pFuncDB->file, ln, pFuncDB->func, (void*)pmut, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -730,9 +730,9 @@ static void dbgCallStackDestruct(void *arg)
|
||||
free(pThrd->pszThrdName);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&mutCallStack);
|
||||
pthread_mutex_lock(&mutCallStack);
|
||||
DLL_Del(CallStack, pThrd);
|
||||
pthread_mutex_unlock(&mutCallStack);
|
||||
pthread_mutex_unlock(&mutCallStack);
|
||||
}
|
||||
|
||||
|
||||
@ -965,7 +965,7 @@ checkDbgFile(const char *srcname)
|
||||
* time being. -- rgerhards, 2008-01-29
|
||||
*/
|
||||
#ifndef DEBUGLESS
|
||||
void
|
||||
void
|
||||
r_dbgoprint( const char *srcname, obj_t *pObj, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -194,8 +194,8 @@ findEntry(struct sockaddr_storage *addr)
|
||||
*/
|
||||
static int
|
||||
mygetnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||
char *host, size_t hostlen,
|
||||
char *serv, size_t servlen, int flags)
|
||||
char *host, size_t hostlen,
|
||||
char *serv, size_t servlen, int flags)
|
||||
{
|
||||
int iCancelStateSave;
|
||||
int i;
|
||||
@ -296,10 +296,10 @@ resolveAddr(struct sockaddr_storage *addr, dnscache_entry_t *etry)
|
||||
rs_size_t fqdnLen;
|
||||
rs_size_t i;
|
||||
|
||||
error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *)addr),
|
||||
error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *)addr),
|
||||
(char*) szIP, sizeof(szIP), NULL, 0, NI_NUMERICHOST);
|
||||
if(error) {
|
||||
dbgprintf("Malformed from address %s\n", gai_strerror(error));
|
||||
if(error) {
|
||||
dbgprintf("Malformed from address %s\n", gai_strerror(error));
|
||||
ABORT_FINALIZE(RS_RET_INVALID_SOURCE);
|
||||
}
|
||||
|
||||
@ -310,7 +310,7 @@ resolveAddr(struct sockaddr_storage *addr, dnscache_entry_t *etry)
|
||||
|
||||
error = mygetnameinfo((struct sockaddr *)addr, SALEN((struct sockaddr *) addr),
|
||||
fqdnBuf, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
|
||||
if(error == 0) {
|
||||
memset (&hints, 0, sizeof (struct addrinfo));
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
@ -375,13 +375,13 @@ finalize_it:
|
||||
/* we need to create the inputName property (only once during our lifetime) */
|
||||
prop.CreateStringProp(&etry->ip, (uchar*)szIP, strlen(szIP));
|
||||
|
||||
if(error || glbl.GetDisableDNS()) {
|
||||
dbgprintf("Host name for your address (%s) unknown\n", szIP);
|
||||
if(error || glbl.GetDisableDNS()) {
|
||||
dbgprintf("Host name for your address (%s) unknown\n", szIP);
|
||||
prop.AddRef(etry->ip);
|
||||
etry->fqdn = etry->ip;
|
||||
prop.AddRef(etry->ip);
|
||||
etry->fqdnLowerCase = etry->ip;
|
||||
}
|
||||
}
|
||||
|
||||
setLocalHostName(etry);
|
||||
|
||||
|
||||
@ -149,21 +149,21 @@ static int read_all(int fd, char *buf, unsigned int nbyte)
|
||||
|
||||
static int write_all(int fd, char *buf, unsigned int nbyte)
|
||||
{
|
||||
int ret;
|
||||
char *ptr;
|
||||
int ret;
|
||||
char *ptr;
|
||||
|
||||
for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) {
|
||||
ret = send(fd, ptr, nbyte, 0);
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return (ret);
|
||||
} else if (ret == 0) {
|
||||
return (ptr - buf);
|
||||
for (ptr = buf; nbyte; ptr += ret, nbyte -= ret) {
|
||||
ret = send(fd, ptr, nbyte, 0);
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
return (ret);
|
||||
} else if (ret == 0) {
|
||||
return (ptr - buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (ptr - buf);
|
||||
return (ptr - buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
|
||||
/*
|
||||
Credit for primes table: Aaron Krowne
|
||||
http://br.endernet.org/~akrowne/
|
||||
http://planetmath.org/encyclopedia/GoodHashTablePrimes.html
|
||||
http://br.endernet.org/~akrowne/
|
||||
http://planetmath.org/encyclopedia/GoodHashTablePrimes.html
|
||||
*/
|
||||
static const unsigned int primes[] = {
|
||||
53, 97, 193, 389,
|
||||
@ -40,36 +40,36 @@ const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
|
||||
static inline unsigned
|
||||
getLoadLimit(unsigned size)
|
||||
{
|
||||
return (unsigned int) ((unsigned long long) size * MAX_LOAD_FACTOR) / 100;
|
||||
return (unsigned int) ((unsigned long long) size * MAX_LOAD_FACTOR) / 100;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
struct hashtable *
|
||||
create_hashtable(unsigned int minsize,
|
||||
unsigned int (*hashf) (void*),
|
||||
int (*eqf) (void*,void*), void (*dest)(void*))
|
||||
unsigned int (*hashf) (void*),
|
||||
int (*eqf) (void*,void*), void (*dest)(void*))
|
||||
{
|
||||
struct hashtable *h;
|
||||
unsigned int pindex, size = primes[0];
|
||||
/* Check requested hashtable isn't too large */
|
||||
if (minsize > (1u << 30)) return NULL;
|
||||
/* Enforce size as prime */
|
||||
for (pindex=0; pindex < prime_table_length; pindex++) {
|
||||
if (primes[pindex] > minsize) { size = primes[pindex]; break; }
|
||||
}
|
||||
h = (struct hashtable *)malloc(sizeof(struct hashtable));
|
||||
if (NULL == h) return NULL; /*oom*/
|
||||
h->table = (struct entry **)malloc(sizeof(struct entry*) * size);
|
||||
if (NULL == h->table) { free(h); return NULL; } /*oom*/
|
||||
memset(h->table, 0, size * sizeof(struct entry *));
|
||||
h->tablelength = size;
|
||||
h->primeindex = pindex;
|
||||
h->entrycount = 0;
|
||||
h->hashfn = hashf;
|
||||
h->eqfn = eqf;
|
||||
h->dest = dest;
|
||||
h->loadlimit = getLoadLimit(size);
|
||||
return h;
|
||||
struct hashtable *h;
|
||||
unsigned int pindex, size = primes[0];
|
||||
/* Check requested hashtable isn't too large */
|
||||
if (minsize > (1u << 30)) return NULL;
|
||||
/* Enforce size as prime */
|
||||
for (pindex=0; pindex < prime_table_length; pindex++) {
|
||||
if (primes[pindex] > minsize) { size = primes[pindex]; break; }
|
||||
}
|
||||
h = (struct hashtable *)malloc(sizeof(struct hashtable));
|
||||
if (NULL == h) return NULL; /*oom*/
|
||||
h->table = (struct entry **)malloc(sizeof(struct entry*) * size);
|
||||
if (NULL == h->table) { free(h); return NULL; } /*oom*/
|
||||
memset(h->table, 0, size * sizeof(struct entry *));
|
||||
h->tablelength = size;
|
||||
h->primeindex = pindex;
|
||||
h->entrycount = 0;
|
||||
h->hashfn = hashf;
|
||||
h->eqfn = eqf;
|
||||
h->dest = dest;
|
||||
h->loadlimit = getLoadLimit(size);
|
||||
return h;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -82,158 +82,158 @@ __attribute__((no_sanitize("unsigned-integer-overflow")))
|
||||
#endif
|
||||
hash(struct hashtable *h, void *k)
|
||||
{
|
||||
/* Aim to protect against poor hash functions by adding logic here
|
||||
* - logic taken from java 1.4 hashtable source */
|
||||
unsigned int i = h->hashfn(k);
|
||||
i += ~(i << 9);
|
||||
i ^= ((i >> 14) | (i << 18)); /* >>> */
|
||||
i += (i << 4);
|
||||
i ^= ((i >> 10) | (i << 22)); /* >>> */
|
||||
return i;
|
||||
/* Aim to protect against poor hash functions by adding logic here
|
||||
* - logic taken from java 1.4 hashtable source */
|
||||
unsigned int i = h->hashfn(k);
|
||||
i += ~(i << 9);
|
||||
i ^= ((i >> 14) | (i << 18)); /* >>> */
|
||||
i += (i << 4);
|
||||
i ^= ((i >> 10) | (i << 22)); /* >>> */
|
||||
return i;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
static int
|
||||
hashtable_expand(struct hashtable *h)
|
||||
{
|
||||
/* Double the size of the table to accomodate more entries */
|
||||
struct entry **newtable;
|
||||
struct entry *e;
|
||||
struct entry **pE;
|
||||
unsigned int newsize, i, idx;
|
||||
/* Check we're not hitting max capacity */
|
||||
if (h->primeindex == (prime_table_length - 1)) return 0;
|
||||
newsize = primes[++(h->primeindex)];
|
||||
/* Double the size of the table to accomodate more entries */
|
||||
struct entry **newtable;
|
||||
struct entry *e;
|
||||
struct entry **pE;
|
||||
unsigned int newsize, i, idx;
|
||||
/* Check we're not hitting max capacity */
|
||||
if (h->primeindex == (prime_table_length - 1)) return 0;
|
||||
newsize = primes[++(h->primeindex)];
|
||||
|
||||
newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize);
|
||||
if (NULL != newtable)
|
||||
{
|
||||
memset(newtable, 0, newsize * sizeof(struct entry *));
|
||||
/* This algorithm is not 'stable'. ie. it reverses the list
|
||||
* when it transfers entries between the tables */
|
||||
for (i = 0; i < h->tablelength; i++) {
|
||||
while (NULL != (e = h->table[i])) {
|
||||
h->table[i] = e->next;
|
||||
idx = indexFor(newsize,e->h);
|
||||
e->next = newtable[idx];
|
||||
newtable[idx] = e;
|
||||
}
|
||||
}
|
||||
free(h->table);
|
||||
h->table = newtable;
|
||||
}
|
||||
/* Plan B: realloc instead */
|
||||
else
|
||||
{
|
||||
newtable = (struct entry **)
|
||||
realloc(h->table, newsize * sizeof(struct entry *));
|
||||
if (NULL == newtable) { (h->primeindex)--; return 0; }
|
||||
h->table = newtable;
|
||||
memset(newtable[h->tablelength], 0, newsize - h->tablelength);
|
||||
for (i = 0; i < h->tablelength; i++) {
|
||||
for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) {
|
||||
idx = indexFor(newsize,e->h);
|
||||
if (idx == i)
|
||||
{
|
||||
pE = &(e->next);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pE = e->next;
|
||||
e->next = newtable[idx];
|
||||
newtable[idx] = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
h->tablelength = newsize;
|
||||
h->loadlimit = getLoadLimit(newsize);
|
||||
return -1;
|
||||
newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize);
|
||||
if (NULL != newtable)
|
||||
{
|
||||
memset(newtable, 0, newsize * sizeof(struct entry *));
|
||||
/* This algorithm is not 'stable'. ie. it reverses the list
|
||||
* when it transfers entries between the tables */
|
||||
for (i = 0; i < h->tablelength; i++) {
|
||||
while (NULL != (e = h->table[i])) {
|
||||
h->table[i] = e->next;
|
||||
idx = indexFor(newsize,e->h);
|
||||
e->next = newtable[idx];
|
||||
newtable[idx] = e;
|
||||
}
|
||||
}
|
||||
free(h->table);
|
||||
h->table = newtable;
|
||||
}
|
||||
/* Plan B: realloc instead */
|
||||
else
|
||||
{
|
||||
newtable = (struct entry **)
|
||||
realloc(h->table, newsize * sizeof(struct entry *));
|
||||
if (NULL == newtable) { (h->primeindex)--; return 0; }
|
||||
h->table = newtable;
|
||||
memset(newtable[h->tablelength], 0, newsize - h->tablelength);
|
||||
for (i = 0; i < h->tablelength; i++) {
|
||||
for (pE = &(newtable[i]), e = *pE; e != NULL; e = *pE) {
|
||||
idx = indexFor(newsize,e->h);
|
||||
if (idx == i)
|
||||
{
|
||||
pE = &(e->next);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pE = e->next;
|
||||
e->next = newtable[idx];
|
||||
newtable[idx] = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
h->tablelength = newsize;
|
||||
h->loadlimit = getLoadLimit(newsize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
unsigned int
|
||||
hashtable_count(struct hashtable *h)
|
||||
{
|
||||
return h->entrycount;
|
||||
return h->entrycount;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
hashtable_insert(struct hashtable *h, void *k, void *v)
|
||||
{
|
||||
/* This method allows duplicate keys - but they shouldn't be used */
|
||||
unsigned int idx;
|
||||
struct entry *e;
|
||||
if (++(h->entrycount) > h->loadlimit)
|
||||
{
|
||||
/* Ignore the return value. If expand fails, we should
|
||||
* still try cramming just this value into the existing table
|
||||
* -- we may not have memory for a larger table, but one more
|
||||
* element may be ok. Next time we insert, we'll try expanding again.*/
|
||||
hashtable_expand(h);
|
||||
}
|
||||
e = (struct entry *)malloc(sizeof(struct entry));
|
||||
if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
|
||||
e->h = hash(h,k);
|
||||
idx = indexFor(h->tablelength,e->h);
|
||||
e->k = k;
|
||||
e->v = v;
|
||||
e->next = h->table[idx];
|
||||
h->table[idx] = e;
|
||||
return -1;
|
||||
/* This method allows duplicate keys - but they shouldn't be used */
|
||||
unsigned int idx;
|
||||
struct entry *e;
|
||||
if (++(h->entrycount) > h->loadlimit)
|
||||
{
|
||||
/* Ignore the return value. If expand fails, we should
|
||||
* still try cramming just this value into the existing table
|
||||
* -- we may not have memory for a larger table, but one more
|
||||
* element may be ok. Next time we insert, we'll try expanding again.*/
|
||||
hashtable_expand(h);
|
||||
}
|
||||
e = (struct entry *)malloc(sizeof(struct entry));
|
||||
if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
|
||||
e->h = hash(h,k);
|
||||
idx = indexFor(h->tablelength,e->h);
|
||||
e->k = k;
|
||||
e->v = v;
|
||||
e->next = h->table[idx];
|
||||
h->table[idx] = e;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void * /* returns value associated with key */
|
||||
hashtable_search(struct hashtable *h, void *k)
|
||||
{
|
||||
struct entry *e;
|
||||
unsigned int hashvalue, idx;
|
||||
hashvalue = hash(h,k);
|
||||
idx = indexFor(h->tablelength,hashvalue);
|
||||
e = h->table[idx];
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v;
|
||||
e = e->next;
|
||||
}
|
||||
return NULL;
|
||||
struct entry *e;
|
||||
unsigned int hashvalue, idx;
|
||||
hashvalue = hash(h,k);
|
||||
idx = indexFor(h->tablelength,hashvalue);
|
||||
e = h->table[idx];
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k))) return e->v;
|
||||
e = e->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
void * /* returns value associated with key */
|
||||
hashtable_remove(struct hashtable *h, void *k)
|
||||
{
|
||||
/* TODO: consider compacting the table when the load factor drops enough,
|
||||
* or provide a 'compact' method. */
|
||||
/* TODO: consider compacting the table when the load factor drops enough,
|
||||
* or provide a 'compact' method. */
|
||||
|
||||
struct entry *e;
|
||||
struct entry **pE;
|
||||
void *v;
|
||||
unsigned int hashvalue, idx;
|
||||
struct entry *e;
|
||||
struct entry **pE;
|
||||
void *v;
|
||||
unsigned int hashvalue, idx;
|
||||
|
||||
hashvalue = hash(h,k);
|
||||
idx = indexFor(h->tablelength,hash(h,k));
|
||||
pE = &(h->table[idx]);
|
||||
e = *pE;
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
|
||||
{
|
||||
*pE = e->next;
|
||||
h->entrycount--;
|
||||
v = e->v;
|
||||
freekey(e->k);
|
||||
free(e);
|
||||
return v;
|
||||
}
|
||||
pE = &(e->next);
|
||||
e = e->next;
|
||||
}
|
||||
return NULL;
|
||||
hashvalue = hash(h,k);
|
||||
idx = indexFor(h->tablelength,hash(h,k));
|
||||
pE = &(h->table[idx]);
|
||||
e = *pE;
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
|
||||
{
|
||||
*pE = e->next;
|
||||
h->entrycount--;
|
||||
v = e->v;
|
||||
freekey(e->k);
|
||||
free(e);
|
||||
return v;
|
||||
}
|
||||
pE = &(e->next);
|
||||
e = e->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -241,38 +241,38 @@ hashtable_remove(struct hashtable *h, void *k)
|
||||
void
|
||||
hashtable_destroy(struct hashtable *h, int free_values)
|
||||
{
|
||||
unsigned int i;
|
||||
struct entry *e, *f;
|
||||
struct entry **table = h->table;
|
||||
if (free_values)
|
||||
{
|
||||
for (i = 0; i < h->tablelength; i++)
|
||||
{
|
||||
e = table[i];
|
||||
while (NULL != e)
|
||||
{
|
||||
f = e;
|
||||
e = e->next;
|
||||
freekey(f->k);
|
||||
if(h->dest == NULL)
|
||||
free(f->v);
|
||||
else
|
||||
h->dest(f->v);
|
||||
free(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < h->tablelength; i++)
|
||||
{
|
||||
e = table[i];
|
||||
while (NULL != e)
|
||||
{ f = e; e = e->next; freekey(f->k); free(f); }
|
||||
}
|
||||
}
|
||||
free(h->table);
|
||||
free(h);
|
||||
unsigned int i;
|
||||
struct entry *e, *f;
|
||||
struct entry **table = h->table;
|
||||
if (free_values)
|
||||
{
|
||||
for (i = 0; i < h->tablelength; i++)
|
||||
{
|
||||
e = table[i];
|
||||
while (NULL != e)
|
||||
{
|
||||
f = e;
|
||||
e = e->next;
|
||||
freekey(f->k);
|
||||
if(h->dest == NULL)
|
||||
free(f->v);
|
||||
else
|
||||
h->dest(f->v);
|
||||
free(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < h->tablelength; i++)
|
||||
{
|
||||
e = table[i];
|
||||
while (NULL != e)
|
||||
{ f = e; e = e->next; freekey(f->k); free(f); }
|
||||
}
|
||||
}
|
||||
free(h->table);
|
||||
free(h);
|
||||
}
|
||||
|
||||
/* some generic hash functions */
|
||||
@ -289,13 +289,13 @@ __attribute__((no_sanitize("unsigned-integer-overflow")))
|
||||
#endif
|
||||
hash_from_string(void *k)
|
||||
{
|
||||
char *rkey = (char*) k;
|
||||
unsigned hashval = 1;
|
||||
char *rkey = (char*) k;
|
||||
unsigned hashval = 1;
|
||||
|
||||
while (*rkey)
|
||||
hashval = hashval * 33 + *rkey++;
|
||||
while (*rkey)
|
||||
hashval = hashval * 33 + *rkey++;
|
||||
|
||||
return hashval;
|
||||
return hashval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -18,23 +18,23 @@
|
||||
int
|
||||
hashtable_change(struct hashtable *h, void *k, void *v)
|
||||
{
|
||||
struct entry *e;
|
||||
unsigned int hashvalue, index;
|
||||
hashvalue = hash(h,k);
|
||||
index = indexFor(h->tablelength,hashvalue);
|
||||
e = h->table[index];
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
|
||||
{
|
||||
free(e->v);
|
||||
e->v = v;
|
||||
return -1;
|
||||
}
|
||||
e = e->next;
|
||||
}
|
||||
return 0;
|
||||
struct entry *e;
|
||||
unsigned int hashvalue, index;
|
||||
hashvalue = hash(h,k);
|
||||
index = indexFor(h->tablelength,hashvalue);
|
||||
e = h->table[index];
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
|
||||
{
|
||||
free(e->v);
|
||||
e->v = v;
|
||||
return -1;
|
||||
}
|
||||
e = e->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -14,12 +14,12 @@ typedef unsigned short uint16_t;
|
||||
/*****************************************************************************/
|
||||
struct key
|
||||
{
|
||||
uint32_t one_ip; uint32_t two_ip; uint16_t one_port; uint16_t two_port;
|
||||
uint32_t one_ip; uint32_t two_ip; uint16_t one_port; uint16_t two_port;
|
||||
};
|
||||
|
||||
struct value
|
||||
{
|
||||
char *id;
|
||||
char *id;
|
||||
};
|
||||
|
||||
DEFINE_HASHTABLE_INSERT(insert_some, struct key, struct value);
|
||||
@ -32,208 +32,208 @@ DEFINE_HASHTABLE_ITERATOR_SEARCH(search_itr_some, struct key);
|
||||
static unsigned int
|
||||
hashfromkey(void *ky)
|
||||
{
|
||||
struct key *k = (struct key *)ky;
|
||||
return (((k->one_ip << 17) | (k->one_ip >> 15)) ^ k->two_ip) +
|
||||
(k->one_port * 17) + (k->two_port * 13 * 29);
|
||||
struct key *k = (struct key *)ky;
|
||||
return (((k->one_ip << 17) | (k->one_ip >> 15)) ^ k->two_ip) +
|
||||
(k->one_port * 17) + (k->two_port * 13 * 29);
|
||||
}
|
||||
|
||||
static int
|
||||
equalkeys(void *k1, void *k2)
|
||||
{
|
||||
return (0 == memcmp(k1,k2,sizeof(struct key)));
|
||||
return (0 == memcmp(k1,k2,sizeof(struct key)));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct key *k, *kk;
|
||||
struct value *v, *found;
|
||||
struct hashtable *h;
|
||||
struct hashtable_itr *itr;
|
||||
int i;
|
||||
struct key *k, *kk;
|
||||
struct value *v, *found;
|
||||
struct hashtable *h;
|
||||
struct hashtable_itr *itr;
|
||||
int i;
|
||||
|
||||
h = create_hashtable(16, hashfromkey, equalkeys);
|
||||
if (NULL == h) exit(-1); /*oom*/
|
||||
h = create_hashtable(16, hashfromkey, equalkeys);
|
||||
if (NULL == h) exit(-1); /*oom*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Insertion */
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
if (NULL == k) {
|
||||
printf("ran out of memory allocating a key\n");
|
||||
return 1;
|
||||
}
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
if (NULL == k) {
|
||||
printf("ran out of memory allocating a key\n");
|
||||
return 1;
|
||||
}
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
|
||||
v = (struct value *)malloc(sizeof(struct value));
|
||||
v->id = "a value";
|
||||
v = (struct value *)malloc(sizeof(struct value));
|
||||
v->id = "a value";
|
||||
|
||||
if (!insert_some(h,k,v)) exit(-1); /*oom*/
|
||||
}
|
||||
printf("After insertion, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
if (!insert_some(h,k,v)) exit(-1); /*oom*/
|
||||
}
|
||||
printf("After insertion, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable search */
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
if (NULL == k) {
|
||||
printf("ran out of memory allocating a key\n");
|
||||
return 1;
|
||||
}
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
if (NULL == k) {
|
||||
printf("ran out of memory allocating a key\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
|
||||
if (NULL == (found = search_some(h,k))) {
|
||||
printf("BUG: key not found\n");
|
||||
}
|
||||
}
|
||||
if (NULL == (found = search_some(h,k))) {
|
||||
printf("BUG: key not found\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable iteration */
|
||||
/* Iterator constructor only returns a valid iterator if
|
||||
* the hashtable is not empty */
|
||||
itr = hashtable_iterator(h);
|
||||
i = 0;
|
||||
if (hashtable_count(h) > 0)
|
||||
{
|
||||
do {
|
||||
kk = hashtable_iterator_key(itr);
|
||||
v = hashtable_iterator_value(itr);
|
||||
/* here (kk,v) are a valid (key, value) pair */
|
||||
/* We could call 'hashtable_remove(h,kk)' - and this operation
|
||||
* 'free's kk. However, the iterator is then broken.
|
||||
* This is why hashtable_iterator_remove exists - see below.
|
||||
*/
|
||||
i++;
|
||||
/* Iterator constructor only returns a valid iterator if
|
||||
* the hashtable is not empty */
|
||||
itr = hashtable_iterator(h);
|
||||
i = 0;
|
||||
if (hashtable_count(h) > 0)
|
||||
{
|
||||
do {
|
||||
kk = hashtable_iterator_key(itr);
|
||||
v = hashtable_iterator_value(itr);
|
||||
/* here (kk,v) are a valid (key, value) pair */
|
||||
/* We could call 'hashtable_remove(h,kk)' - and this operation
|
||||
* 'free's kk. However, the iterator is then broken.
|
||||
* This is why hashtable_iterator_remove exists - see below.
|
||||
*/
|
||||
i++;
|
||||
|
||||
} while (hashtable_iterator_advance(itr));
|
||||
}
|
||||
printf("Iterated through %u entries.\n", i);
|
||||
} while (hashtable_iterator_advance(itr));
|
||||
}
|
||||
printf("Iterated through %u entries.\n", i);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable iterator search */
|
||||
|
||||
/* Try the search some method */
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
/* Try the search some method */
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
|
||||
if (0 == search_itr_some(itr,h,k)) {
|
||||
printf("BUG: key not found searching with iterator");
|
||||
}
|
||||
}
|
||||
if (0 == search_itr_some(itr,h,k)) {
|
||||
printf("BUG: key not found searching with iterator");
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable removal */
|
||||
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
|
||||
if (NULL == (found = remove_some(h,k))) {
|
||||
printf("BUG: key not found for removal\n");
|
||||
}
|
||||
}
|
||||
printf("After removal, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
if (NULL == (found = remove_some(h,k))) {
|
||||
printf("BUG: key not found for removal\n");
|
||||
}
|
||||
}
|
||||
printf("After removal, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable destroy and create */
|
||||
|
||||
hashtable_destroy(h, 1);
|
||||
h = NULL;
|
||||
free(k);
|
||||
hashtable_destroy(h, 1);
|
||||
h = NULL;
|
||||
free(k);
|
||||
|
||||
h = create_hashtable(160, hashfromkey, equalkeys);
|
||||
if (NULL == h) {
|
||||
printf("out of memory allocating second hashtable\n");
|
||||
return 1;
|
||||
}
|
||||
h = create_hashtable(160, hashfromkey, equalkeys);
|
||||
if (NULL == h) {
|
||||
printf("out of memory allocating second hashtable\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable insertion */
|
||||
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
for (i = 0; i < ITEM_COUNT; i++)
|
||||
{
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
|
||||
v = (struct value *)malloc(sizeof(struct value));
|
||||
v->id = "a value";
|
||||
v = (struct value *)malloc(sizeof(struct value));
|
||||
v->id = "a value";
|
||||
|
||||
if (!insert_some(h,k,v))
|
||||
{
|
||||
printf("out of memory inserting into second hashtable\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("After insertion, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
if (!insert_some(h,k,v))
|
||||
{
|
||||
printf("out of memory inserting into second hashtable\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("After insertion, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable iterator search and iterator remove */
|
||||
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
if (NULL == k) {
|
||||
printf("ran out of memory allocating a key\n");
|
||||
return 1;
|
||||
}
|
||||
k = (struct key *)malloc(sizeof(struct key));
|
||||
if (NULL == k) {
|
||||
printf("ran out of memory allocating a key\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = ITEM_COUNT - 1; i >= 0; i = i - 7)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
for (i = ITEM_COUNT - 1; i >= 0; i = i - 7)
|
||||
{
|
||||
k->one_ip = 0xcfccee40 + i;
|
||||
k->two_ip = 0xcf0cee67 - (5 * i);
|
||||
k->one_port = 22 + (7 * i);
|
||||
k->two_port = 5522 - (3 * i);
|
||||
|
||||
if (0 == search_itr_some(itr, h, k)) {
|
||||
printf("BUG: key %u not found for search preremoval using iterator\n", i);
|
||||
return 1;
|
||||
}
|
||||
if (0 == hashtable_iterator_remove(itr)) {
|
||||
printf("BUG: key not found for removal using iterator\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
free(itr);
|
||||
if (0 == search_itr_some(itr, h, k)) {
|
||||
printf("BUG: key %u not found for search preremoval using iterator\n", i);
|
||||
return 1;
|
||||
}
|
||||
if (0 == hashtable_iterator_remove(itr)) {
|
||||
printf("BUG: key not found for removal using iterator\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
free(itr);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable iterator remove and advance */
|
||||
|
||||
for (itr = hashtable_iterator(h);
|
||||
hashtable_iterator_remove(itr) != 0; ) {
|
||||
;
|
||||
}
|
||||
free(itr);
|
||||
printf("After removal, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
for (itr = hashtable_iterator(h);
|
||||
hashtable_iterator_remove(itr) != 0; ) {
|
||||
;
|
||||
}
|
||||
free(itr);
|
||||
printf("After removal, hashtable contains %u items.\n",
|
||||
hashtable_count(h));
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Hashtable destroy */
|
||||
|
||||
hashtable_destroy(h, 1);
|
||||
free(k);
|
||||
return 0;
|
||||
hashtable_destroy(h, 1);
|
||||
free(k);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -10,27 +10,27 @@
|
||||
struct hashtable_itr *
|
||||
hashtable_iterator(struct hashtable *h)
|
||||
{
|
||||
unsigned int i, tablelength;
|
||||
struct hashtable_itr *itr = (struct hashtable_itr *)
|
||||
malloc(sizeof(struct hashtable_itr));
|
||||
if (NULL == itr) return NULL;
|
||||
itr->h = h;
|
||||
itr->e = NULL;
|
||||
itr->parent = NULL;
|
||||
tablelength = h->tablelength;
|
||||
itr->index = tablelength;
|
||||
if (0 == h->entrycount) return itr;
|
||||
unsigned int i, tablelength;
|
||||
struct hashtable_itr *itr = (struct hashtable_itr *)
|
||||
malloc(sizeof(struct hashtable_itr));
|
||||
if (NULL == itr) return NULL;
|
||||
itr->h = h;
|
||||
itr->e = NULL;
|
||||
itr->parent = NULL;
|
||||
tablelength = h->tablelength;
|
||||
itr->index = tablelength;
|
||||
if (0 == h->entrycount) return itr;
|
||||
|
||||
for (i = 0; i < tablelength; i++)
|
||||
{
|
||||
if (NULL != h->table[i])
|
||||
{
|
||||
itr->e = h->table[i];
|
||||
itr->index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return itr;
|
||||
for (i = 0; i < tablelength; i++)
|
||||
{
|
||||
if (NULL != h->table[i])
|
||||
{
|
||||
itr->e = h->table[i];
|
||||
itr->index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return itr;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -54,38 +54,38 @@ hashtable_iterator_value(struct hashtable_itr *i)
|
||||
int
|
||||
hashtable_iterator_advance(struct hashtable_itr *itr)
|
||||
{
|
||||
unsigned int j,tablelength;
|
||||
struct entry **table;
|
||||
struct entry *next;
|
||||
if (NULL == itr->e) return 0; /* stupidity check */
|
||||
unsigned int j,tablelength;
|
||||
struct entry **table;
|
||||
struct entry *next;
|
||||
if (NULL == itr->e) return 0; /* stupidity check */
|
||||
|
||||
next = itr->e->next;
|
||||
if (NULL != next)
|
||||
{
|
||||
itr->parent = itr->e;
|
||||
itr->e = next;
|
||||
return -1;
|
||||
}
|
||||
tablelength = itr->h->tablelength;
|
||||
itr->parent = NULL;
|
||||
if (tablelength <= (j = ++(itr->index)))
|
||||
{
|
||||
itr->e = NULL;
|
||||
return 0;
|
||||
}
|
||||
table = itr->h->table;
|
||||
while (NULL == (next = table[j]))
|
||||
{
|
||||
if (++j >= tablelength)
|
||||
{
|
||||
itr->index = tablelength;
|
||||
itr->e = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
itr->index = j;
|
||||
itr->e = next;
|
||||
return -1;
|
||||
next = itr->e->next;
|
||||
if (NULL != next)
|
||||
{
|
||||
itr->parent = itr->e;
|
||||
itr->e = next;
|
||||
return -1;
|
||||
}
|
||||
tablelength = itr->h->tablelength;
|
||||
itr->parent = NULL;
|
||||
if (tablelength <= (j = ++(itr->index)))
|
||||
{
|
||||
itr->e = NULL;
|
||||
return 0;
|
||||
}
|
||||
table = itr->h->table;
|
||||
while (NULL == (next = table[j]))
|
||||
{
|
||||
if (++j >= tablelength)
|
||||
{
|
||||
itr->index = tablelength;
|
||||
itr->e = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
itr->index = j;
|
||||
itr->e = next;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -99,59 +99,59 @@ hashtable_iterator_advance(struct hashtable_itr *itr)
|
||||
int
|
||||
hashtable_iterator_remove(struct hashtable_itr *itr)
|
||||
{
|
||||
struct entry *remember_e, *remember_parent;
|
||||
int ret;
|
||||
struct entry *remember_e, *remember_parent;
|
||||
int ret;
|
||||
|
||||
/* Do the removal */
|
||||
if (NULL == (itr->parent))
|
||||
{
|
||||
/* element is head of a chain */
|
||||
itr->h->table[itr->index] = itr->e->next;
|
||||
} else {
|
||||
/* element is mid-chain */
|
||||
itr->parent->next = itr->e->next;
|
||||
}
|
||||
/* itr->e is now outside the hashtable */
|
||||
remember_e = itr->e;
|
||||
itr->h->entrycount--;
|
||||
freekey(remember_e->k);
|
||||
/* Do the removal */
|
||||
if (NULL == (itr->parent))
|
||||
{
|
||||
/* element is head of a chain */
|
||||
itr->h->table[itr->index] = itr->e->next;
|
||||
} else {
|
||||
/* element is mid-chain */
|
||||
itr->parent->next = itr->e->next;
|
||||
}
|
||||
/* itr->e is now outside the hashtable */
|
||||
remember_e = itr->e;
|
||||
itr->h->entrycount--;
|
||||
freekey(remember_e->k);
|
||||
|
||||
/* Advance the iterator, correcting the parent */
|
||||
remember_parent = itr->parent;
|
||||
ret = hashtable_iterator_advance(itr);
|
||||
if (itr->parent == remember_e) { itr->parent = remember_parent; }
|
||||
free(remember_e);
|
||||
return ret;
|
||||
/* Advance the iterator, correcting the parent */
|
||||
remember_parent = itr->parent;
|
||||
ret = hashtable_iterator_advance(itr);
|
||||
if (itr->parent == remember_e) { itr->parent = remember_parent; }
|
||||
free(remember_e);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int /* returns zero if not found */
|
||||
hashtable_iterator_search(struct hashtable_itr *itr,
|
||||
struct hashtable *h, void *k)
|
||||
struct hashtable *h, void *k)
|
||||
{
|
||||
struct entry *e, *parent;
|
||||
unsigned int hashvalue, index;
|
||||
struct entry *e, *parent;
|
||||
unsigned int hashvalue, index;
|
||||
|
||||
hashvalue = hash(h,k);
|
||||
index = indexFor(h->tablelength,hashvalue);
|
||||
hashvalue = hash(h,k);
|
||||
index = indexFor(h->tablelength,hashvalue);
|
||||
|
||||
e = h->table[index];
|
||||
parent = NULL;
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
|
||||
{
|
||||
itr->index = index;
|
||||
itr->e = e;
|
||||
itr->parent = parent;
|
||||
itr->h = h;
|
||||
return -1;
|
||||
}
|
||||
parent = e;
|
||||
e = e->next;
|
||||
}
|
||||
return 0;
|
||||
e = h->table[index];
|
||||
parent = NULL;
|
||||
while (NULL != e)
|
||||
{
|
||||
/* Check hash value to short circuit heavier comparison */
|
||||
if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
|
||||
{
|
||||
itr->index = index;
|
||||
itr->e = e;
|
||||
itr->parent = parent;
|
||||
itr->h = h;
|
||||
return -1;
|
||||
}
|
||||
parent = e;
|
||||
e = e->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
* accessor functions. */
|
||||
struct hashtable_itr
|
||||
{
|
||||
struct hashtable *h;
|
||||
struct entry *e;
|
||||
struct entry *parent;
|
||||
unsigned int index;
|
||||
struct hashtable *h;
|
||||
struct entry *e;
|
||||
struct entry *parent;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
|
||||
@ -53,16 +53,16 @@ hashtable_iterator_remove(struct hashtable_itr *itr);
|
||||
/*****************************************************************************/
|
||||
/* search - overwrite the supplied iterator, to point to the entry
|
||||
* matching the supplied key.
|
||||
h points to the hashtable to be searched.
|
||||
* h points to the hashtable to be searched.
|
||||
* returns zero if not found. */
|
||||
int
|
||||
hashtable_iterator_search(struct hashtable_itr *itr,
|
||||
struct hashtable *h, void *k);
|
||||
struct hashtable *h, void *k);
|
||||
|
||||
#define DEFINE_HASHTABLE_ITERATOR_SEARCH(fnname, keytype) \
|
||||
int fnname (struct hashtable_itr *i, struct hashtable *h, keytype *k) \
|
||||
{ \
|
||||
return (hashtable_iterator_search(i,h,k)); \
|
||||
return (hashtable_iterator_search(i,h,k)); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -161,7 +161,7 @@ bool ProtectedQueue_getItem(ProtectedQueue* this, size_t index, void** item) {
|
||||
}
|
||||
|
||||
/* Waits for a new work item or timeout (if specified). Returns 0 in case of exit
|
||||
condition, 1 if item became available and ETIMEDOUT in case of timeout. */
|
||||
* condition, 1 if item became available and ETIMEDOUT in case of timeout. */
|
||||
int ProtectedQueue_waitForItem(ProtectedQueue* this, void** item, uint64_t timeout) {
|
||||
struct timespec ts;
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
|
||||
@ -410,7 +410,7 @@ rsksi_tlvRecRead(FILE *fp, tlvrecord_t *rec)
|
||||
}
|
||||
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
/* Only show debug if no fail */
|
||||
if(rsksi_read_debug && r != 0 && r != RSGTE_EOF)
|
||||
printf("debug: rsksi_tlvRecRead:\t read tlvtype %4.4x, len %u r=%d\n",
|
||||
@ -467,7 +467,7 @@ rsksi_tlvDecodeSUBREC(tlvrecord_t *rec, uint16_t *stridx, tlvrecord_t *newrec)
|
||||
(unsigned) newrec->tlvtype,
|
||||
(unsigned) newrec->tlvlen);
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r != 0) /* Only on FAIL! */
|
||||
printf("debug: rsksi_tlvDecodeSUBREC:\t\t Failed, tlv record %4.4x with error %d\n", rec->tlvtype, r);
|
||||
return r;
|
||||
@ -494,7 +494,7 @@ rsksi_tlvDecodeIMPRINT(tlvrecord_t *rec, imprint_t **imprint)
|
||||
memcpy(imp->data, rec->data+1, imp->len);
|
||||
*imprint = imp;
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0) {
|
||||
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeIMPRINT:\t\t returned %d TLVType=%4.4x, "
|
||||
"TLVLen=%d, HashID=%d\n", r, rec->tlvtype, rec->tlvlen, imp->hashID);
|
||||
@ -547,7 +547,7 @@ rsksi_tlvDecodeREC_HASH(tlvrecord_t *rec, uint16_t *strtidx, imprint_t *imp)
|
||||
if((imp->data = (uint8_t*)malloc(imp->len)) == NULL) {r=RSGTE_OOM;goto done;}
|
||||
memcpy(imp->data, subrec.data+1, subrec.tlvlen-1);
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0) {
|
||||
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeREC_HASH:\t\t returned %d TLVType=%4.4x, "
|
||||
"TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen);
|
||||
@ -572,7 +572,7 @@ rsksi_tlvDecodeLEVEL_CORR(tlvrecord_t *rec, uint16_t *strtidx, uint8_t *levelcor
|
||||
}
|
||||
*levelcorr = subrec.data[0];
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0) {
|
||||
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeLEVEL_CORR:\t returned %d TLVType=%4.4x, "
|
||||
"TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen);
|
||||
@ -588,7 +588,7 @@ rsksi_tlvDecodeHASH_STEP(tlvrecord_t *rec, uint16_t *pstrtidx, block_hashstep_t
|
||||
int r = 1;
|
||||
uint16_t strtidx = 0;
|
||||
tlvrecord_t subrec;
|
||||
*blhashstep = NULL; /* Set to NULL by default first */
|
||||
*blhashstep = NULL; /* Set to NULL by default first */
|
||||
|
||||
/* Init HashStep */
|
||||
block_hashstep_t *hashstep = NULL;
|
||||
@ -611,9 +611,9 @@ rsksi_tlvDecodeHASH_STEP(tlvrecord_t *rec, uint16_t *pstrtidx, block_hashstep_t
|
||||
goto done;
|
||||
}
|
||||
|
||||
*blhashstep = hashstep;
|
||||
*blhashstep = hashstep;
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if (r == 0) {
|
||||
if(rsksi_read_debug) printf("debug: rsksi_tlvDecodeHASH_STEP:\t returned %d, tlvtype "
|
||||
"%4.4x\n", r, (unsigned) rec->tlvtype);
|
||||
@ -656,7 +656,7 @@ rsksi_tlvDecodeHASH_CHAIN(tlvrecord_t *rec, block_hashchain_t **blhashchain)
|
||||
|
||||
*blhashchain = hashchain;
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0) {
|
||||
if (rsksi_read_debug) printf("debug: rsksi_tlvDecodeHASH_CHAIN:\t returned %d TLVType=%4.4x, "
|
||||
"TLVLen=%d\n", r, rec->tlvtype, rec->tlvlen);
|
||||
@ -751,7 +751,7 @@ rsksi_tlvDecodeSIG(tlvrecord_t *rec, uint16_t *strtidx, block_sig_t *bs)
|
||||
if((bs->sig.der.data = (uint8_t*)malloc(bs->sig.der.len)) == NULL) {r=RSGTE_OOM;goto done;}
|
||||
memcpy(bs->sig.der.data, subrec.data, bs->sig.der.len);
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(rsksi_read_debug) printf("debug: rsksi_tlvDecodeSIG:\t\t returned %d, tlvtype %4.4x\n",
|
||||
r, (unsigned) rec->tlvtype);
|
||||
return r;
|
||||
@ -776,7 +776,7 @@ rsksi_tlvDecodeBLOCK_HDR(tlvrecord_t *rec, block_hdr_t **blockhdr)
|
||||
}
|
||||
*blockhdr = bh;
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if (r == 0) {
|
||||
if(rsksi_read_debug) printf("debug: tlvDecodeBLOCK_HDR:\t\t returned %d, tlvtype %4.4x\n",
|
||||
r, (unsigned) rec->tlvtype);
|
||||
@ -808,7 +808,7 @@ rsksi_tlvDecodeEXCERPT_SIG(tlvrecord_t *rec, block_sig_t **blocksig)
|
||||
|
||||
*blocksig = bs;
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0) {
|
||||
if (rsksi_read_debug) printf("debug: tlvDecodeEXCERPT_SIG:\t returned %d, tlvtype %4.4x\n",
|
||||
r, (unsigned) rec->tlvtype);
|
||||
@ -816,7 +816,7 @@ done:
|
||||
/* Free memory on FAIL!*/
|
||||
if (bs != NULL)
|
||||
rsksi_objfree(rec->tlvtype, bs);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
static int
|
||||
@ -838,7 +838,7 @@ rsksi_tlvDecodeBLOCK_SIG(tlvrecord_t *rec, block_sig_t **blocksig)
|
||||
}
|
||||
*blocksig = bs;
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0) {
|
||||
if (rsksi_read_debug) printf("debug: tlvDecodeBLOCK_SIG:\t\t returned %d, tlvtype %4.4x, recCount "
|
||||
"%ju\n", r, (unsigned) rec->tlvtype, bs->recCount);
|
||||
@ -846,7 +846,7 @@ done:
|
||||
/* Free memory on FAIL!*/
|
||||
if (bs != NULL)
|
||||
rsksi_objfree(rec->tlvtype, bs);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
int
|
||||
@ -901,7 +901,7 @@ rsksi_tlvrdRecHash(FILE *fp, FILE *outfp, imprint_t **imp)
|
||||
if((r = rsksi_tlvwrite(outfp, &rec)) != 0) goto done;
|
||||
}
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0 && rsksi_read_debug)
|
||||
printf("debug: tlvrdRecHash:\t\t\t returned %d, rec->tlvtype %4.4x\n", r, (unsigned) rec.tlvtype);
|
||||
return r;
|
||||
@ -926,7 +926,7 @@ rsksi_tlvrdTreeHash(FILE *fp, FILE *outfp, imprint_t **imp)
|
||||
if((r = rsksi_tlvwrite(outfp, &rec)) != 0) goto done;
|
||||
}
|
||||
r = 0;
|
||||
done:
|
||||
done:
|
||||
if(r == 0 && rsksi_read_debug) printf("debug: rsksi_tlvrdTreeHash:\t\t returned %d, rec->tlvtype %4.4x\n",
|
||||
r, (unsigned) rec.tlvtype);
|
||||
return r;
|
||||
@ -974,7 +974,7 @@ rsksi_tlvrd(FILE *fp, tlvrecord_t *rec, void *obj)
|
||||
int r;
|
||||
if((r = rsksi_tlvRecRead(fp, rec)) != 0) goto done;
|
||||
r = rsksi_tlvRecDecode(rec, obj);
|
||||
done:
|
||||
done:
|
||||
if(rsksi_read_debug && r != RSGTE_SUCCESS && r != RSGTE_EOF) printf("debug: rsksi_tlvrd:\t failed with "
|
||||
"error %d\n", r);
|
||||
return r;
|
||||
@ -1025,19 +1025,19 @@ rsksi_printINT_HASH(FILE *fp, imprint_t *imp, uint8_t verbose)
|
||||
*/
|
||||
void
|
||||
rsksi_printBLOCK_HDR(FILE *fp, block_hdr_t *bh, uint8_t verbose)
|
||||
{
|
||||
{
|
||||
fprintf(fp, "[0x0901]Block Header Record:\n");
|
||||
fprintf(fp, "\tPrevious Block Hash:\n");
|
||||
fprintf(fp, "\tPrevious Block Hash:\n");
|
||||
fprintf(fp, "\t Algorithm..: %s\n", hashAlgNameKSI(bh->lastHash.hashID));
|
||||
fprintf(fp, "\t Hash.......: ");
|
||||
fprintf(fp, "\t Hash.......: ");
|
||||
outputHexBlob(fp, bh->lastHash.data, bh->lastHash.len, verbose);
|
||||
fputc('\n', fp);
|
||||
fputc('\n', fp);
|
||||
if(blobIsZero(bh->lastHash.data, bh->lastHash.len))
|
||||
fprintf(fp, "\t NOTE: New Hash Chain Start!\n");
|
||||
fprintf(fp, "\t NOTE: New Hash Chain Start!\n");
|
||||
fprintf(fp, "\tHash Algorithm: %s\n", hashAlgNameKSI(bh->hashID));
|
||||
fprintf(fp, "\tIV............: ");
|
||||
fprintf(fp, "\tIV............: ");
|
||||
outputHexBlob(fp, bh->iv, getIVLenKSI(bh), verbose);
|
||||
fputc('\n', fp);
|
||||
fputc('\n', fp);
|
||||
}
|
||||
|
||||
|
||||
@ -1223,7 +1223,7 @@ rsksiHashstepFromKSI_DataHash(ksifile ksi, KSI_DataHash *hash)
|
||||
goto done;
|
||||
}
|
||||
memcpy(hashstep->sib_hash.data, digest, digest_len);
|
||||
done:
|
||||
done:
|
||||
return hashstep;
|
||||
}
|
||||
|
||||
@ -1377,7 +1377,7 @@ rsksi_getExcerptBlockParams(FILE *fp, uint8_t bRewind, block_sig_t **bs, block_h
|
||||
default:fprintf(fp, "unknown tlv record %4.4x\n", rec.tlvtype);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Free second Signatur object if set! */
|
||||
if(bSig == 1 && obj != NULL) rsksi_objfree(rec.tlvtype, obj);
|
||||
}
|
||||
@ -1566,7 +1566,7 @@ done:
|
||||
|
||||
static int
|
||||
rsksi_vrfy_chkTreeHash(ksifile ksi, FILE *sigfp, FILE *nsigfp,
|
||||
KSI_DataHash *hash, ksierrctx_t *ectx)
|
||||
KSI_DataHash *hash, ksierrctx_t *ectx)
|
||||
{
|
||||
int r = 0;
|
||||
imprint_t *imp = NULL;
|
||||
@ -1726,11 +1726,11 @@ block_hashchain_t *hashchain, int storehashchain)
|
||||
hashstep->level_corr = 0; /* Level Correction 0 */
|
||||
if(rsksi_read_debug) outputHash(stdout, "debug: rsksi_vrfy_nextRecExtract:\t RIGHT Hash:"
|
||||
" \t\t", hashstep->sib_hash.data, hashstep->sib_hash.len, ectx->verbose);
|
||||
|
||||
|
||||
/* Attach to HashChain */
|
||||
hashchain->hashsteps[hashchain->stepCount] = hashstep;
|
||||
hashchain->stepCount++;
|
||||
|
||||
|
||||
hashchain->direction = 0x03; /* RIGHT */
|
||||
hashchain->level = 1;
|
||||
}
|
||||
@ -1773,7 +1773,7 @@ block_hashchain_t *hashchain, int storehashchain)
|
||||
hashstep->sib_hash.len, ectx->verbose);
|
||||
}
|
||||
hashstep->direction = hashchain->direction;
|
||||
hashstep->level_corr = 0;
|
||||
hashstep->level_corr = 0;
|
||||
/* Attach to HashChain */
|
||||
hashchain->hashsteps[hashchain->stepCount] = hashstep;
|
||||
hashchain->stepCount++;
|
||||
@ -1942,7 +1942,7 @@ rsksi_vrfy_nextHashChain(ksifile ksi, block_sig_t *bs, FILE *sigfp, unsigned cha
|
||||
}
|
||||
bCheckLineHash = 1;
|
||||
}
|
||||
|
||||
|
||||
/* Store into TMP for next LOOP */
|
||||
root_tmp = root_hash;
|
||||
|
||||
@ -2051,7 +2051,7 @@ if(rsksi_read_debug)
|
||||
ectx->verbose);
|
||||
}
|
||||
hashstep->direction = hashchain->direction;
|
||||
hashstep->level_corr = j+1 - hashchain->level;
|
||||
hashstep->level_corr = j+1 - hashchain->level;
|
||||
if(rsksi_read_debug) printf("debug: verifySigblkFinishChain:\t\t level_corr=%d\n", hashstep->level_corr);
|
||||
|
||||
/* Attach to HashChain */
|
||||
@ -2224,7 +2224,7 @@ verifyBLOCK_HDRKSI(FILE *sigfp, FILE *nsigfp, tlvrecord_t* tlvrec)
|
||||
}
|
||||
if (nsigfp != NULL)
|
||||
if ((r = rsksi_tlvwrite(nsigfp, tlvrec)) != 0) goto done;
|
||||
done:
|
||||
done:
|
||||
if (bh != NULL)
|
||||
rsksi_objfree(tlvrec->tlvtype, bh);
|
||||
if(rsksi_read_debug) printf("debug: verifyBLOCK_HDRKSI:\t\t returned %d\n", r);
|
||||
@ -2236,7 +2236,7 @@ done:
|
||||
*/
|
||||
int
|
||||
verifyBLOCK_SIGKSI(block_sig_t *bs, ksifile ksi, FILE *sigfp, FILE *nsigfp,
|
||||
uint8_t bExtend, KSI_DataHash *ksiHash, ksierrctx_t *ectx)
|
||||
uint8_t bExtend, KSI_DataHash *ksiHash, ksierrctx_t *ectx)
|
||||
{
|
||||
int r;
|
||||
int ksistate;
|
||||
@ -2591,7 +2591,7 @@ int rsksi_WriteHashChain(FILE *newsigfp, block_hashchain_t *hashchain, int verbo
|
||||
tlvlenLevelCorr = rsksi_tlvGetInt64OctetSize(uiLevelCorr);
|
||||
|
||||
/* Total Length of Hash Chain */
|
||||
tlvlen = /*4 + ???? */
|
||||
tlvlen = /*4 + ???? */
|
||||
2 + 1 + hashchain->rec_hash.len /* rec-hash */ +
|
||||
((2 + 2 + tlvlenLevelCorr + 2 + 1 + hashchain->hashsteps[0]->sib_hash.len) * hashchain->stepCount);
|
||||
/* Count of all left/right chains*/
|
||||
|
||||
118
runtime/msg.c
118
runtime/msg.c
@ -43,10 +43,10 @@
|
||||
#include <libestr.h>
|
||||
#include <json.h>
|
||||
#ifdef HAVE_MALLOC_H
|
||||
# include <malloc.h>
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#ifdef USE_LIBUUID
|
||||
#include <uuid/uuid.h>
|
||||
#include <uuid/uuid.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include "rsyslog.h"
|
||||
@ -374,19 +374,19 @@ static char hexdigit[16] =
|
||||
{'0', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
#if defined(_AIX)
|
||||
/* AIXPORT : replace facility names with aso and caa only for AIX */
|
||||
static char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
|
||||
"news", "uucp", "cron", "authpriv", "ftp", "aso", "audit",
|
||||
"alert", "caa", "local0", "local1", "local2", "local3",
|
||||
"local4", "local5", "local6", "local7", "invld" };
|
||||
/* length of the facility names string (for optimizatiions) */
|
||||
static short len_syslog_fac_names[LOG_NFACILITIES] = { 4, 4, 4, 6, 4, 6, 3,
|
||||
4, 4, 4, 8, 3, 3, 5,
|
||||
5, 3, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 5 };
|
||||
#if defined(_AIX)
|
||||
/* AIXPORT : replace facility names with aso and caa only for AIX */
|
||||
static char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
|
||||
"news", "uucp", "cron", "authpriv", "ftp", "aso", "audit",
|
||||
"alert", "caa", "local0", "local1", "local2", "local3",
|
||||
"local4", "local5", "local6", "local7", "invld" };
|
||||
/* length of the facility names string (for optimizatiions) */
|
||||
static short len_syslog_fac_names[LOG_NFACILITIES] = { 4, 4, 4, 6, 4, 6, 3,
|
||||
4, 4, 4, 8, 3, 3, 5,
|
||||
5, 3, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 5 };
|
||||
|
||||
#else
|
||||
#else
|
||||
/*syslog facility names (as of RFC5424) */
|
||||
static const char *syslog_fac_names[LOG_NFACILITIES] = { "kern", "user", "mail", "daemon", "auth", "syslog", "lpr",
|
||||
"news", "uucp", "cron", "authpriv", "ftp", "ntp", "audit",
|
||||
@ -960,7 +960,7 @@ static inline void freeHOSTNAME(smsg_t *pThis)
|
||||
rsRetVal msgDestruct(smsg_t **ppThis)
|
||||
{
|
||||
DEFiRet;
|
||||
smsg_t *pThis;
|
||||
smsg_t *pThis;
|
||||
int currRefCount;
|
||||
# ifdef HAVE_MALLOC_TRIM
|
||||
int currCnt;
|
||||
@ -2130,10 +2130,10 @@ static const char *getFacility(smsg_t * const pM)
|
||||
|
||||
static const char *getFacilityStr(smsg_t * const pM)
|
||||
{
|
||||
const char *name = NULL;
|
||||
const char *name = NULL;
|
||||
|
||||
if(pM == NULL)
|
||||
return "";
|
||||
if(pM == NULL)
|
||||
return "";
|
||||
|
||||
if(pM->iFacility > 23) {
|
||||
name = "invld";
|
||||
@ -3470,8 +3470,8 @@ finalize_it:
|
||||
*pPropLen = sizeof("**OUT OF MEMORY**") - 1; \
|
||||
return(UCHAR_CONSTANT("**OUT OF MEMORY**"));}
|
||||
uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restrict__ const pTpe,
|
||||
msgPropDescr_t *pProp, rs_size_t *__restrict__ const pPropLen,
|
||||
unsigned short *__restrict__ const pbMustBeFreed, struct syslogTime * const ttNow)
|
||||
msgPropDescr_t *pProp, rs_size_t *__restrict__ const pPropLen,
|
||||
unsigned short *__restrict__ const pbMustBeFreed, struct syslogTime * const ttNow)
|
||||
{
|
||||
uchar *pRes; /* result pointer */
|
||||
rs_size_t bufLen = -1; /* length of string or -1, if not known */
|
||||
@ -3790,14 +3790,14 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
|
||||
if(clock_gettime(CLOCK_UPTIME, &tp) == -1) {
|
||||
free(pRes);
|
||||
*pPropLen = sizeof("**SYSCALL FAILED**") - 1;
|
||||
return(UCHAR_CONSTANT("**SYSCALL FAILED**"));
|
||||
}
|
||||
*pPropLen = sizeof("**SYSCALL FAILED**") - 1;
|
||||
return(UCHAR_CONSTANT("**SYSCALL FAILED**"));
|
||||
}
|
||||
|
||||
*pbMustBeFreed = 1;
|
||||
|
||||
snprintf((char*) pRes, 32, "%ld", tp.tv_sec);
|
||||
}
|
||||
}
|
||||
|
||||
# else
|
||||
|
||||
@ -3871,7 +3871,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
}
|
||||
}
|
||||
dbgprintf("field requested %d, field found %d\n", pTpe->data.field.iFieldNr, (int) iCurrFld);
|
||||
|
||||
|
||||
if(iCurrFld == pTpe->data.field.iFieldNr) {
|
||||
/* field found, now extract it */
|
||||
/* first of all, we need to find the end */
|
||||
@ -4172,7 +4172,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
uchar *pDstStart;
|
||||
uchar *pDst;
|
||||
uchar bDropped = 0;
|
||||
|
||||
|
||||
while(*pSrc) {
|
||||
if(!iscntrl((int) *pSrc++))
|
||||
iLenBuf++;
|
||||
@ -4202,7 +4202,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
uchar *pSrc;
|
||||
uchar *pDstStart;
|
||||
uchar *pDst;
|
||||
|
||||
|
||||
if(*pbMustBeFreed == 1) {
|
||||
/* in this case, we already work on dynamic
|
||||
* memory, so there is no need to copy it - we can
|
||||
@ -4291,14 +4291,14 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
uchar *pDstStart;
|
||||
uchar *pDst;
|
||||
uchar bDropped = 0;
|
||||
|
||||
|
||||
while(*pSrc) {
|
||||
if(*pSrc++ != '/')
|
||||
iLenBuf++;
|
||||
else
|
||||
bDropped = 1;
|
||||
}
|
||||
|
||||
|
||||
if(bDropped) {
|
||||
pDst = pDstStart = MALLOC(iLenBuf + 1);
|
||||
if(pDst == NULL) {
|
||||
@ -4321,7 +4321,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
uchar *pSrc;
|
||||
uchar *pDstStart;
|
||||
uchar *pDst;
|
||||
|
||||
|
||||
if(*pbMustBeFreed == 1) {
|
||||
/* here, again, we can modify the string as we already obtained
|
||||
* a private buffer. As we do not change the size of that buffer,
|
||||
@ -4356,7 +4356,7 @@ uchar *MsgGetProp(smsg_t *__restrict__ const pMsg, struct templateEntry *__restr
|
||||
*pbMustBeFreed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* check for "." and ".." (note the parenthesis in the if condition!) */
|
||||
if(*pRes == '\0') {
|
||||
if(*pbMustBeFreed == 1)
|
||||
@ -4692,33 +4692,33 @@ jsonPathGetLeaf(uchar *name, int lenName)
|
||||
}
|
||||
|
||||
static json_bool jsonVarExtract(struct json_object* root, const char *key, struct json_object **value) {
|
||||
char namebuf[MAX_VARIABLE_NAME_LEN];
|
||||
int key_len = strlen(key);
|
||||
char *array_idx_start = strstr(key, "[");
|
||||
char *array_idx_end = NULL;
|
||||
char *array_idx_num_end_discovered = NULL;
|
||||
struct json_object *arr = NULL;
|
||||
if (array_idx_start != NULL) {
|
||||
array_idx_end = strstr(array_idx_start, "]");
|
||||
}
|
||||
if (array_idx_end != NULL && (array_idx_end - key + 1) == key_len) {
|
||||
errno = 0;
|
||||
int idx = (int) strtol(array_idx_start + 1, &array_idx_num_end_discovered, 10);
|
||||
if (errno == 0 && array_idx_num_end_discovered == array_idx_end) {
|
||||
memcpy(namebuf, key, array_idx_start - key);
|
||||
namebuf[array_idx_start - key] = '\0';
|
||||
json_bool found_obj = json_object_object_get_ex(root, namebuf, &arr);
|
||||
if (found_obj && json_object_is_type(arr, json_type_array)) {
|
||||
int len = json_object_array_length(arr);
|
||||
if (len > idx) {
|
||||
*value = json_object_array_get_idx(arr, idx);
|
||||
if (*value != NULL) return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return json_object_object_get_ex(root, key, value);
|
||||
char namebuf[MAX_VARIABLE_NAME_LEN];
|
||||
int key_len = strlen(key);
|
||||
char *array_idx_start = strstr(key, "[");
|
||||
char *array_idx_end = NULL;
|
||||
char *array_idx_num_end_discovered = NULL;
|
||||
struct json_object *arr = NULL;
|
||||
if (array_idx_start != NULL) {
|
||||
array_idx_end = strstr(array_idx_start, "]");
|
||||
}
|
||||
if (array_idx_end != NULL && (array_idx_end - key + 1) == key_len) {
|
||||
errno = 0;
|
||||
int idx = (int) strtol(array_idx_start + 1, &array_idx_num_end_discovered, 10);
|
||||
if (errno == 0 && array_idx_num_end_discovered == array_idx_end) {
|
||||
memcpy(namebuf, key, array_idx_start - key);
|
||||
namebuf[array_idx_start - key] = '\0';
|
||||
json_bool found_obj = json_object_object_get_ex(root, namebuf, &arr);
|
||||
if (found_obj && json_object_is_type(arr, json_type_array)) {
|
||||
int len = json_object_array_length(arr);
|
||||
if (len > idx) {
|
||||
*value = json_object_array_get_idx(arr, idx);
|
||||
if (*value != NULL) return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return json_object_object_get_ex(root, key, value);
|
||||
}
|
||||
|
||||
|
||||
@ -4988,7 +4988,7 @@ msgAddMultiMetadata(smsg_t *const __restrict__ pMsg,
|
||||
if(jval == NULL) {
|
||||
json_object_put(json);
|
||||
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
json_object_object_add(json, (const char *const)metaname[i], jval);
|
||||
}
|
||||
iRet = msgAddJSON(pMsg, (uchar*)"!metadata", json, 0, 0);
|
||||
|
||||
136
runtime/net.c
136
runtime/net.c
@ -282,7 +282,7 @@ AddPermittedPeer(permittedPeers_t **ppRootPeer, uchar* pszID)
|
||||
pNew->pNext = *ppRootPeer;
|
||||
}
|
||||
*ppRootPeer = pNew;
|
||||
|
||||
|
||||
finalize_it:
|
||||
if(iRet != RS_RET_OK) {
|
||||
if(pNew != NULL)
|
||||
@ -524,8 +524,8 @@ static void MaskIP4 (struct in_addr *addr, uint8_t bits) {
|
||||
*/
|
||||
static int
|
||||
mygetnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||
char *host, size_t hostlen,
|
||||
char *serv, size_t servlen, int flags)
|
||||
char *host, size_t hostlen,
|
||||
char *serv, size_t servlen, int flags)
|
||||
{
|
||||
int iCancelStateSave;
|
||||
int i;
|
||||
@ -632,7 +632,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
LogError(0, NO_ERRCODE, "You can not specify 0 bits of the netmask, this would "
|
||||
"match ALL systems. If you really intend to do that, "
|
||||
"remove all $AllowedSender directives.");
|
||||
|
||||
|
||||
switch (iAllow->addr.NetAddr->sa_family) {
|
||||
case AF_INET:
|
||||
if((iSignificantBits < 1) || (iSignificantBits > 32)) {
|
||||
@ -640,7 +640,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
(int)iSignificantBits);
|
||||
iSignificantBits = 32;
|
||||
}
|
||||
|
||||
|
||||
MaskIP4 (&(SIN(iAllow->addr.NetAddr)->sin_addr), iSignificantBits);
|
||||
break;
|
||||
case AF_INET6:
|
||||
@ -672,7 +672,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
LogError(0, NO_ERRCODE, "Ignoring hostname based ACLs because DNS is disabled.");
|
||||
ABORT_FINALIZE(RS_RET_OK);
|
||||
}
|
||||
|
||||
|
||||
if (!strchr (iAllow->addr.HostWildcard, '*') &&
|
||||
!strchr (iAllow->addr.HostWildcard, '?') &&
|
||||
ACLDontResolve == 0) {
|
||||
@ -681,7 +681,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
*/
|
||||
struct addrinfo hints, *res;
|
||||
struct NetAddr allowIP;
|
||||
|
||||
|
||||
memset (&hints, 0, sizeof (struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
@ -691,7 +691,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
|
||||
if (getaddrinfo (iAllow->addr.HostWildcard, NULL, &hints, &res) != 0) {
|
||||
LogError(0, NO_ERRCODE, "DNS error: Can't resolve \"%s\"", iAllow->addr.HostWildcard);
|
||||
|
||||
|
||||
if (ACLAddHostnameOnFail) {
|
||||
LogError(0, NO_ERRCODE, "Adding hostname \"%s\" to ACL as a wildcard "
|
||||
"entry.", iAllow->addr.HostWildcard);
|
||||
@ -703,7 +703,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
ABORT_FINALIZE(RS_RET_NOENTRY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restmp = res;
|
||||
for ( ; res != NULL ; res = res->ai_next) {
|
||||
switch (res->ai_family) {
|
||||
@ -714,7 +714,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
||||
}
|
||||
memcpy(allowIP.addr.NetAddr, res->ai_addr, res->ai_addrlen);
|
||||
|
||||
|
||||
if((iRet = AddAllowedSenderEntry(ppRoot, ppLast, &allowIP, iSignificantBits))
|
||||
!= RS_RET_OK) {
|
||||
free(allowIP.addr.NetAddr);
|
||||
@ -724,7 +724,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
case AF_INET6: /* IPv6 - but need to check if it is a v6-mapped IPv4 */
|
||||
if(IN6_IS_ADDR_V4MAPPED (&SIN6(res->ai_addr)->sin6_addr)) {
|
||||
/* extract & add IPv4 */
|
||||
|
||||
|
||||
iSignificantBits = 32;
|
||||
allowIP.flags = 0;
|
||||
if((allowIP.addr.NetAddr = (struct sockaddr *)
|
||||
@ -733,7 +733,7 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
}
|
||||
SIN(allowIP.addr.NetAddr)->sin_family = AF_INET;
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
SIN(allowIP.addr.NetAddr)->sin_len = sizeof (struct sockaddr_in);
|
||||
SIN(allowIP.addr.NetAddr)->sin_len = sizeof (struct sockaddr_in);
|
||||
#endif
|
||||
SIN(allowIP.addr.NetAddr)->sin_port = 0;
|
||||
memcpy(&(SIN(allowIP.addr.NetAddr)->sin_addr.s_addr),
|
||||
@ -748,14 +748,14 @@ static rsRetVal AddAllowedSender(struct AllowedSenders **ppRoot, struct AllowedS
|
||||
}
|
||||
} else {
|
||||
/* finally add IPv6 */
|
||||
|
||||
|
||||
iSignificantBits = 128;
|
||||
allowIP.flags = 0;
|
||||
if((allowIP.addr.NetAddr = MALLOC(res->ai_addrlen)) == NULL) {
|
||||
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
|
||||
}
|
||||
memcpy(allowIP.addr.NetAddr, res->ai_addr, res->ai_addrlen);
|
||||
|
||||
|
||||
if((iRet = AddAllowedSenderEntry(ppRoot, ppLast, &allowIP,
|
||||
iSignificantBits))
|
||||
!= RS_RET_OK) {
|
||||
@ -945,7 +945,7 @@ MaskCmp(struct NetAddr *pAllow, uint8_t bits, struct sockaddr *pFrom, const char
|
||||
if(bChkDNS == 0)
|
||||
return 2;
|
||||
dbgprintf("MaskCmp: host=\"%s\"; pattern=\"%s\"\n", pszFromHost, pAllow->addr.HostWildcard);
|
||||
|
||||
|
||||
# if !defined(FNM_CASEFOLD)
|
||||
/* TODO: I don't know if that then works, seen on HP UX, what I have not in lab... ;) */
|
||||
return(fnmatch(pAllow->addr.HostWildcard, pszFromHost, FNM_NOESCAPE) == 0);
|
||||
@ -966,16 +966,16 @@ MaskCmp(struct NetAddr *pAllow, uint8_t bits, struct sockaddr *pFrom, const char
|
||||
case AF_INET6: {
|
||||
struct in6_addr ip, net;
|
||||
register uint8_t i;
|
||||
|
||||
|
||||
memcpy (&ip, &(SIN6(pFrom))->sin6_addr, sizeof (struct in6_addr));
|
||||
memcpy (&net, &(SIN6(pAllow->addr.NetAddr))->sin6_addr, sizeof (struct in6_addr));
|
||||
|
||||
|
||||
i = bits/32;
|
||||
if (bits % 32)
|
||||
ip.s6_addr32[i++] &= htonl(0xffffffff << (32 - (bits % 32)));
|
||||
for (; i < (sizeof ip.s6_addr32)/4; i++)
|
||||
ip.s6_addr32[i] = 0;
|
||||
|
||||
|
||||
return (memcmp (ip.s6_addr, net.s6_addr, sizeof ip.s6_addr) == 0 &&
|
||||
(SIN6(pAllow->addr.NetAddr)->sin6_scope_id != 0 ?
|
||||
SIN6(pFrom)->sin6_scope_id == SIN6(pAllow->addr.NetAddr)->sin6_scope_id : 1));
|
||||
@ -983,7 +983,7 @@ MaskCmp(struct NetAddr *pAllow, uint8_t bits, struct sockaddr *pFrom, const char
|
||||
case AF_INET: {
|
||||
struct in6_addr *ip6 = &(SIN6(pFrom))->sin6_addr;
|
||||
struct in_addr *net = &(SIN(pAllow->addr.NetAddr))->sin_addr;
|
||||
|
||||
|
||||
if ((ip6->s6_addr32[3] & (u_int32_t)
|
||||
htonl((0xffffffff << (32 - bits)))) == net->s_addr &&
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
@ -1068,35 +1068,35 @@ static int
|
||||
should_use_so_bsdcompat(void)
|
||||
{
|
||||
#ifndef OS_BSD
|
||||
static int init_done = 0;
|
||||
static int so_bsdcompat_is_obsolete = 0;
|
||||
static int init_done = 0;
|
||||
static int so_bsdcompat_is_obsolete = 0;
|
||||
|
||||
if (!init_done) {
|
||||
struct utsname myutsname;
|
||||
unsigned int version, patchlevel;
|
||||
if (!init_done) {
|
||||
struct utsname myutsname;
|
||||
unsigned int version, patchlevel;
|
||||
|
||||
init_done = 1;
|
||||
if (uname(&myutsname) < 0) {
|
||||
char errStr[1024];
|
||||
dbgprintf("uname: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr)));
|
||||
return 1;
|
||||
init_done = 1;
|
||||
if (uname(&myutsname) < 0) {
|
||||
char errStr[1024];
|
||||
dbgprintf("uname: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr)));
|
||||
return 1;
|
||||
}
|
||||
/* Format is <version>.<patchlevel>.<sublevel><extraversion>
|
||||
* where the first three are unsigned integers and the last
|
||||
* is an arbitrary string. We only care about the first two. */
|
||||
if (sscanf(myutsname.release, "%u.%u", &version, &patchlevel) != 2) {
|
||||
dbgprintf("uname: unexpected release '%s'\r\n",
|
||||
myutsname.release);
|
||||
return 1;
|
||||
}
|
||||
/* SO_BSCOMPAT is deprecated and triggers warnings in 2.5
|
||||
kernels. It is a no-op in 2.4 but not in 2.2 kernels. */
|
||||
if (version > 2 || (version == 2 && patchlevel >= 5))
|
||||
so_bsdcompat_is_obsolete = 1;
|
||||
}
|
||||
/* Format is <version>.<patchlevel>.<sublevel><extraversion>
|
||||
where the first three are unsigned integers and the last
|
||||
is an arbitrary string. We only care about the first two. */
|
||||
if (sscanf(myutsname.release, "%u.%u", &version, &patchlevel) != 2) {
|
||||
dbgprintf("uname: unexpected release '%s'\r\n",
|
||||
myutsname.release);
|
||||
return 1;
|
||||
}
|
||||
/* SO_BSCOMPAT is deprecated and triggers warnings in 2.5
|
||||
kernels. It is a no-op in 2.4 but not in 2.2 kernels. */
|
||||
if (version > 2 || (version == 2 && patchlevel >= 5))
|
||||
so_bsdcompat_is_obsolete = 1;
|
||||
}
|
||||
return !so_bsdcompat_is_obsolete;
|
||||
return !so_bsdcompat_is_obsolete;
|
||||
#else /* #ifndef OS_BSD */
|
||||
return 1;
|
||||
return 1;
|
||||
#endif /* #ifndef OS_BSD */
|
||||
}
|
||||
#ifndef SO_BSDCOMPAT
|
||||
@ -1244,7 +1244,7 @@ closeUDPListenSockets(int *pSockArr)
|
||||
register int i;
|
||||
|
||||
assert(pSockArr != NULL);
|
||||
if(pSockArr != NULL) {
|
||||
if(pSockArr != NULL) {
|
||||
for (i = 0; i < *pSockArr; i++)
|
||||
close(pSockArr[i+1]);
|
||||
free(pSockArr);
|
||||
@ -1268,7 +1268,7 @@ create_single_udp_socket(int *const s, /* socket */
|
||||
const char *const device
|
||||
)
|
||||
{
|
||||
const int on = 1;
|
||||
const int on = 1;
|
||||
int sockflags;
|
||||
int actrcvbuf;
|
||||
int actsndbuf;
|
||||
@ -1471,44 +1471,44 @@ create_udp_socket(uchar *hostname,
|
||||
const int ipfreebind,
|
||||
char *device)
|
||||
{
|
||||
struct addrinfo hints, *res, *r;
|
||||
int error, maxs, *s, *socks;
|
||||
struct addrinfo hints, *res, *r;
|
||||
int error, maxs, *s, *socks;
|
||||
rsRetVal localRet;
|
||||
|
||||
assert(!((pszPort == NULL) && (hostname == NULL))); /* one of them must be non-NULL */
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
if(bIsServer)
|
||||
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
|
||||
else
|
||||
hints.ai_flags = AI_NUMERICSERV;
|
||||
hints.ai_family = glbl.GetDefPFFamily();
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
hints.ai_family = glbl.GetDefPFFamily();
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
# if defined (_AIX)
|
||||
/* AIXPORT : SOCK_DGRAM has the protocol IPPROTO_UDP
|
||||
* getaddrinfo needs this hint on AIX
|
||||
*/
|
||||
hints.ai_protocol = IPPROTO_UDP;
|
||||
hints.ai_protocol = IPPROTO_UDP;
|
||||
# endif
|
||||
error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res);
|
||||
if(error) {
|
||||
LogError(0, NO_ERRCODE, "%s", gai_strerror(error));
|
||||
LogError(0, NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n");
|
||||
error = getaddrinfo((char*) hostname, (char*) pszPort, &hints, &res);
|
||||
if(error) {
|
||||
LogError(0, NO_ERRCODE, "%s", gai_strerror(error));
|
||||
LogError(0, NO_ERRCODE, "UDP message reception disabled due to error logged in last message.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Count max number of sockets we may open */
|
||||
for (maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++)
|
||||
/* Count max number of sockets we may open */
|
||||
for (maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++)
|
||||
/* EMPTY */;
|
||||
socks = MALLOC((maxs+1) * sizeof(int));
|
||||
if (socks == NULL) {
|
||||
socks = MALLOC((maxs+1) * sizeof(int));
|
||||
if (socks == NULL) {
|
||||
LogError(0, RS_RET_OUT_OF_MEMORY, "couldn't allocate memory for UDP "
|
||||
"sockets, suspending UDP message reception");
|
||||
freeaddrinfo(res);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*socks = 0; /* num of sockets counter at start of array */
|
||||
s = socks + 1;
|
||||
*socks = 0; /* num of sockets counter at start of array */
|
||||
s = socks + 1;
|
||||
for (r = res; r != NULL ; r = r->ai_next) {
|
||||
localRet = create_single_udp_socket(s, r, hostname, bIsServer, rcvbuf,
|
||||
sndbuf, ipfreebind, device);
|
||||
@ -1518,18 +1518,18 @@ create_udp_socket(uchar *hostname,
|
||||
}
|
||||
}
|
||||
|
||||
if(res != NULL)
|
||||
freeaddrinfo(res);
|
||||
if(res != NULL)
|
||||
freeaddrinfo(res);
|
||||
|
||||
if(Debug && *socks != maxs)
|
||||
dbgprintf("We could initialize %d UDP listen sockets out of %d we received "
|
||||
"- this may or may not be an error indication.\n", *socks, maxs);
|
||||
|
||||
if(*socks == 0) {
|
||||
if(*socks == 0) {
|
||||
LogError(0, NO_ERRCODE, "No UDP socket could successfully be initialized, "
|
||||
"some functionality may be disabled.\n");
|
||||
/* we do NOT need to close any sockets, because there were none... */
|
||||
free(socks);
|
||||
free(socks);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
@ -1631,7 +1631,7 @@ getIFIPAddr(uchar *szif, int family, uchar *pszbuf, int lenBuf)
|
||||
void * pAddr;
|
||||
DEFiRet;
|
||||
|
||||
if(getifaddrs(&ifaddrs) != 0) {
|
||||
if(getifaddrs(&ifaddrs) != 0) {
|
||||
ABORT_FINALIZE(RS_RET_ERR);
|
||||
}
|
||||
|
||||
|
||||
@ -311,38 +311,38 @@ long BIO_debug_callback(BIO *bio, int cmd, const char __attribute__((unused)) *a
|
||||
dbgprintf("write %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
#endif
|
||||
case BIO_CB_PUTS:
|
||||
dbgprintf("puts() - %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_GETS:
|
||||
dbgprintf("gets(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_CTRL:
|
||||
dbgprintf("ctrl(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_READ:
|
||||
dbgprintf("read return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_WRITE:
|
||||
dbgprintf("write return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_GETS:
|
||||
dbgprintf("gets return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_PUTS:
|
||||
dbgprintf("puts return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_CTRL:
|
||||
dbgprintf("ctrl return %ld\n", ret);
|
||||
break;
|
||||
default:
|
||||
dbgprintf("bio callback - unknown type (%d)\n", cmd);
|
||||
break;
|
||||
}
|
||||
case BIO_CB_PUTS:
|
||||
dbgprintf("puts() - %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_GETS:
|
||||
dbgprintf("gets(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_CTRL:
|
||||
dbgprintf("ctrl(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_READ:
|
||||
dbgprintf("read return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_WRITE:
|
||||
dbgprintf("write return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_GETS:
|
||||
dbgprintf("gets return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_PUTS:
|
||||
dbgprintf("puts return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_CTRL:
|
||||
dbgprintf("ctrl return %ld\n", ret);
|
||||
break;
|
||||
default:
|
||||
dbgprintf("bio callback - unknown type (%d)\n", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
return (r);
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -292,7 +292,7 @@ Abort(nsd_t *pNsd)
|
||||
if((pThis)->sock != -1) {
|
||||
ling.l_onoff = 1;
|
||||
ling.l_linger = 0;
|
||||
if(setsockopt((pThis)->sock, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) < 0 ) {
|
||||
if(setsockopt((pThis)->sock, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) < 0 ) {
|
||||
dbgprintf("could not set SO_LINGER, errno %d\n", errno);
|
||||
}
|
||||
}
|
||||
@ -416,11 +416,11 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
DEFiRet;
|
||||
netstrm_t *pNewStrm = NULL;
|
||||
nsd_t *pNewNsd = NULL;
|
||||
int error, maxs, on = 1;
|
||||
int error, maxs, on = 1;
|
||||
int sock = -1;
|
||||
int numSocks;
|
||||
int sockflags;
|
||||
struct addrinfo hints, *res = NULL, *r;
|
||||
struct addrinfo hints, *res = NULL, *r;
|
||||
|
||||
ISOBJ_TYPE_assert(pNS, netstrms);
|
||||
assert(fAddLstn != NULL);
|
||||
@ -429,49 +429,49 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
|
||||
dbgprintf("creating tcp listen socket on port %s\n", pLstnPort);
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_family = glbl.GetDefPFFamily();
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_family = glbl.GetDefPFFamily();
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
error = getaddrinfo((char*)pLstnIP, (char*) pLstnPort, &hints, &res);
|
||||
if(error) {
|
||||
error = getaddrinfo((char*)pLstnIP, (char*) pLstnPort, &hints, &res);
|
||||
if(error) {
|
||||
LogError(0, RS_RET_INVALID_PORT, "error querying port '%s': %s",
|
||||
pLstnPort, gai_strerror(error));
|
||||
ABORT_FINALIZE(RS_RET_INVALID_PORT);
|
||||
}
|
||||
|
||||
/* Count max number of sockets we may open */
|
||||
for(maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++)
|
||||
/* Count max number of sockets we may open */
|
||||
for(maxs = 0, r = res; r != NULL ; r = r->ai_next, maxs++)
|
||||
/* EMPTY */;
|
||||
|
||||
numSocks = 0; /* num of sockets counter at start of array */
|
||||
numSocks = 0; /* num of sockets counter at start of array */
|
||||
for(r = res; r != NULL ; r = r->ai_next) {
|
||||
sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
|
||||
if(sock < 0) {
|
||||
sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
|
||||
if(sock < 0) {
|
||||
if(!(r->ai_family == PF_INET6 && errno == EAFNOSUPPORT)) {
|
||||
dbgprintf("error %d creating tcp listen socket", errno);
|
||||
/* it is debatable if PF_INET with EAFNOSUPPORT should
|
||||
* also be ignored...
|
||||
*/
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef IPV6_V6ONLY
|
||||
if(r->ai_family == AF_INET6) {
|
||||
int iOn = 1;
|
||||
if(r->ai_family == AF_INET6) {
|
||||
int iOn = 1;
|
||||
if(setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(char *)&iOn, sizeof (iOn)) < 0) {
|
||||
close(sock);
|
||||
sock = -1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) {
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0 ) {
|
||||
dbgprintf("error %d setting tcp socket option\n", errno);
|
||||
close(sock);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
continue;
|
||||
}
|
||||
@ -486,7 +486,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
}
|
||||
if(sockflags == -1) {
|
||||
dbgprintf("error %d setting fcntl(O_NONBLOCK) on tcp socket", errno);
|
||||
close(sock);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
continue;
|
||||
}
|
||||
@ -496,15 +496,15 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
* could flood our log files by sending us tons of ICMP errors.
|
||||
*/
|
||||
/* AIXPORT : SO_BSDCOMPAT socket option is depricated , and its usage has been discontinued
|
||||
on most unixes, AIX does not support this option , hence remove the call.
|
||||
*/
|
||||
* on most unixes, AIX does not support this option , hence remove the call.
|
||||
*/
|
||||
#if !defined(_AIX)
|
||||
#ifndef BSD
|
||||
if(net.should_use_so_bsdcompat()) {
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BSDCOMPAT,
|
||||
(char *) &on, sizeof(on)) < 0) {
|
||||
LogError(errno, NO_ERRCODE, "TCP setsockopt(BSDCOMPAT)");
|
||||
close(sock);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
continue;
|
||||
}
|
||||
@ -520,11 +520,11 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
/* TODO: check if *we* bound the socket - else we *have* an error! */
|
||||
char errStr[1024];
|
||||
rs_strerror_r(errno, errStr, sizeof(errStr));
|
||||
dbgprintf("error %d while binding tcp socket: %s\n", errno, errStr);
|
||||
close(sock);
|
||||
dbgprintf("error %d while binding tcp socket: %s\n", errno, errStr);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(listen(sock, iSessMax / 10 + 5) < 0) {
|
||||
/* If the listen fails, it most probably fails because we ask
|
||||
@ -538,7 +538,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
dbgprintf("tcp listen error %d, suspending\n", errno);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -569,7 +569,7 @@ LstnInit(netstrms_t *pNS, void *pUsr, rsRetVal(*fAddLstn)(void*,netstrm_t*),
|
||||
dbgprintf("We could initialize %d TCP listen sockets out of %d we received "
|
||||
"- this may or may not be an error indication.\n", numSocks, maxs);
|
||||
|
||||
if(numSocks == 0) {
|
||||
if(numSocks == 0) {
|
||||
dbgprintf("No TCP listen sockets could successfully be initialized\n");
|
||||
ABORT_FINALIZE(RS_RET_COULD_NOT_BIND);
|
||||
}
|
||||
@ -774,8 +774,8 @@ Connect(nsd_t *pNsd, int family, uchar *port, uchar *host, char *device)
|
||||
# if defined(SO_BINDTODEVICE)
|
||||
if(setsockopt(pThis->sock, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device) + 1) < 0)
|
||||
# endif
|
||||
{
|
||||
dbgprintf("setsockopt(SO_BINDTODEVICE) failed\n");
|
||||
{
|
||||
dbgprintf("setsockopt(SO_BINDTODEVICE) failed\n");
|
||||
ABORT_FINALIZE(RS_RET_IO_ERROR);
|
||||
}
|
||||
}
|
||||
@ -788,7 +788,7 @@ Connect(nsd_t *pNsd, int family, uchar *port, uchar *host, char *device)
|
||||
|
||||
finalize_it:
|
||||
if(res != NULL)
|
||||
freeaddrinfo(res);
|
||||
freeaddrinfo(res);
|
||||
|
||||
if(iRet != RS_RET_OK) {
|
||||
sockClose(&pThis->sock);
|
||||
|
||||
@ -133,8 +133,8 @@ static rsRetVal objInfoNotImplementedDummy(void __attribute__((unused)) *pThis)
|
||||
*/
|
||||
static rsRetVal
|
||||
InfoConstruct(objInfo_t **ppThis, uchar *pszID, int iObjVers,
|
||||
rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *),
|
||||
rsRetVal (*pQueryIF)(interface_t*), modInfo_t *pModInfo)
|
||||
rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *),
|
||||
rsRetVal (*pQueryIF)(interface_t*), modInfo_t *pModInfo)
|
||||
{
|
||||
DEFiRet;
|
||||
int i;
|
||||
|
||||
@ -61,7 +61,7 @@ BEGINinterface(parser) /* name must also be changed in ENDinterface macro! */
|
||||
ENDinterface(parser)
|
||||
#define parserCURR_IF_VERSION 2 /* increment whenever you change the interface above! */
|
||||
/* version changes
|
||||
2 SetDoSanitization removed, no longer needed
|
||||
2 SetDoSanitization removed, no longer needed
|
||||
*/
|
||||
|
||||
void printParserList(parserList_t *pList);
|
||||
|
||||
@ -2123,7 +2123,7 @@ finalize_it:
|
||||
* Unless the error code is RS_RET_ERR_QUEUE_EMERGENCY, we reset the return state to RS_RET_OK.
|
||||
* Otherwise the Caller functions would run into an infinite Loop trying to enqueue the
|
||||
* same messages over and over again.
|
||||
*
|
||||
*
|
||||
* However we do NOT overwrite positive return states like
|
||||
* RS_RET_TERMINATE_NOW,
|
||||
* RS_RET_NO_RUN,
|
||||
@ -2525,7 +2525,7 @@ qqueuePersist(qqueue_t *pThis, int bIsCheckpoint)
|
||||
if(pThis->qType != QUEUETYPE_DISK) {
|
||||
if(getPhysicalQueueSize(pThis) > 0) {
|
||||
/* This error code is OK, but we will probably not implement this any time
|
||||
* The reason is that persistence happens via DA queues. But I would like to
|
||||
* The reason is that persistence happens via DA queues. But I would like to
|
||||
* leave the code as is, as we so have a hook in case we need one.
|
||||
* -- rgerhards, 2008-01-28
|
||||
*/
|
||||
@ -2552,7 +2552,7 @@ qqueuePersist(qqueue_t *pThis, int bIsCheckpoint)
|
||||
lentmpQIFName = strlen( pThis->pszQIFNam) + strlen(".tmp") + 1;
|
||||
tmpQIFName = malloc(sizeof(char)*lentmpQIFName);
|
||||
if(tmpQIFName == NULL)
|
||||
tmpQIFName = (char*)pThis->pszQIFNam;
|
||||
tmpQIFName = (char*)pThis->pszQIFNam;
|
||||
snprintf(tmpQIFName, lentmpQIFName, "%s.tmp", pThis->pszQIFNam);
|
||||
#else
|
||||
lentmpQIFName = asprintf((char **)&tmpQIFName, "%s.tmp", pThis->pszQIFNam);
|
||||
@ -2898,7 +2898,7 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, smsg_t *pMsg)
|
||||
DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()"
|
||||
"/fulldelay returned %d\n", err);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
DBGPRINTF("wti worker in full delay timed out, checking termination...\n");
|
||||
}
|
||||
@ -2912,7 +2912,7 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, smsg_t *pMsg)
|
||||
/* Something is really wrong now. Report to debug log */
|
||||
DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()"
|
||||
"/lightdelay returned %d\n", err);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3302,14 +3302,14 @@ static rsRetVal qqueueSetProperty(qqueue_t *pThis, var_t *pProp)
|
||||
ISOBJ_TYPE_assert(pThis, qqueue);
|
||||
ASSERT(pProp != NULL);
|
||||
|
||||
if(isProp("iQueueSize")) {
|
||||
if(isProp("iQueueSize")) {
|
||||
pThis->iQueueSize = pProp->val.num;
|
||||
# ifdef ENABLE_IMDIAG
|
||||
iOverallQueueSize += pThis->iQueueSize;
|
||||
# endif
|
||||
} else if(isProp("tVars.disk.sizeOnDisk")) {
|
||||
} else if(isProp("tVars.disk.sizeOnDisk")) {
|
||||
pThis->tVars.disk.sizeOnDisk = pProp->val.num;
|
||||
} else if(isProp("qType")) {
|
||||
} else if(isProp("qType")) {
|
||||
if(pThis->qType != pProp->val.num)
|
||||
ABORT_FINALIZE(RS_RET_QTYPE_MISMATCH);
|
||||
}
|
||||
|
||||
@ -203,21 +203,21 @@ uchar *srUtilStrDup(uchar *pOld, size_t len)
|
||||
static int real_makeFileParentDirs(const uchar *const szFile, const size_t lenFile, const mode_t mode,
|
||||
const uid_t uid, const gid_t gid, const int bFailOnChownFail)
|
||||
{
|
||||
uchar *p;
|
||||
uchar *pszWork;
|
||||
size_t len;
|
||||
uchar *p;
|
||||
uchar *pszWork;
|
||||
size_t len;
|
||||
|
||||
assert(szFile != NULL);
|
||||
assert(lenFile > 0);
|
||||
|
||||
len = lenFile + 1; /* add one for '\0'-byte */
|
||||
len = lenFile + 1; /* add one for '\0'-byte */
|
||||
if((pszWork = MALLOC(len)) == NULL)
|
||||
return -1;
|
||||
memcpy(pszWork, szFile, len);
|
||||
for(p = pszWork+1 ; *p ; p++)
|
||||
if(*p == '/') {
|
||||
memcpy(pszWork, szFile, len);
|
||||
for(p = pszWork+1 ; *p ; p++)
|
||||
if(*p == '/') {
|
||||
/* temporarily terminate string, create dir and go on */
|
||||
*p = '\0';
|
||||
*p = '\0';
|
||||
int bErr = 0;
|
||||
if(mkdir((char*)pszWork, mode) == 0) {
|
||||
if(uid != (uid_t) -1 || gid != (gid_t) -1) {
|
||||
@ -242,8 +242,8 @@ static int real_makeFileParentDirs(const uchar *const szFile, const size_t lenFi
|
||||
errno = eSave;
|
||||
return -1;
|
||||
}
|
||||
*p = '/';
|
||||
}
|
||||
*p = '/';
|
||||
}
|
||||
free(pszWork);
|
||||
return 0;
|
||||
}
|
||||
@ -274,17 +274,17 @@ int makeFileParentDirs(const uchar *const szFile, const size_t lenFile, const mo
|
||||
*/
|
||||
int execProg(uchar *program, int bWait, uchar *arg)
|
||||
{
|
||||
int pid;
|
||||
int pid;
|
||||
int sig;
|
||||
struct sigaction sigAct;
|
||||
|
||||
dbgprintf("exec program '%s' with param '%s'\n", program, arg);
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
return 0;
|
||||
}
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(pid) { /* Parent */
|
||||
if(pid) { /* Parent */
|
||||
if(bWait)
|
||||
if(waitpid(pid, NULL, 0) == -1)
|
||||
if(errno != ECHILD) {
|
||||
@ -296,9 +296,9 @@ int execProg(uchar *program, int bWait, uchar *arg)
|
||||
dbgprintf("could not wait on child after executing '%s'",
|
||||
(char*)program);
|
||||
}
|
||||
return pid;
|
||||
return pid;
|
||||
}
|
||||
/* Child */
|
||||
/* Child */
|
||||
alarm(0); /* create a clean environment before we exec the real child */
|
||||
|
||||
memset(&sigAct, 0, sizeof(sigAct));
|
||||
@ -637,7 +637,7 @@ int getSubString(uchar **ppSrc, char *pDst, size_t DstSize, char cSep)
|
||||
if ((cSep == ' ' ? !isspace(*pSrc) : *pSrc != cSep) && *pSrc != '\n' && *pSrc != '\0') {
|
||||
dbgprintf("in getSubString, error Src buffer > Dst buffer\n");
|
||||
iErr = 1;
|
||||
}
|
||||
}
|
||||
if (*pSrc == '\0' || *pSrc == '\n')
|
||||
/* this line was missing, causing ppSrc to be invalid when it
|
||||
* was returned in case of end-of-string. rgerhards 2005-07-29
|
||||
|
||||
@ -232,12 +232,12 @@ ctr_t **entryRef, int8_t linked)
|
||||
*entryRef = ctr;
|
||||
|
||||
finalize_it:
|
||||
if (iRet != RS_RET_OK) {
|
||||
if (ctr != NULL) {
|
||||
free(ctr->name);
|
||||
free(ctr);
|
||||
}
|
||||
}
|
||||
if (iRet != RS_RET_OK) {
|
||||
if (ctr != NULL) {
|
||||
free(ctr->name);
|
||||
free(ctr);
|
||||
}
|
||||
}
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ destructUnlinkedCounter(ctr_t *ctr) {
|
||||
static void
|
||||
destructCounter(statsobj_t *pThis, ctr_t *pCtr)
|
||||
{
|
||||
pthread_mutex_lock(&pThis->mutCtr);
|
||||
pthread_mutex_lock(&pThis->mutCtr);
|
||||
if (pCtr->prev != NULL) {
|
||||
pCtr->prev->next = pCtr->next;
|
||||
}
|
||||
|
||||
@ -862,7 +862,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF,
|
||||
if(pThis->bPrevWasNL) {
|
||||
if ((c == ' ') || (c == '\t')){
|
||||
CHKiRet(cstrAppendChar(*ppCStr, c));
|
||||
CHKiRet(strmReadChar(pThis, &c));
|
||||
CHKiRet(strmReadChar(pThis, &c));
|
||||
pThis->bPrevWasNL = 0;
|
||||
} else {
|
||||
/* clean things up by putting the character we just read back into
|
||||
@ -885,7 +885,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF,
|
||||
} else {
|
||||
CHKiRet(cstrAppendChar(*ppCStr, c));
|
||||
}
|
||||
CHKiRet(strmReadChar(pThis, &c));
|
||||
CHKiRet(strmReadChar(pThis, &c));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -900,7 +900,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF,
|
||||
}
|
||||
|
||||
finalize_it:
|
||||
if(iRet == RS_RET_OK) {
|
||||
if(iRet == RS_RET_OK) {
|
||||
if(strtOffs != NULL) {
|
||||
*strtOffs = pThis->strtOffs;
|
||||
}
|
||||
@ -920,7 +920,7 @@ finalize_it:
|
||||
}
|
||||
}
|
||||
|
||||
RETiRet;
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
/* check if the current multi line read is timed out
|
||||
@ -950,13 +950,13 @@ rsRetVal
|
||||
strmReadMultiLine(strm_t *pThis, cstr_t **ppCStr, regex_t *preg, const sbool bEscapeLF,
|
||||
const sbool discardTruncatedMsg, const sbool msgDiscardingError, int64 *const strtOffs)
|
||||
{
|
||||
uchar c;
|
||||
uchar c;
|
||||
uchar finished = 0;
|
||||
cstr_t *thisLine = NULL;
|
||||
rsRetVal readCharRet;
|
||||
const time_t tCurr = pThis->readTimeout ? getTime(NULL) : 0;
|
||||
int maxMsgSize = glblGetMaxLine();
|
||||
DEFiRet;
|
||||
DEFiRet;
|
||||
|
||||
do {
|
||||
CHKiRet(strmReadChar(pThis, &c)); /* immediately exit on EOF */
|
||||
@ -1073,7 +1073,7 @@ finalize_it:
|
||||
}
|
||||
}
|
||||
}
|
||||
RETiRet;
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
/* Standard-Constructor for the strm object
|
||||
@ -1544,7 +1544,7 @@ asyncWriterThread(void *pPtr)
|
||||
pthread_cond_broadcast(&pThis->isEmpty);
|
||||
}
|
||||
}
|
||||
/* Not reached */
|
||||
/* Not reached */
|
||||
|
||||
finalize_it:
|
||||
ENDfunc
|
||||
@ -2318,37 +2318,37 @@ static rsRetVal strmSetProperty(strm_t *pThis, var_t *pProp)
|
||||
ISOBJ_TYPE_assert(pThis, strm);
|
||||
ASSERT(pProp != NULL);
|
||||
|
||||
if(isProp("sType")) {
|
||||
if(isProp("sType")) {
|
||||
CHKiRet(strmSetsType(pThis, (strmType_t) pProp->val.num));
|
||||
} else if(isProp("iCurrFNum")) {
|
||||
} else if(isProp("iCurrFNum")) {
|
||||
pThis->iCurrFNum = (unsigned) pProp->val.num;
|
||||
} else if(isProp("pszFName")) {
|
||||
} else if(isProp("pszFName")) {
|
||||
CHKiRet(strmSetFName(pThis, rsCStrGetSzStrNoNULL(pProp->val.pStr), rsCStrLen(pProp->val.pStr)));
|
||||
} else if(isProp("tOperationsMode")) {
|
||||
} else if(isProp("tOperationsMode")) {
|
||||
CHKiRet(strmSettOperationsMode(pThis, pProp->val.num));
|
||||
} else if(isProp("tOpenMode")) {
|
||||
} else if(isProp("tOpenMode")) {
|
||||
CHKiRet(strmSettOpenMode(pThis, pProp->val.num));
|
||||
} else if(isProp("iCurrOffs")) {
|
||||
} else if(isProp("iCurrOffs")) {
|
||||
pThis->iCurrOffs = pProp->val.num;
|
||||
} else if(isProp("inode")) {
|
||||
} else if(isProp("inode")) {
|
||||
pThis->inode = (ino_t) pProp->val.num;
|
||||
} else if(isProp("strtOffs")) {
|
||||
} else if(isProp("strtOffs")) {
|
||||
pThis->strtOffs = pProp->val.num;
|
||||
} else if(isProp("iMaxFileSize")) {
|
||||
} else if(isProp("iMaxFileSize")) {
|
||||
CHKiRet(strmSetiMaxFileSize(pThis, pProp->val.num));
|
||||
} else if(isProp("fileNotFoundError")) {
|
||||
} else if(isProp("fileNotFoundError")) {
|
||||
CHKiRet(strmSetFileNotFoundError(pThis, pProp->val.num));
|
||||
} else if(isProp("iMaxFiles")) {
|
||||
} else if(isProp("iMaxFiles")) {
|
||||
CHKiRet(strmSetiMaxFiles(pThis, pProp->val.num));
|
||||
} else if(isProp("iFileNumDigits")) {
|
||||
} else if(isProp("iFileNumDigits")) {
|
||||
CHKiRet(strmSetiFileNumDigits(pThis, pProp->val.num));
|
||||
} else if(isProp("bDeleteOnClose")) {
|
||||
} else if(isProp("bDeleteOnClose")) {
|
||||
CHKiRet(strmSetbDeleteOnClose(pThis, pProp->val.num));
|
||||
} else if(isProp("prevLineSegment")) {
|
||||
} else if(isProp("prevLineSegment")) {
|
||||
CHKiRet(rsCStrConstructFromCStr(&pThis->prevLineSegment, pProp->val.pStr));
|
||||
} else if(isProp("prevMsgSegment")) {
|
||||
} else if(isProp("prevMsgSegment")) {
|
||||
CHKiRet(rsCStrConstructFromCStr(&pThis->prevMsgSegment, pProp->val.pStr));
|
||||
} else if(isProp("bPrevWasNL")) {
|
||||
} else if(isProp("bPrevWasNL")) {
|
||||
pThis->bPrevWasNL = (sbool) pProp->val.num;
|
||||
}
|
||||
|
||||
|
||||
@ -307,7 +307,7 @@ static void deinit_strm_listener(strmsrv_t *pThis)
|
||||
/* now get next... */
|
||||
i = STRMSessGetNxtSess(pThis, i);
|
||||
}
|
||||
|
||||
|
||||
/* we are done with the session table - so get rid of it... */
|
||||
free(pThis->pSessions);
|
||||
pThis->pSessions = NULL; /* just to make sure... */
|
||||
|
||||
@ -95,7 +95,7 @@ CreateSocket(struct addrinfo *addrDest)
|
||||
char errStr[1024];
|
||||
dbgprintf("couldn't create send socket, reason %s", rs_strerror_r(errno, errStr,
|
||||
sizeof(errStr)));
|
||||
}
|
||||
}
|
||||
r = r->ai_next;
|
||||
}
|
||||
|
||||
|
||||
@ -1187,10 +1187,10 @@ SetKeepAliveProbes(tcpsrv_t *pThis, int iVal)
|
||||
static rsRetVal
|
||||
SetKeepAliveTime(tcpsrv_t *pThis, int iVal)
|
||||
{
|
||||
DEFiRet;
|
||||
DBGPRINTF("tcpsrv: keep-alive timeout set to %d\n", iVal);
|
||||
pThis->iKeepAliveTime = iVal;
|
||||
RETiRet;
|
||||
DEFiRet;
|
||||
DBGPRINTF("tcpsrv: keep-alive timeout set to %d\n", iVal);
|
||||
pThis->iKeepAliveTime = iVal;
|
||||
RETiRet;
|
||||
}
|
||||
|
||||
static rsRetVal
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#define INCLUDED_TYPEDEFS_H
|
||||
|
||||
#ifndef _AIX
|
||||
#include <stdint.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef _AIX
|
||||
#include "config.h"
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#ifdef USE_UNLIMITED_SELECT
|
||||
static inline void freeFdSet(fd_set *p) {
|
||||
free(p);
|
||||
free(p);
|
||||
}
|
||||
#else
|
||||
# define freeFdSet(x)
|
||||
|
||||
20
template.c
20
template.c
@ -647,7 +647,7 @@ do_Constant(unsigned char **pp, struct template *pTpl, int bDoEscapes)
|
||||
while(*p && *p != '%' && !(bDoEscapes && *p == '\"')) {
|
||||
if(bDoEscapes && *p == '\\') {
|
||||
switch(*++p) {
|
||||
case '\0':
|
||||
case '\0':
|
||||
/* the best we can do - it's invalid anyhow... */
|
||||
cstrAppendChar(pStrB, *p);
|
||||
break;
|
||||
@ -760,8 +760,8 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe)
|
||||
*/
|
||||
if(!strcmp((char*)Buf, "date-mysql")) {
|
||||
pTpe->data.field.eDateFormat = tplFmtMySQLDate;
|
||||
} else if(!strcmp((char*)Buf, "date-pgsql")) {
|
||||
pTpe->data.field.eDateFormat = tplFmtPgSQLDate;
|
||||
} else if(!strcmp((char*)Buf, "date-pgsql")) {
|
||||
pTpe->data.field.eDateFormat = tplFmtPgSQLDate;
|
||||
} else if(!strcmp((char*)Buf, "date-rfc3164")) {
|
||||
pTpe->data.field.eDateFormat = tplFmtRFC3164Date;
|
||||
} else if(!strcmp((char*)Buf, "date-rfc3164-buggyday")) {
|
||||
@ -1264,7 +1264,7 @@ tplAddTplMod(struct template *pTpl, uchar** ppRestOfConfLine)
|
||||
while(*pSrc && !isspace(*pSrc) && lenMod < sizeof(szMod) - 1) {
|
||||
szMod[lenMod] = *pSrc++;
|
||||
lenMod++;
|
||||
|
||||
|
||||
}
|
||||
szMod[lenMod] = '\0';
|
||||
*ppRestOfConfLine = pSrc;
|
||||
@ -1300,7 +1300,7 @@ finalize_it:
|
||||
struct template *tplAddLine(rsconf_t *conf, const char* pName, uchar** ppRestOfConfLine)
|
||||
{
|
||||
struct template *pTpl;
|
||||
unsigned char *p;
|
||||
unsigned char *p;
|
||||
int bDone;
|
||||
size_t i;
|
||||
rsRetVal localRet;
|
||||
@ -1392,14 +1392,14 @@ struct template *tplAddLine(rsconf_t *conf, const char* pName, uchar** ppRestOfC
|
||||
while(*p) {
|
||||
while(isspace((int)*p))/* skip whitespace */
|
||||
++p;
|
||||
|
||||
|
||||
if(*p != ',')
|
||||
break;
|
||||
++p; /* eat ',' */
|
||||
|
||||
while(isspace((int)*p))/* skip whitespace */
|
||||
++p;
|
||||
|
||||
|
||||
/* read option word */
|
||||
char optBuf[128] = { '\0' }; /* buffer for options - should be more than enough... */
|
||||
i = 0;
|
||||
@ -2345,9 +2345,9 @@ void tplPrintList(rsconf_t *conf)
|
||||
case tplFmtMySQLDate:
|
||||
dbgprintf("[Format as MySQL-Date] ");
|
||||
break;
|
||||
case tplFmtPgSQLDate:
|
||||
dbgprintf("[Format as PgSQL-Date] ");
|
||||
break;
|
||||
case tplFmtPgSQLDate:
|
||||
dbgprintf("[Format as PgSQL-Date] ");
|
||||
break;
|
||||
case tplFmtRFC3164Date:
|
||||
dbgprintf("[Format as RFC3164-Date] ");
|
||||
break;
|
||||
|
||||
14
template.h
14
template.h
@ -60,12 +60,12 @@ struct template {
|
||||
|
||||
enum EntryTypes { UNDEFINED = 0, CONSTANT = 1, FIELD = 2 };
|
||||
enum tplFormatTypes { tplFmtDefault = 0, tplFmtMySQLDate = 1,
|
||||
tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3, tplFmtPgSQLDate = 4,
|
||||
tplFmtSecFrac = 5, tplFmtRFC3164BuggyDate = 6, tplFmtUnixDate = 7,
|
||||
tplFmtWDayName = 8, tplFmtYear = 9, tplFmtMonth = 10, tplFmtDay = 11,
|
||||
tplFmtHour = 12, tplFmtMinute = 13, tplFmtSecond = 14,
|
||||
tplFmtTZOffsHour = 15, tplFmtTZOffsMin = 16, tplFmtTZOffsDirection = 17,
|
||||
tplFmtWDay = 18, tplFmtOrdinal = 19, tplFmtWeek = 20};
|
||||
tplFmtRFC3164Date = 2, tplFmtRFC3339Date = 3, tplFmtPgSQLDate = 4,
|
||||
tplFmtSecFrac = 5, tplFmtRFC3164BuggyDate = 6, tplFmtUnixDate = 7,
|
||||
tplFmtWDayName = 8, tplFmtYear = 9, tplFmtMonth = 10, tplFmtDay = 11,
|
||||
tplFmtHour = 12, tplFmtMinute = 13, tplFmtSecond = 14,
|
||||
tplFmtTZOffsHour = 15, tplFmtTZOffsMin = 16, tplFmtTZOffsDirection = 17,
|
||||
tplFmtWDay = 18, tplFmtOrdinal = 19, tplFmtWeek = 20};
|
||||
enum tplFormatCaseConvTypes { tplCaseConvNo = 0, tplCaseConvUpper = 1, tplCaseConvLower = 2 };
|
||||
enum tplRegexType { TPL_REGEX_BRE = 0, /* posix BRE */
|
||||
TPL_REGEX_ERE = 1 /* posix ERE */
|
||||
@ -104,7 +104,7 @@ struct templateEntry {
|
||||
that we were searching in*/
|
||||
TPL_REGEX_NOMATCH_USE_ZERO = 3 /* use 0 (useful for numerical values) */
|
||||
} nomatchAction; /**< what to do if we do not have a match? */
|
||||
|
||||
|
||||
#endif
|
||||
unsigned has_fields; /* support for field-counting: field to extract */
|
||||
unsigned char field_delim; /* support for field-counting: field delemiter char */
|
||||
|
||||
130
tests/tcpflood.c
130
tests/tcpflood.c
@ -254,7 +254,7 @@ static void closeTLSSess(int __attribute__((unused)) i);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-security"
|
||||
static void relp_dbgprintf(char __attribute__((unused)) *fmt, ...) {
|
||||
printf(fmt);
|
||||
printf(fmt);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
@ -938,79 +938,79 @@ runTests(void)
|
||||
*/
|
||||
|
||||
long BIO_debug_callback(BIO *bio, int cmd, const char __attribute__((unused)) *argp,
|
||||
int argi, long __attribute__((unused)) argl, long ret)
|
||||
int argi, long __attribute__((unused)) argl, long ret)
|
||||
{
|
||||
long r = 1;
|
||||
long r = 1;
|
||||
|
||||
if (BIO_CB_RETURN & cmd)
|
||||
r = ret;
|
||||
if (BIO_CB_RETURN & cmd)
|
||||
r = ret;
|
||||
|
||||
printf("tcpdump: openssl debugmsg: BIO[%p]: ", (void *)bio);
|
||||
printf("tcpdump: openssl debugmsg: BIO[%p]: ", (void *)bio);
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CB_FREE:
|
||||
printf("Free - %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
switch (cmd) {
|
||||
case BIO_CB_FREE:
|
||||
printf("Free - %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
/* Disabled due API changes for OpenSSL 1.1.0+ */
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
case BIO_CB_READ:
|
||||
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
||||
printf("read(%d,%lu) - %s fd=%d\n",
|
||||
RSYSLOG_BIO_number_read(bio), (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_read(bio));
|
||||
else
|
||||
printf("read(%d,%lu) - %s\n",
|
||||
RSYSLOG_BIO_number_read(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_WRITE:
|
||||
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
||||
printf("write(%d,%lu) - %s fd=%d\n",
|
||||
RSYSLOG_BIO_number_written(bio), (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_written(bio));
|
||||
else
|
||||
printf("write(%d,%lu) - %s\n",
|
||||
RSYSLOG_BIO_number_written(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_READ:
|
||||
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
||||
printf("read(%d,%lu) - %s fd=%d\n",
|
||||
RSYSLOG_BIO_number_read(bio), (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_read(bio));
|
||||
else
|
||||
printf("read(%d,%lu) - %s\n",
|
||||
RSYSLOG_BIO_number_read(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_WRITE:
|
||||
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
|
||||
printf("write(%d,%lu) - %s fd=%d\n",
|
||||
RSYSLOG_BIO_number_written(bio), (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio), RSYSLOG_BIO_number_written(bio));
|
||||
else
|
||||
printf("write(%d,%lu) - %s\n",
|
||||
RSYSLOG_BIO_number_written(bio), (unsigned long)argi, RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
#else
|
||||
case BIO_CB_READ:
|
||||
printf("read %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_WRITE:
|
||||
printf("write %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_READ:
|
||||
printf("read %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_WRITE:
|
||||
printf("write %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
#endif
|
||||
case BIO_CB_PUTS:
|
||||
printf("puts() - %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_GETS:
|
||||
printf("gets(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_CTRL:
|
||||
printf("ctrl(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_READ:
|
||||
printf("read return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_WRITE:
|
||||
printf("write return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_GETS:
|
||||
printf("gets return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_PUTS:
|
||||
printf("puts return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_CTRL:
|
||||
printf("ctrl return %ld\n", ret);
|
||||
break;
|
||||
default:
|
||||
printf("bio callback - unknown type (%d)\n", cmd);
|
||||
break;
|
||||
}
|
||||
case BIO_CB_PUTS:
|
||||
printf("puts() - %s\n", RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_GETS:
|
||||
printf("gets(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_CTRL:
|
||||
printf("ctrl(%lu) - %s\n", (unsigned long)argi,
|
||||
RSYSLOG_BIO_method_name(bio));
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_READ:
|
||||
printf("read return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_WRITE:
|
||||
printf("write return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_GETS:
|
||||
printf("gets return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_PUTS:
|
||||
printf("puts return %ld\n", ret);
|
||||
break;
|
||||
case BIO_CB_RETURN | BIO_CB_CTRL:
|
||||
printf("ctrl return %ld\n", ret);
|
||||
break;
|
||||
default:
|
||||
printf("bio callback - unknown type (%d)\n", cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
return (r);
|
||||
return (r);
|
||||
}
|
||||
|
||||
void osslLastSSLErrorMsg(int ret, SSL *ssl, const char* pszCallSource)
|
||||
|
||||
@ -55,7 +55,7 @@ static rsRetVal doInit(void) \
|
||||
DEFiRet; \
|
||||
char *pErrObj; /* tells us which object failed if that happens */ \
|
||||
putenv("RSYSLOG_MODDIR=../runtime/.libs/"); /* this is a bit hackish... */ \
|
||||
\
|
||||
\
|
||||
dbgClassInit(); \
|
||||
/* Intialize the runtime system */ \
|
||||
pErrObj = "rsyslog runtime"; /* set in case the runtime errors before setting an object */ \
|
||||
@ -68,7 +68,7 @@ finalize_it: \
|
||||
if(iRet != RS_RET_OK) { \
|
||||
printf("failure occured during init of object '%s'\n", pErrObj); \
|
||||
} \
|
||||
\
|
||||
\
|
||||
RETiRet; \
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ int addNL = 0;
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
unlink(sockName);
|
||||
unlink(sockName);
|
||||
close(sock);
|
||||
}
|
||||
|
||||
@ -77,12 +77,12 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
int rlen;
|
||||
int rlen;
|
||||
FILE *fp = stdout;
|
||||
unsigned char data[128*1024];
|
||||
struct sockaddr_un addr; /* address of server */
|
||||
struct sockaddr from;
|
||||
socklen_t fromlen;
|
||||
unsigned char data[128*1024];
|
||||
struct sockaddr_un addr; /* address of server */
|
||||
struct sockaddr from;
|
||||
socklen_t fromlen;
|
||||
|
||||
if(argc < 2) {
|
||||
fprintf(stderr, "error: too few arguments!\n");
|
||||
@ -91,13 +91,13 @@ main(int argc, char *argv[])
|
||||
|
||||
while((opt = getopt(argc, argv, "s:o:l")) != EOF) {
|
||||
switch((char)opt) {
|
||||
case 'l':
|
||||
case 'l':
|
||||
addNL = 1;
|
||||
break;
|
||||
case 's':
|
||||
case 's':
|
||||
sockName = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
case 'o':
|
||||
if((fp = fopen(optarg, "w")) == NULL) {
|
||||
perror(optarg);
|
||||
exit(1);
|
||||
@ -112,33 +112,33 @@ main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(signal(SIGTERM, doTerm) == SIG_ERR) {
|
||||
if(signal(SIGTERM, doTerm) == SIG_ERR) {
|
||||
perror("signal(SIGTERM, ...)");
|
||||
exit(1);
|
||||
}
|
||||
if(signal(SIGINT, doTerm) == SIG_ERR) {
|
||||
if(signal(SIGINT, doTerm) == SIG_ERR) {
|
||||
perror("signal(SIGINT, ...)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create a UNIX datagram socket for server */
|
||||
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("server: socket");
|
||||
exit(1);
|
||||
}
|
||||
/* Create a UNIX datagram socket for server */
|
||||
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("server: socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
atexit(cleanup);
|
||||
|
||||
/* Set up address structure for server socket */
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy(addr.sun_path, sockName);
|
||||
/* Set up address structure for server socket */
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
strcpy(addr.sun_path, sockName);
|
||||
|
||||
if (bind(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
|
||||
close(sock);
|
||||
perror("server: bind");
|
||||
exit(1);
|
||||
}
|
||||
if (bind(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
|
||||
close(sock);
|
||||
perror("server: bind");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* we now run in an endless loop. We do not check who sends us
|
||||
* data. This should be no problem for our testbench use.
|
||||
@ -154,7 +154,7 @@ main(int argc, char *argv[])
|
||||
if(addNL)
|
||||
fputc('\n', fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -279,9 +279,9 @@ rsRetVal thrdCreate(rsRetVal (*thrdMain)(thrdInfo_t*), rsRetVal(*afterRun)(thrdI
|
||||
pThis->bNeedsCancel = bNeedsCancel;
|
||||
pThis->name = ustrdup(name);
|
||||
#if defined (_AIX)
|
||||
pthread_attr_init(&aix_attr);
|
||||
pthread_attr_setstacksize(&aix_attr, 4096*512);
|
||||
pthread_create(&pThis->thrdID, &aix_attr, thrdStarter, pThis);
|
||||
pthread_attr_init(&aix_attr);
|
||||
pthread_attr_setstacksize(&aix_attr, 4096*512);
|
||||
pthread_create(&pThis->thrdID, &aix_attr, thrdStarter, pThis);
|
||||
#else
|
||||
pthread_create(&pThis->thrdID, &default_thread_attr, thrdStarter, pThis);
|
||||
#endif
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright 2017 Hugo Soszynski and aDvens
|
||||
*
|
||||
* long short
|
||||
* long short
|
||||
|
||||
* level l read records with level x
|
||||
* severity s read records with severity x
|
||||
|
||||
@ -1409,7 +1409,7 @@ CODESTARTparseSelectorAct
|
||||
pData->iSizeLimit = 0; /* default value, use outchannels to configure! */
|
||||
|
||||
switch(*p) {
|
||||
case '$':
|
||||
case '$':
|
||||
CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
||||
pData->iNumTpls = 1;
|
||||
/* rgerhards 2005-06-21: this is a special setting for output-channel
|
||||
|
||||
@ -1330,7 +1330,7 @@ BEGINparseSelectorAct
|
||||
uchar *q;
|
||||
int i;
|
||||
rsRetVal localRet;
|
||||
struct addrinfo;
|
||||
struct addrinfo;
|
||||
TCPFRAMINGMODE tcp_framing = TCP_FRAMING_OCTET_STUFFING;
|
||||
CODESTARTparseSelectorAct
|
||||
CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
||||
|
||||
@ -397,7 +397,7 @@ CODESTARTparseSelectorAct
|
||||
++p;
|
||||
CHKiRet(cflineParseFileName(p, (uchar*) pData->pipe, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS,
|
||||
getDfltTpl()));
|
||||
|
||||
|
||||
CODE_STD_FINALIZERparseSelectorAct
|
||||
ENDparseSelectorAct
|
||||
|
||||
|
||||
@ -408,7 +408,7 @@ CODEmodInit_QueryRegCFSLineHdlr
|
||||
CHKiRet(objUse(datetime, CORE_COMPONENT));
|
||||
|
||||
DBGPRINTF("rfc3164 parser init called\n");
|
||||
bParseHOSTNAMEandTAG = glbl.GetParseHOSTNAMEandTAG();
|
||||
bParseHOSTNAMEandTAG = glbl.GetParseHOSTNAMEandTAG();
|
||||
/* cache value, is set only during rsyslogd option processing */
|
||||
|
||||
|
||||
|
||||
@ -237,7 +237,7 @@ CODESTARTparse
|
||||
* wiser than to use individual buffers.
|
||||
*/
|
||||
CHKmalloc(pBuf = MALLOC(lenMsg + 1));
|
||||
|
||||
|
||||
/* IMPORTANT NOTE:
|
||||
* Validation is not actually done below nor are any errors handled. I have
|
||||
* NOT included this for the current proof of concept. However, it is strongly
|
||||
|
||||
@ -182,7 +182,7 @@ done: return r;
|
||||
static int
|
||||
initCrypt(FILE *eifp)
|
||||
{
|
||||
int r = 0;
|
||||
int r = 0;
|
||||
gcry_error_t gcryError;
|
||||
char iv[4096];
|
||||
|
||||
@ -296,21 +296,21 @@ doDecrypt(FILE *logfp, FILE *eifp, FILE *outfp)
|
||||
off64_t currOffs = 0;
|
||||
int r = 1;
|
||||
int fd;
|
||||
struct stat buf;
|
||||
struct stat buf;
|
||||
|
||||
while(1) {
|
||||
/* process block */
|
||||
if(initCrypt(eifp) != 0)
|
||||
goto done;
|
||||
/* set blkEnd to size of logfp and proceed. */
|
||||
if((fd = fileno(logfp)) == -1) {
|
||||
r = -1;
|
||||
goto done;
|
||||
}
|
||||
if((r = fstat(fd, &buf)) != 0) goto done;
|
||||
blkEnd = buf.st_size;
|
||||
r = eiGetEND(eifp, &blkEnd);
|
||||
if(r != 0 && r != 1) goto done;
|
||||
if((fd = fileno(logfp)) == -1) {
|
||||
r = -1;
|
||||
goto done;
|
||||
}
|
||||
if((r = fstat(fd, &buf)) != 0) goto done;
|
||||
blkEnd = buf.st_size;
|
||||
r = eiGetEND(eifp, &blkEnd);
|
||||
if(r != 0 && r != 1) goto done;
|
||||
decryptBlock(logfp, outfp, blkEnd, &currOffs);
|
||||
gcry_cipher_close(gcry_chd);
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ static int bHadHUP;
|
||||
static int doFork = 1; /* fork - run in daemon mode - read-only after startup */
|
||||
int bFinished = 0; /* used by termination signal handler, read-only except there
|
||||
* is either 0 or the number of the signal that requested the
|
||||
* termination.
|
||||
* termination.
|
||||
*/
|
||||
const char *PidFile;
|
||||
#define NO_PIDFILE "NONE"
|
||||
@ -1309,9 +1309,9 @@ initAll(int argc, char **argv)
|
||||
while((ch = getopt(argc, argv, "46ACDdf:i:l:M:nN:qQs:S:T:u:vwx")) != EOF) {
|
||||
#endif
|
||||
switch((char)ch) {
|
||||
case '4':
|
||||
case '6':
|
||||
case 'A':
|
||||
case '4':
|
||||
case '6':
|
||||
case 'A':
|
||||
case 'f': /* configuration file */
|
||||
case 'i': /* pid file name */
|
||||
case 'l':
|
||||
@ -1392,24 +1392,24 @@ initAll(int argc, char **argv)
|
||||
while((iRet = bufOptRemove(&ch, &arg)) == RS_RET_OK) {
|
||||
DBGPRINTF("deque option %c, optarg '%s'\n", ch, (arg == NULL) ? "" : arg);
|
||||
switch((char)ch) {
|
||||
case '4':
|
||||
case '4':
|
||||
fprintf (stderr, "rsyslogd: the -4 command line option will go away "
|
||||
"soon.\nPlease use the global(net.ipprotocol=\"ipv4-only\") "
|
||||
"configuration parameter instead.\n");
|
||||
glbl.SetDefPFFamily(PF_INET);
|
||||
break;
|
||||
case '6':
|
||||
break;
|
||||
case '6':
|
||||
fprintf (stderr, "rsyslogd: the -6 command line option will go away "
|
||||
"soon.\nPlease use the global(net.ipprotocol=\"ipv6-only\") "
|
||||
"configuration parameter instead.\n");
|
||||
glbl.SetDefPFFamily(PF_INET6);
|
||||
break;
|
||||
case 'A':
|
||||
glbl.SetDefPFFamily(PF_INET6);
|
||||
break;
|
||||
case 'A':
|
||||
fprintf (stderr, "rsyslogd: the -A command line option will go away "
|
||||
"soon.\n"
|
||||
"Please use the omfwd parameter \"upd.sendToAll\" instead.\n");
|
||||
send_to_all++;
|
||||
break;
|
||||
send_to_all++;
|
||||
break;
|
||||
case 'S': /* Source IP for local client to be used on multihomed host */
|
||||
fprintf (stderr, "rsyslogd: the -S command line option will go away "
|
||||
"soon.\n"
|
||||
@ -1477,8 +1477,8 @@ initAll(int argc, char **argv)
|
||||
perror("chroot");
|
||||
exit(1);
|
||||
}
|
||||
if(chdir("/") != 0) {
|
||||
perror("chdir");
|
||||
if(chdir("/") != 0) {
|
||||
perror("chdir");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
@ -1514,7 +1514,7 @@ initAll(int argc, char **argv)
|
||||
"configuration parameter instead.\n");
|
||||
glbl.SetDisableDNS(1);
|
||||
break;
|
||||
case '?':
|
||||
case '?':
|
||||
default:
|
||||
rsyslogd_usage();
|
||||
}
|
||||
|
||||
@ -350,8 +350,8 @@ doTest(syncType_t st)
|
||||
}
|
||||
|
||||
/* we have a memory leak due to calling dispRuntime(), but we don't
|
||||
* care as we terminate immediately.
|
||||
*/
|
||||
* care as we terminate immediately.
|
||||
*/
|
||||
printf("%-10s: total runtime %6ld.%3.3u, avg %s, min %s, max %s\n",
|
||||
getSyncMethName(st),
|
||||
(long)totalRuntime/1000, (unsigned)(totalRuntime % 1000),
|
||||
|
||||
@ -147,7 +147,7 @@ char **syslogd_crunch_list(char *list)
|
||||
}
|
||||
/* cut off leading delimiters */
|
||||
while (p[0] == LIST_DELIMITER) {
|
||||
p++;
|
||||
p++;
|
||||
}
|
||||
|
||||
/* count delimiters to calculate elements */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user