QoreHashNode* qore_httpclient_priv::sendMessageAndGetResponse(const char* meth, const char* mpath, const QoreHashNode& nh, const void* data, unsigned size, const ResolvedCallReferenceNode* send_callback, QoreHashNode* info, bool with_connect, int timeout_ms, int& code, bool& aborted, ExceptionSink* xsink) { QoreString pathstr(msock->socket->getEncoding()); const char* msgpath = with_connect ? mpath : getMsgPath(mpath, pathstr); if (!connected) { if (persistent) { xsink->raiseException("PERSISTENCE-ERROR", "the current connection has been temporarily marked as persistent, but has been disconnected"); return 0; } if (connect_unlocked(xsink)) { // if we have an info hash then write the request-uri key for reporting/logging purposes if (info) info->setKeyValue("request-uri", new QoreStringNodeMaker("%s %s HTTP/%s", meth, msgpath && msgpath[0] ? msgpath : "/", http11 ? "1.1" : "1.0"), 0); return 0; } } // send the message int rc = msock->socket->priv->sendHttpMessage(xsink, info, meth, msgpath, http11 ? "1.1" : "1.0", &nh, data, size, send_callback, QORE_SOURCE_HTTPCLIENT, timeout_ms, &msock->m, &aborted); //sendHTTPMessage(xsink, info, meth, msgpath, http11 ? "1.1" : "1.0", &nh, data, size, QORE_SOURCE_HTTPCLIENT, timeout_ms); if (rc) { assert(*xsink); if (rc == QSE_NOT_OPEN) disconnect_unlocked(); return 0; } QoreHashNode* ah = 0; while (true) { ReferenceHolder<QoreHashNode> ans(msock->socket->readHTTPHeader(xsink, info, timeout, QORE_SOURCE_HTTPCLIENT), xsink); if (!(*ans)) { disconnect_unlocked(); assert(*xsink); return 0; } // check HTTP status code AbstractQoreNode* v = ans->getKeyValue("status_code"); if (!v) { xsink->raiseException("HTTP-CLIENT-RECEIVE-ERROR", "no HTTP status code received in response"); return 0; } code = v->getAsInt(); // continue processing if "100 Continue" response received (ignore this response) if (code == 100) continue; ah = ans.release(); break; } return ah; }
INT4 CPortEventReportor::report(CSmartPtr<CSwitch> sw, UINT4 port_no, INT4 event, INT4 reason, INT4 type, INT4 state, INT4 stateNew) { if (sw.isNull()) return BNC_ERR; if ((EVENT_TYPE_PORT_DOWN < event) || (EVENT_TYPE_PORT_UP > event)) return BNC_ERR; if ((PORT_EVENT_DELETE < type) || (PORT_EVENT_ADD > type)) return BNC_ERR; CPortEvent* evt = new CPortEvent(event, reason, type, sw->getSockfd(), sw->getDpid(), port_no); if (NULL == evt) { LOG_ERROR_FMT("new CPortEvent failed[%d]!", errno); return BNC_ERR; } CMsgPath path = getMsgPath(event); evt->setPath(path); CMsgKey key = getMsgKey(sw->getDpid(), port_no); evt->setKey(key); evt->setState(state); evt->setStateNew(stateNew); INT1 descStr[1024]; if (PORT_EVENT_ADD == type) snprintf(descStr, sizeof(descStr), "Reported event[0x%x][%s] with reason[0x%x] on switch[%llx], port[%u] with state[%d] added", event, path.c_str(), reason, sw->getDpid(), port_no, stateNew); else if (PORT_EVENT_MODIFY == type) snprintf(descStr, sizeof(descStr), "Reported event[0x%x][%s] with reason[0x%x] on switch[%llx], " "state of port[%u] changed from %d to %d, when %s happened", event, path.c_str(), reason, sw->getDpid(), port_no, state, stateNew, g_eventTypeString[type]); else if (PORT_EVENT_DELETE == type) snprintf(descStr, sizeof(descStr), "Reported event[0x%x][%s] with reason[0x%x] on switch[%llx], port[%u] with state[%d] deleted", event, path.c_str(), reason, sw->getDpid(), port_no, state); LOG_WARN(descStr); CEventDesc desc(descStr); evt->setDesc(desc); return CEventReportor::report(evt); }
INT4 CTagFlowEventReportor::report(INT4 event, INT4 reason, UINT8 srcDpid, UINT4 outport, UINT8 dstDpid, UINT4 inport) { if (!((EVENT_TYPE_TAG_FLOW_ADD <= event) && (EVENT_TYPE_TAG_FLOW_ADD >= event))) return BNC_ERR; CTagFlowEvent* evt = new CTagFlowEvent(event, reason, srcDpid, outport, dstDpid, inport); if (NULL == evt) { LOG_ERROR_FMT("new CTagFlowEvent failed[%d]!", errno); return BNC_ERR; } CMsgPath path = getMsgPath(event); evt->setPath(path); return CEventReportor::report(evt); }
INT4 CTagFlowEventReportor::report(INT4 event, INT4 reason, std::list<sw_tagflow_t*> & tagflow_list) { if (!((EVENT_TYPE_TAG_FLOW_ADD <= event) && (EVENT_TYPE_TAG_FLOW_ADD >= event))) return BNC_ERR; CTagFlowEvent* evt = new CTagFlowEvent(event, reason, tagflow_list); if (NULL == evt) { LOG_ERROR_FMT("new CTagFlowEvent failed[%d]!", errno); return BNC_ERR; } CMsgPath path = getMsgPath(event); evt->setPath(path); return CEventReportor::report(evt); }
INT4 CPortforwardEventReportor::report(INT4 event, INT4 reason, const CPortforwardRule& rule) { if (!((EVENT_TYPE_PORTFORWARD_RULE_C <= event) && (EVENT_TYPE_PORTFORWARD_RULE_DS >= event))) return BNC_ERR; CPortforwardEvent* evt = new CPortforwardEvent(event, reason, rule); if (NULL == evt) { LOG_ERROR_FMT("new CPortforwardEvent failed!"); return BNC_ERR; } CMsgPath path = getMsgPath(event); evt->setPath(path); INT1 outIpStr[20] = {0}, inIpStr[20] = {0}; number2ip(htonl(rule.getOutsideIp()), outIpStr); number2ip(htonl(rule.getInsideIp()), inIpStr); UINT2 outPortStart = 0, outPortEnd = 0, inPortStart = 0, inPortEnd = 0; rule.getOutsidePort(outPortStart, outPortEnd); rule.getInsidePort(inPortStart, inPortEnd); INT1 descStr[1024]; snprintf(descStr, sizeof(descStr), "Reported event[0x%x][%s] with reason[0x%x], %s portforward rule" "(%s,protocol[%d],outIp[%s],inIp[%s],outPort[%u-%u],inPort[%u-%u],networkId[%s],subnetId[%s])", event, path.c_str(), reason, (EVENT_TYPE_PORTFORWARD_RULE_C==event)?"CREATED": (EVENT_TYPE_PORTFORWARD_RULE_U==event)?"UPDATED": (EVENT_TYPE_PORTFORWARD_RULE_D==event)?"DELETED":"UNKNOWN", rule.getEnabled()?"enabled":"disabled", rule.getProtocol(), outIpStr, inIpStr, outPortStart, outPortEnd, inPortStart, inPortEnd, rule.getNetworkId().c_str(), rule.getSubnetId().c_str()); //LOG_WARN(descStr); CEventDesc desc(descStr); evt->setDesc(desc); return CEventReportor::report(evt); }