diff --git a/esp/services/ws_logaccess/WsLogAccessService.cpp b/esp/services/ws_logaccess/WsLogAccessService.cpp index 98e4a98ad90..0e9100337fc 100644 --- a/esp/services/ws_logaccess/WsLogAccessService.cpp +++ b/esp/services/ws_logaccess/WsLogAccessService.cpp @@ -208,10 +208,10 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter) if (!binaryfilter) return nullptr; - ILogAccessFilter * leftFilter = nullptr; + Owned leftFilter; if (binaryfilter->getLeftBinaryFilter().ordinality() == 0) { - leftFilter = buildLogFilter(&binaryfilter->getLeftFilter()); + leftFilter.setown(buildLogFilter(&binaryfilter->getLeftFilter())); } else { @@ -221,7 +221,7 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter) if (!isLogFilterEmpty(&binaryfilter->getLeftFilter())) throw makeStringException(-1, "WsLogAccess: Cannot submit leftFilter and leftBinaryFilter!"); - leftFilter = buildBinaryLogFilter(&binaryfilter->getLeftBinaryFilter().item(0)); + leftFilter.setown(buildBinaryLogFilter(&binaryfilter->getLeftBinaryFilter().item(0))); } if (!leftFilter) @@ -233,14 +233,14 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter) case LogAccessFilterOperator_Undefined: //no operator found //if (rightFilter != nullptr) // WARNLOG("right FILTER ENCOUNTERED but no valid operator"); - return leftFilter; + return leftFilter.getClear(); case CLogAccessFilterOperator_AND: case CLogAccessFilterOperator_OR: { - ILogAccessFilter * rightFilter = nullptr; + Owned rightFilter; if (binaryfilter->getRightBinaryFilter().ordinality() == 0) { - rightFilter = buildLogFilter(&binaryfilter->getRightFilter()); + rightFilter.setown(buildLogFilter(&binaryfilter->getRightFilter())); } else { @@ -250,13 +250,13 @@ ILogAccessFilter * buildBinaryLogFilter(IConstBinaryLogFilter * binaryfilter) if (!isLogFilterEmpty(&binaryfilter->getRightFilter())) throw makeStringException(-1, "WsLogAccess: Cannot submit rightFilter and rightBinaryFilter!"); - rightFilter = buildBinaryLogFilter(&binaryfilter->getRightBinaryFilter().item(0)); + rightFilter.setown(buildBinaryLogFilter(&binaryfilter->getRightBinaryFilter().item(0))); } if (!rightFilter) throw makeStringExceptionV(-1, "WsLogAccess: Empty RIGHT filter encountered"); - return getBinaryLogAccessFilterOwn(leftFilter, rightFilter, cLogAccessFilterOperator2LogAccessFilterType(binaryfilter->getOperator())); + return getBinaryLogAccessFilter(leftFilter, rightFilter, cLogAccessFilterOperator2LogAccessFilterType(binaryfilter->getOperator())); } default: diff --git a/esp/services/ws_workunits/ws_workunitsHelpers.cpp b/esp/services/ws_workunits/ws_workunitsHelpers.cpp index 1fb3a8fc9de..f1dfb7fbeb8 100644 --- a/esp/services/ws_workunits/ws_workunitsHelpers.cpp +++ b/esp/services/ws_workunits/ws_workunitsHelpers.cpp @@ -4270,9 +4270,9 @@ void CWsWuFileHelper::readWULogToFiles(IConstWorkUnit *cwu, WsWuInfo &winfo, con ForEach(*iter) { const char *processName = iter->query().queryProp("@podName"); - Owned processLogFetchFilter(logFetchFilter.getLink()); // retain original for next iteration - compoundOwnedFilter(processLogFetchFilter, getPodLogAccessFilter(processName), LOGACCESS_FILTER_and); - zapLogFilterOptions.logFilter.logFetchOptions.setFilter(processLogFetchFilter.getClear()); + Owned podFilter(getPodLogAccessFilter(processName)); + Owned compoundFilter(getCompoundLogAccessFilter(logFetchFilter, podFilter, LOGACCESS_FILTER_and)); + zapLogFilterOptions.logFilter.logFetchOptions.setFilter(compoundFilter.getClear()); VStringBuffer processLog("%s%c%s-%s-log.%s", path, PATHSEPCHAR, wuid, processName, logfileextension.str()); readWULogToFile(processLog, winfo, zapLogFilterOptions); diff --git a/esp/services/ws_workunits/ws_workunitsHelpers.hpp b/esp/services/ws_workunits/ws_workunitsHelpers.hpp index e9c15171142..dbfdae6b733 100644 --- a/esp/services/ws_workunits/ws_workunitsHelpers.hpp +++ b/esp/services/ws_workunits/ws_workunitsHelpers.hpp @@ -255,18 +255,25 @@ struct WUComponentLogOptions { StringArray componentsFilter; componentsFilter.appendList(componentsFilterList.str(), ","); - compoundOwnedFilter(logFetchFilter, getOredComponentsLogFilter(componentsFilter), LOGACCESS_FILTER_and); + Owned filterClause = getOredComponentsLogFilter(componentsFilter); + logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and)); } StringBuffer logType; //"DIS","ERR","WRN","INF","PRO","MET","EVT","ALL" zapHttpRequest->getParameter("LogFilter_LogEventType", logType); if (!logType.isEmpty() && strcmp(logType.str(), "ALL") != 0) - compoundOwnedFilter(logFetchFilter, getClassLogAccessFilter(LogMsgClassFromAbbrev(logType.str())), LOGACCESS_FILTER_and); + { + Owned filterClause(getClassLogAccessFilter(LogMsgClassFromAbbrev(logType.str()))); + logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and)); + } StringBuffer wildCharFilter; zapHttpRequest->getParameter("LogFilter_WildcardFilter", wildCharFilter); if (!wildCharFilter.isEmpty()) - compoundOwnedFilter(logFetchFilter, getWildCardLogAccessFilter(wildCharFilter), LOGACCESS_FILTER_or); + { + Owned filterClause(getWildCardLogAccessFilter(wildCharFilter.str())); + logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_or)); + } logFetchOptions.setFilter(logFetchFilter.getClear()); @@ -326,15 +333,24 @@ struct WUComponentLogOptions logFetchOptions.setStartFrom(logFilterReq.getLineStartFrom()); if (logFilterReq.getComponentsFilter().length() > 0) - compoundOwnedFilter(logFetchFilter, getOredComponentsLogFilter(logFilterReq.getComponentsFilter()), LOGACCESS_FILTER_and); + { + Owned filterClause = getOredComponentsLogFilter(logFilterReq.getComponentsFilter()); + logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and)); + } const char * logType = logFilterReq.getLogEventTypeAsString(); if (!isEmptyString(logType) && strcmp(logType,"ALL") != 0) - compoundOwnedFilter(logFetchFilter, getClassLogAccessFilter(LogMsgClassFromAbbrev(logType)), LOGACCESS_FILTER_and); + { + Owned filterClause(getClassLogAccessFilter(LogMsgClassFromAbbrev(logType))); + logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_and)); + } const char * wildCharFilter = logFilterReq.getWildcardFilter(); if (!isEmptyString(wildCharFilter)) - compoundOwnedFilter(logFetchFilter, getWildCardLogAccessFilter(wildCharFilter), LOGACCESS_FILTER_or); + { + Owned filterClause(getWildCardLogAccessFilter(wildCharFilter)); + logFetchFilter.setown(getCompoundLogAccessFilter(logFetchFilter, filterClause, LOGACCESS_FILTER_or)); + } logFetchOptions.setFilter(logFetchFilter.getClear()); CSortDirection espSortDirection = logFilterReq.getSortByTimeDirection(); diff --git a/system/jlib/jlog.cpp b/system/jlib/jlog.cpp index 9cadf318c79..fda54e65934 100644 --- a/system/jlib/jlog.cpp +++ b/system/jlib/jlog.cpp @@ -3158,12 +3158,13 @@ ILogAccessFilter * getBinaryLogAccessFilterOwn(ILogAccessFilter * arg1, ILogAcce return ret; } -void compoundOwnedFilter(Owned& compoundFilter, ILogAccessFilter* extension, LogAccessFilterType operation) +ILogAccessFilter* getCompoundLogAccessFilter(ILogAccessFilter* arg1, ILogAccessFilter* arg2, LogAccessFilterType type) { - if (!compoundFilter) - compoundFilter.setown(extension); - else if (extension) - compoundFilter.setown(getBinaryLogAccessFilterOwn(compoundFilter.getLink(), extension, operation)); + if (!arg1) + return LINK(arg2); + if (!arg2) + return LINK(arg1); + return getBinaryLogAccessFilter(arg1, arg2, type); } diff --git a/system/jlib/jlog.hpp b/system/jlib/jlog.hpp index 4d5380f2d89..25c826fa360 100644 --- a/system/jlib/jlog.hpp +++ b/system/jlib/jlog.hpp @@ -1705,26 +1705,11 @@ extern jlib_decl ILogAccessFilter * getAudienceLogAccessFilter(MessageAudience a extern jlib_decl ILogAccessFilter * getClassLogAccessFilter(LogMsgClass logclass); extern jlib_decl ILogAccessFilter * getBinaryLogAccessFilter(ILogAccessFilter * arg1, ILogAccessFilter * arg2, LogAccessFilterType type); extern jlib_decl ILogAccessFilter * getBinaryLogAccessFilterOwn(ILogAccessFilter * arg1, ILogAccessFilter * arg2, LogAccessFilterType type); +extern jlib_decl ILogAccessFilter * getCompoundLogAccessFilter(ILogAccessFilter * arg1, ILogAccessFilter * arg2, LogAccessFilterType type); extern jlib_decl ILogAccessFilter * getWildCardLogAccessFilter(); extern jlib_decl ILogAccessFilter * getWildCardLogAccessFilter(const char * wildcardfilter); extern jlib_decl ILogAccessFilter * getColumnLogAccessFilter(const char * columnName, const char * value); -/** - * @brief Logically combine a new filter with an existing compound filter. - * - * Given an existing filter, an extension filter is logically combined with it based on a - * requested logical operation. The existing filter is replaced by the combined filter. - * - * If the existing filter is NULL, it is assigned to the extension. If the extension is NULL, - * the existing filter is unchanged. - * - * @param compoundFilter The existing filter to be logically combined with the extension. - * @param extension The new filter to be logically combined with the existing filter. - * Ownership of the given reference is transferred to the function. - * @param operation The logical operation to be performed on the existing and new filters. - */ -extern jlib_decl void compoundOwnedFilter(Owned & compoundFilter, ILogAccessFilter * extension, LogAccessFilterType operation); - // Helper functions to actuate log access query extern jlib_decl bool fetchLog(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, ILogAccessFilter * filter, LogAccessTimeRange timeRange, const StringArray & cols, LogAccessLogFormat format, unsigned int & totalReceived, unsigned int & totalAvailable); extern jlib_decl bool fetchJobIDLog(LogQueryResultDetails & resultDetails, StringBuffer & returnbuf, IRemoteLogAccess & logAccess, const char *jobid, LogAccessTimeRange timeRange, StringArray & cols, LogAccessLogFormat format);