Browse Source

Replace SNFMilterContext::SkipReturn with global variable SkipReturn

(in file SNFMilter.cpp).  Implemented assignContextToCtx to assign a
SNFMilterContext object.


git-svn-id: https://svn.microneil.com/svn/SNFMilter/trunk@7 2c985dca-31e6-41a4-b4a2-d8f5b7f8e074
master
adeniz 15 years ago
parent
commit
594aee75e5
3 changed files with 38 additions and 30 deletions
  1. 11
    0
      ChangeLog
  2. 27
    27
      SNFMilter.cpp
  3. 0
    3
      SNFMilter.hpp

+ 11
- 0
ChangeLog View File

2009-06-03 Alban Deniz <adeniz@skidmark.localdomain>

* SNFMilter.cpp: Added global variable SkipReturn. This replaces
SNFMilterContext::SkipReturn.
(assignContextToCtx): Implemented function.
(mlfi_connect): Invoke assignContextToCtx().
(mlfi_negotiate): Do not assign a SNFMilterContext object.

* SNFMilter.hpp (class SNFMilterContext): Removed member
SkipReturn.

2009-05-27 Alban Deniz <adeniz@skidmark.localdomain> 2009-05-27 Alban Deniz <adeniz@skidmark.localdomain>


* Makefile.am (EXTRA_DIST): Include ChangeLog. * Makefile.am (EXTRA_DIST): Include ChangeLog.

+ 27
- 27
SNFMilter.cpp View File

SNFMilterContextPool* MilterContexts = 0; // The global contexts handle. SNFMilterContextPool* MilterContexts = 0; // The global contexts handle.
bool MilterDebugMode; // True if debug mode is on. 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. /// Get the connection context object.
// //
return Context; 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. // Function to output an info message.
void logInfo(const string ContextName, int Code, std::string Message) { void logInfo(const string ContextName, int Code, std::string Message) {
cout << ContextName << " (code " << Code << "): " << Message << endl; cout << ContextName << " (code " << Code << "): " << Message << endl;
//// SNFMilterContext //// SNFMilterContext
SNFMilterContext::SNFMilterContext(snf_RulebaseHandler *myRulebase) : SNFMilterContext::SNFMilterContext(snf_RulebaseHandler *myRulebase) :
SkipReturn(SMFIS_CONTINUE),
milterEngine(myRulebase), milterEngine(myRulebase),
MessageData(MailBufferReserveSize) {} MessageData(MailBufferReserveSize) {}
sfsistat CallbackResult = FailSafeMilterResponse; sfsistat CallbackResult = FailSafeMilterResponse;
try { 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. Context->State = SNFMilterContext::Connect; // Update context state.
// is scanned. // is scanned.
// //
// Returns: SMFIS_CONTINUE if more of the message body is needed, // 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. // connection context object.
// //
sfsistat sfsistat
if (Context->MessageData.MessageBuffer.size() >= // Return if there is enough in the if (Context->MessageData.MessageBuffer.size() >= // Return if there is enough in the
MailBufferReserveSize) { // message buffer. MailBufferReserveSize) { // message buffer.
return Context->SkipReturn;
return SkipReturn;
} }
sfsistat CallbackResult = SMFIS_ALL_OPTS; sfsistat CallbackResult = SMFIS_ALL_OPTS;
try { 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; bool AcceptsSkip = F1 & SMFIP_SKIP;
if (AcceptsSkip) { // MTA accepts SMFIS_SKIP return? if (AcceptsSkip) { // MTA accepts SMFIS_SKIP return?
Context->SkipReturn = SMFIS_SKIP; // Yes. Use SMFIS_SKIP.
SkipReturn = SMFIS_SKIP; // Yes. Use SMFIS_SKIP.
} else { } else {
Context->SkipReturn = SMFIS_CONTINUE; // No. Use SMFIS_CONTINUE.
SkipReturn = SMFIS_CONTINUE; // No. Use SMFIS_CONTINUE.
} }
if (MilterDebugMode) { if (MilterDebugMode) {

+ 0
- 3
SNFMilter.hpp View File

SNFMilterContext(snf_RulebaseHandler *); SNFMilterContext(snf_RulebaseHandler *);
~SNFMilterContext(); ~SNFMilterContext();
sfsistat SkipReturn; // libmilter return value when further
// callbacks of the same type are to be skipped.
// Map the scan result to the libmilter return value. // Map the scan result to the libmilter return value.
sfsistat sfsistat
smfisReturn(SNFMilterAction); smfisReturn(SNFMilterAction);

Loading…
Cancel
Save