static int ApplyFilters(const uint8_t* alpha, int width, int height, uint64_t data_size, int method, int filter, int reduce_levels, int effort_level, uint8_t** const output, size_t* const output_size, WebPAuxStats* const stats) { int ok = 1; uint8_t* filtered_alpha = NULL; uint32_t try_map = GetFilterMap(alpha, width, height, filter, effort_level); filtered_alpha = (uint8_t*)malloc(data_size); ok = (filtered_alpha != NULL); if (ok) { FilterTrial best; InitFilterTrial(&best); for (filter = WEBP_FILTER_NONE; try_map; ++filter, try_map >>= 1) { if (try_map & 1) { FilterTrial trial; ok = EncodeAlphaInternal(alpha, width, height, method, filter, reduce_levels, effort_level, filtered_alpha, &trial.bw, stats); if (ok) { trial.score = VP8BitWriterSize(&trial.bw); if (trial.score < best.score) { VP8BitWriterWipeOut(&best.bw); best = trial; if (stats != NULL) best.stats = *stats; } else { VP8BitWriterWipeOut(&trial.bw); } } else { VP8BitWriterWipeOut(&trial.bw); VP8BitWriterWipeOut(&best.bw); break; } } } if (ok) { if (stats != NULL) *stats = best.stats; *output_size = VP8BitWriterSize(&best.bw); *output = VP8BitWriterBuf(&best.bw); } free(filtered_alpha); } return ok; }
bool DistributedLogManager::kafka_log(Trade::TradeLog log) { /* { "logType":"trade", //日志类型。'trade':交易日志 "message":{ "logLevel":"warn", //日志级别 "request":"", //交易请求。 "requestTime":"2012-05-10 13:00:00", //请求时间点 "requestRuntime":"", //请求耗时。单位:毫秒 "status":"0", //交易状态。1:成功;0:失败 "response":"", //交易请求响应。 "sourceSysNo":"njzq_jlp", //交易请求来源系统编号 "sourceSysVer":"iphone", //交易请求来源系统版本 "counterIp":"", //柜台IP "counterPort":"", //柜台端口 "gatewayIp":"", //交易网关IP "gatewayPort":"" //交易网关端口 } } */ std::string json; json = "{"; std::string SOH = "\x01"; std::string funcid = log.funcid(); // 心跳不记录 if (funcid == "999999") { // delete log; return true; } std::string countertype = log.countertype(); // 恒生t2 if (countertype == "1") { // 如果启用了过滤查询功能号 if (gConfigManager::instance().m_nFilterFuncId) { std::map<std::string, FUNCTION_DESC>::iterator it = m_mT2_FilterFunc.find(funcid); if (it != m_mT2_FilterFunc.end()) { // 过滤查询功能号 if (it->second.isQuery) { //log.destroy(); //delete log; return true; } } } } // 金证 if (countertype == "3") { // 如果启用了过滤查询功能号 if (gConfigManager::instance().m_nFilterFuncId) { std::map<std::string, FUNCTION_DESC>::iterator it = m_mKingdom_FilterFunc.find(funcid); if (it != m_mKingdom_FilterFunc.end()) { // 过滤查询功能号 if (it->second.isQuery) { //log.destroy(); //delete log; return true; } } } } // 顶点 if (countertype == "5") { // 如果启用了过滤查询功能号 if (gConfigManager::instance().m_nFilterFuncId) { std::map<std::string, FUNCTION_DESC>::iterator it = m_mDingDian_FilterFunc.find(funcid); if (it != m_mDingDian_FilterFunc.end()) { // 过滤查询功能号 if (it->second.isQuery) { //log.destroy(); delete this; return true; } } } } std::string request = log.request(); std::map<std::string, std::string> reqmap; // 过滤字段 if (countertype == "1") { GetFilterMap(request, m_mT2_FilterField, reqmap); } else if (countertype == "3") { GetFilterMap(request, m_mKingdom_FilterField, reqmap); } else if (countertype == "5") { GetFilterMap(request, m_mDingDian_FilterField, reqmap); } std::string sFilterRequest = ""; for (std::map<std::string, std::string>::iterator it = reqmap.begin(); it != reqmap.end(); it++) { sFilterRequest += it->first; sFilterRequest += "="; sFilterRequest += it->second; sFilterRequest += SOH; } if (sFilterRequest.empty()) sFilterRequest = request; json += "\"request\":\""; std::string b64Request = ""; g_MyBotan.Base64Encoder((const unsigned char*) sFilterRequest.c_str(), sFilterRequest.length(), b64Request); json += b64Request; json += "\","; std::string sysNo = log.sysno(); if (sysNo.empty()) sysNo = "no_sysno"; json += "\"sourceSysNo\":\""; json += sysNo; json += "\","; std::string sysVer = log.sysver(); if (sysVer.empty()) sysVer = "no_sysver"; json += "\"sourceSysVer\":\""; json += sysVer; json += "\","; std::string busiType = log.busitype(); if (busiType.empty()) busiType = "no_busitype"; json += "\"busiType\":\""; json += busiType; json += "\","; // 账户和日志级别 //std::string account = logMsg.account(); //if (account.empty()) // sLogFileName += "no_account"; //else // sLogFileName += account; json += "\"logLevel\":\""; switch (log.level()) { case Trade::TradeLog::DEBUG_LEVEL: json += "debug"; break; case Trade::TradeLog::INFO_LEVEL: json += "info"; break; case Trade::TradeLog::WARN_LEVEL: json += "warn"; break; case Trade::TradeLog::ERROR_LEVEL: json += "error"; break; default: json += "error"; } json += "\","; json += "\"requestTime\":\""; json += log.recvtime(); json += "\","; json += "\"requestRuntime\":\""; json += boost::lexical_cast<std::string>(log.runtime()/1000); json += "\","; json += "\"status\":\""; json += boost::lexical_cast<std::string>(log.status()); json += "\","; json += "\"response\":\""; std::string b64Response = ""; g_MyBotan.Base64Encoder((const unsigned char*) log.response().c_str(), log.response().length(), b64Response); json += b64Response; json += "\","; json += "\"counterIp\":\""; json += log.gtip(); json += "\","; json += "\"counterPort\":\""; json += log.gtport(); json += "\","; json += "\"gatewayIp\":\""; json += log.gatewayip(); json += "\","; json += "\"gatewayPort\":\""; json += log.gatewayport(); json += "\""; // 注意:最后没有逗号 json += "}"; LogConnect * pConnect = gLogConnectPool::instance().GetConnect(); if (pConnect == NULL) { gFileLog::instance().Log(json, 0, "写分布式日志失败"); } else { int retry = 1; for (int i=0; i <= retry; i++) { std::string response = ""; if (pConnect->Send(json, response)) { // 归还连接 gLogConnectPool::instance().PushConnect(pConnect); break; } else { if (pConnect->ReConnect()) { continue; } else { delete pConnect; // 不归还连接,需要释放 gFileLog::instance().Log(json, 0, "写分布式日志失败"); break; } } }//end for retry } // end if // 释放 //log.destroy(); //delete log; return true; }