|
|
@@ -25,6 +25,8 @@ |
|
|
|
|
|
|
|
SNFMilterContextPool* MilterContexts = 0; // The global contexts handle.
|
|
|
|
bool MilterDebugMode; // True if debug mode is on.
|
|
|
|
sfsistat SkipReturn = SMFIS_CONTINUE; // libmilter return value when further
|
|
|
|
// callbacks of the same type are to be skipped.
|
|
|
|
|
|
|
|
/// Get the connection context object.
|
|
|
|
//
|
|
|
@@ -41,6 +43,24 @@ getContextFromCtx(SMFICTX* Ctx) { |
|
|
|
return Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get a new connection object and assign it to the context.
|
|
|
|
//
|
|
|
|
// \param[in] Ctx is the libmilter context object.
|
|
|
|
//
|
|
|
|
// \returns the pointer to the connection context object.
|
|
|
|
//
|
|
|
|
// \throws runtime_error if the obtained pointer is 0.
|
|
|
|
//
|
|
|
|
SNFMilterContext *
|
|
|
|
assignContextToCtx(SMFICTX* Ctx) {
|
|
|
|
SNFMilterContext *Context = MilterContexts->grab(); // Get any existing context object.
|
|
|
|
if(0 == Context) // Check address.
|
|
|
|
throw runtime_error("Got NULL from MilterContexts->grab()");
|
|
|
|
smfi_setpriv(Ctx, Context); // Save the context object.
|
|
|
|
Context->ConnectionData.clear(); // Clear the connection context object.
|
|
|
|
return Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to output an info message.
|
|
|
|
void logInfo(const string ContextName, int Code, std::string Message) {
|
|
|
|
cout << ContextName << " (code " << Code << "): " << Message << endl;
|
|
|
@@ -238,7 +258,6 @@ string SNFMilterEngine::XHeaders() { |
|
|
|
//// SNFMilterContext
|
|
|
|
|
|
|
|
SNFMilterContext::SNFMilterContext(snf_RulebaseHandler *myRulebase) :
|
|
|
|
SkipReturn(SMFIS_CONTINUE),
|
|
|
|
milterEngine(myRulebase),
|
|
|
|
MessageData(MailBufferReserveSize) {}
|
|
|
|
|
|
|
@@ -461,18 +480,8 @@ extern "C" { |
|
|
|
sfsistat CallbackResult = FailSafeMilterResponse;
|
|
|
|
|
|
|
|
try {
|
|
|
|
#ifdef NEW_SNFMILTER
|
|
|
|
SNFMilterContext *Context = getContextFromCtx(Ctx); // Get the existing context object.
|
|
|
|
#else
|
|
|
|
SNFMilterContext *Context = (SNFMilterContext *) smfi_getpriv(Ctx); // Get the context object.
|
|
|
|
if (0 == Context) {
|
|
|
|
Context = MilterContexts->grab(); // Get a context object.
|
|
|
|
if(0 == Context) // Check address.
|
|
|
|
throw runtime_error("Got NULL from MilterContexts->grab()");
|
|
|
|
smfi_setpriv(Ctx, Context); // Save the context object.
|
|
|
|
Context->ConnectionData.clear(); // Clear the connection context object.
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
SNFMilterContext *Context = assignContextToCtx(Ctx); // Get the existing context object,
|
|
|
|
// or assign a new context object.
|
|
|
|
|
|
|
|
Context->State = SNFMilterContext::Connect; // Update context state.
|
|
|
|
|
|
|
@@ -754,8 +763,8 @@ extern "C" { |
|
|
|
// is scanned.
|
|
|
|
//
|
|
|
|
// Returns: SMFIS_CONTINUE if more of the message body is needed,
|
|
|
|
// Context->SkipReturn if more of the message body is not needed,
|
|
|
|
// or FailSafeMilterResponse if an error occurs. Context is the
|
|
|
|
// SkipReturn if more of the message body is not needed, or
|
|
|
|
// FailSafeMilterResponse if an error occurs. Context is the
|
|
|
|
// connection context object.
|
|
|
|
//
|
|
|
|
sfsistat
|
|
|
@@ -775,7 +784,7 @@ extern "C" { |
|
|
|
if (Context->MessageData.MessageBuffer.size() >= // Return if there is enough in the
|
|
|
|
MailBufferReserveSize) { // message buffer.
|
|
|
|
|
|
|
|
return Context->SkipReturn;
|
|
|
|
return SkipReturn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
@@ -1167,20 +1176,11 @@ extern "C" { |
|
|
|
sfsistat CallbackResult = SMFIS_ALL_OPTS;
|
|
|
|
|
|
|
|
try {
|
|
|
|
SNFMilterContext *Context = (SNFMilterContext *) smfi_getpriv(Ctx); // Get the context object.
|
|
|
|
if (0 == Context) {
|
|
|
|
Context = MilterContexts->grab(); // Get a context object.
|
|
|
|
if(0 == Context) // Check address.
|
|
|
|
throw runtime_error("Got NULL from MilterContexts->grab()");
|
|
|
|
smfi_setpriv(Ctx, Context); // Save the context object.
|
|
|
|
Context->ConnectionData.clear(); // Clear the connection context object.
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AcceptsSkip = F1 & SMFIP_SKIP;
|
|
|
|
if (AcceptsSkip) { // MTA accepts SMFIS_SKIP return?
|
|
|
|
Context->SkipReturn = SMFIS_SKIP; // Yes. Use SMFIS_SKIP.
|
|
|
|
SkipReturn = SMFIS_SKIP; // Yes. Use SMFIS_SKIP.
|
|
|
|
} else {
|
|
|
|
Context->SkipReturn = SMFIS_CONTINUE; // No. Use SMFIS_CONTINUE.
|
|
|
|
SkipReturn = SMFIS_CONTINUE; // No. Use SMFIS_CONTINUE.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MilterDebugMode) {
|