reference: remove global

pull/1484/head
Victor Julien 10 years ago
parent 393689ce44
commit b2da57c827

@ -822,7 +822,7 @@ static DetectEngineCtx *DetectEngineCtxInitReal(int minimal, const char *prefix)
#endif
SCClassConfLoadClassficationConfigFile(de_ctx, NULL);
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfLoadReferenceConfigFile(de_ctx, NULL);
if (ActionInitConfig() < 0) {
goto error;

@ -242,9 +242,8 @@ static int DetectReferenceParseTest01(void)
}
de_ctx->flags |= DE_QUIET;
SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
s = de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
"(msg:\"One reference\"; reference:one,001-2010; sid:2;)");
@ -289,9 +288,8 @@ static int DetectReferenceParseTest02(void)
}
de_ctx->flags |= DE_QUIET;
SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
s = de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
"(msg:\"Two references\"; "
@ -344,9 +342,8 @@ static int DetectReferenceParseTest03(void)
}
de_ctx->flags |= DE_QUIET;
SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd =SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
s = de_ctx->sig_list = SigInit(de_ctx, "alert icmp any any -> any any "
"(msg:\"invalid ref\"; "

@ -43,7 +43,6 @@
/* Holds a pointer to the default path for the reference.config file */
static const char *file_path = SC_RCONF_DEFAULT_FILE_PATH;
static FILE *fd = NULL;
static pcre *regex = NULL;
static pcre_extra *regex_study = NULL;
@ -69,7 +68,7 @@ static char *SCRConfGetConfFilename(void);
* \retval 0 On success.
* \retval -1 On failure.
*/
static int SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx)
static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
{
char *filename = NULL;
const char *eb = NULL;
@ -116,7 +115,7 @@ static int SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx)
goto error;
}
return 0;
return fd;
error:
if (de_ctx->reference_conf_ht != NULL) {
@ -137,7 +136,7 @@ static int SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx)
regex_study = NULL;
}
return -1;
return NULL;
}
@ -162,12 +161,13 @@ static char *SCRConfGetConfFilename(void)
/**
* \brief Releases local resources used by the Reference Config API.
*/
static void SCRConfDeInitLocalResources(DetectEngineCtx *de_ctx)
static void SCRConfDeInitLocalResources(DetectEngineCtx *de_ctx, FILE *fd)
{
if (fd != NULL)
if (fd != NULL) {
fclose(fd);
fd = NULL;
}
file_path = SC_RCONF_DEFAULT_FILE_PATH;
fd = NULL;
if (regex != NULL) {
pcre_free(regex);
@ -319,7 +319,7 @@ static int SCRConfIsLineBlankOrComment(char *line)
*
* \param de_ctx Pointer to the Detection Engine Context.
*/
static void SCRConfParseFile(DetectEngineCtx *de_ctx)
static void SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
{
char line[1024];
uint8_t i = 1;
@ -487,9 +487,10 @@ void SCRConfReferenceHashFree(void *data)
* \retval 0 On success.
* \retval -1 On failure.
*/
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx)
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
{
if (SCRConfInitContextAndLocalResources(de_ctx) == -1) {
fd = SCRConfInitContextAndLocalResources(de_ctx, fd);
if (fd == NULL) {
#ifdef UNITTESTS
if (RunmodeIsUnittests() && fd == NULL) {
return -1;
@ -500,8 +501,8 @@ int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx)
return -1;
}
SCRConfParseFile(de_ctx);
SCRConfDeInitLocalResources(de_ctx);
SCRConfParseFile(de_ctx, fd);
SCRConfDeInitLocalResources(de_ctx, fd);
return 0;
}
@ -539,7 +540,7 @@ SCRConfReference *SCRConfGetReference(const char *rconf_name,
* \brief Creates a dummy reference config, with all valid references, for
* testing purposes.
*/
void SCRConfGenerateValidDummyReferenceConfigFD01(void)
FILE *SCRConfGenerateValidDummyReferenceConfigFD01(void)
{
const char *buffer =
"config reference: one http://www.one.com\n"
@ -548,18 +549,18 @@ void SCRConfGenerateValidDummyReferenceConfigFD01(void)
"config reference: one http://www.one.com\n"
"config reference: three http://www.three.com\n";
fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
if (fd == NULL)
SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
return;
return fd;
}
/**
* \brief Creates a dummy reference config, with some valid references and a
* couple of invalid references, for testing purposes.
*/
void SCRConfGenerateInValidDummyReferenceConfigFD02(void)
FILE *SCRConfGenerateInValidDummyReferenceConfigFD02(void)
{
const char *buffer =
"config reference: one http://www.one.com\n"
@ -568,18 +569,18 @@ void SCRConfGenerateInValidDummyReferenceConfigFD02(void)
"config reference: four\n"
"config reference five http://www.five.com\n";
fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
if (fd == NULL)
SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
return;
return fd;
}
/**
* \brief Creates a dummy reference config, with all invalid references, for
* testing purposes.
*/
void SCRConfGenerateInValidDummyReferenceConfigFD03(void)
FILE *SCRConfGenerateInValidDummyReferenceConfigFD03(void)
{
const char *buffer =
"config reference one http://www.one.com\n"
@ -587,24 +588,11 @@ void SCRConfGenerateInValidDummyReferenceConfigFD03(void)
"config reference_: three http://www.three.com\n"
"config reference: four\n";
fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
FILE *fd = SCFmemopen((void *)buffer, strlen(buffer), "r");
if (fd == NULL)
SCLogDebug("Error with SCFmemopen() called by Reference Config test code");
return;
}
/**
* \brief Deletes the FD, if set by the other testing functions.
*/
void SCRConfDeleteDummyReferenceConfigFD(void)
{
if (fd != NULL) {
fclose(fd);
fd = NULL;
}
return;
return fd;
}
/**
@ -619,9 +607,8 @@ int SCRConfTest01(void)
if (de_ctx == NULL)
return result;
SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
if (de_ctx->reference_conf_ht == NULL)
goto end;
@ -648,9 +635,8 @@ int SCRConfTest02(void)
if (de_ctx == NULL)
return result;
SCRConfGenerateInValidDummyReferenceConfigFD03();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateInValidDummyReferenceConfigFD03();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
if (de_ctx->reference_conf_ht == NULL)
goto end;
@ -676,9 +662,8 @@ int SCRConfTest03(void)
if (de_ctx == NULL)
return result;
SCRConfGenerateInValidDummyReferenceConfigFD02();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateInValidDummyReferenceConfigFD02();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
if (de_ctx->reference_conf_ht == NULL)
goto end;
@ -703,9 +688,8 @@ int SCRConfTest04(void)
if (de_ctx == NULL)
return 0;
SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateValidDummyReferenceConfigFD01();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
if (de_ctx->reference_conf_ht == NULL)
goto end;
@ -736,9 +720,8 @@ int SCRConfTest05(void)
if (de_ctx == NULL)
return 0;
SCRConfGenerateInValidDummyReferenceConfigFD03();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateInValidDummyReferenceConfigFD03();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
if (de_ctx->reference_conf_ht == NULL)
goto end;
@ -769,9 +752,8 @@ int SCRConfTest06(void)
if (de_ctx == NULL)
return 0;
SCRConfGenerateInValidDummyReferenceConfigFD02();
SCRConfLoadReferenceConfigFile(de_ctx);
SCRConfDeleteDummyReferenceConfigFD();
FILE *fd = SCRConfGenerateInValidDummyReferenceConfigFD02();
SCRConfLoadReferenceConfigFile(de_ctx, fd);
if (de_ctx->reference_conf_ht == NULL)
goto end;

@ -36,16 +36,15 @@ typedef struct SCRConfReference_ {
SCRConfReference *SCRConfAllocSCRConfReference(const char *, const char *);
void SCRConfDeAllocSCRConfReference(SCRConfReference *);
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *);
int SCRConfLoadReferenceConfigFile(DetectEngineCtx *, FILE *);
void SCRConfDeInitContext(DetectEngineCtx *);
SCRConfReference *SCRConfGetReference(const char *,
DetectEngineCtx *);
void SCRConfRegisterTests(void);
/* these below functions are only used by unittests */
void SCRConfGenerateValidDummyReferenceConfigFD01(void);
void SCRConfGenerateInValidDummyReferenceConfigFD02(void);
void SCRConfGenerateInValidDummyReferenceConfigFD03(void);
void SCRConfDeleteDummyReferenceConfigFD(void);
FILE *SCRConfGenerateValidDummyReferenceConfigFD01(void);
FILE *SCRConfGenerateInValidDummyReferenceConfigFD02(void);
FILE *SCRConfGenerateInValidDummyReferenceConfigFD03(void);
#endif /* __UTIL_REFERENCE_CONFIG_H__ */

Loading…
Cancel
Save