Commit c648084a authored by François Grisez's avatar François Grisez

EventLog: log the value of 'Priority' header of each event

parent 3f9d7d85
Pipeline #7025 passed with stages
in 40 minutes and 29 seconds
......@@ -41,6 +41,7 @@ public:
virtual ~EventLog();
void setCompleted();
void setStatusCode(int sip_status, const char *reason);
void setPriority(const std::string &priority) {mPriority = priority;}
bool isCompleted() const {
return mCompleted;
}
......@@ -48,14 +49,16 @@ public:
protected:
su_home_t mHome;
sip_from_t *mFrom;
sip_to_t *mTo;
sip_user_agent_t *mUA;
sip_from_t *mFrom = nullptr;
sip_to_t *mTo = nullptr;
sip_user_agent_t *mUA = nullptr;
time_t mDate;
int mStatusCode;
int mStatusCode = 0;
std::string mReason;
bool mCompleted;
bool mCompleted = false;
std::string mCallId;
std::string mPriority = "normal";
class Init {
public:
Init();
......
......@@ -52,9 +52,9 @@ class ForkMessageContext : public ForkContext {
static void sOnAcceptanceTimer(su_root_magic_t *magic, su_timer_t *t, su_timer_arg_t *arg);
void acceptMessage();
void onAcceptanceTimer();
void logReceivedFromUserEvent(const std::shared_ptr<ResponseSipEvent> &ev);
void logReceivedFromUserEvent(const std::shared_ptr<RequestSipEvent> &reqEv, const std::shared_ptr<ResponseSipEvent> &respEv);
void checkFinished();
void logDeliveredToUserEvent(const std::shared_ptr<BranchInfo> &br, const std::shared_ptr<ResponseSipEvent> &event);
void logDeliveredToUserEvent(const std::shared_ptr<RequestSipEvent> &reqEv, const std::shared_ptr<ResponseSipEvent> &respEv);
};
}
......@@ -29,6 +29,8 @@
#include <sstream>
#include <typeinfo>
#include "utils/string-utils.hh"
using namespace std;
using namespace flexisip;
......@@ -80,9 +82,6 @@ EventLog::EventLog(const sip_t *sip) {
mUA = sip->sip_user_agent ? sip_user_agent_dup(&mHome, sip->sip_user_agent) : NULL;
mCallId = sip->sip_call_id->i_id;
mStatusCode = 0;
mCompleted = false;
}
EventLog::~EventLog() {
......@@ -688,11 +687,23 @@ void DataBaseEventLogWriter::initTables(soci::session *session, Backend backend)
" reason VARCHAR(255) NOT NULL,"
" completed CHAR(1) NOT NULL,"
" call_id VARCHAR(255) NOT NULL,"
" FOREIGN KEY (type_id)"
" REFERENCES event_type(id)"
")" + tableOptions;
// Schema migration #1: add 'priority' column to event_log
*session << "DROP PROCEDURE IF EXISTS add_priority_column_to_event_log_table";
*session <<
"CREATE PROCEDURE add_priority_column_to_event_log_table()"
"BEGIN"
" IF NOT EXISTS ((SELECT * FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='event_log' AND column_name='priority')) THEN"
" ALTER TABLE event_log ADD COLUMN priority VARCHAR(255) NOT NULL DEFAULT 'normal';"
" END IF;"
"END";
*session << "CALL add_priority_column_to_event_log_table()";
*session << "DROP PROCEDURE IF EXISTS add_priority_column_to_event_log_table";
// Specialized events table.
*session <<
"CREATE TABLE IF NOT EXISTS event_registration_log ("
......@@ -791,11 +802,11 @@ void DataBaseEventLogWriter::writeEventLog(soci::session *session, const std::sh
string completed(boolToSqlString(evlog->mCompleted));
*session << "INSERT INTO event_log "
"(type_id, sip_from, sip_to, user_agent, date, status_code, reason, completed, call_id)"
"VALUES (:typeId, :sipFrom, :sipTo, :userAgent, :date, :statusCode, :reason, :completed, :callId)",
"(type_id, sip_from, sip_to, user_agent, date, status_code, reason, completed, call_id, priority)"
"VALUES (:typeId, :sipFrom, :sipTo, :userAgent, :date, :statusCode, :reason, :completed, :callId, :priority)",
soci::use(typeId), soci::use(from), soci::use(to),
soci::use(ua), soci::use(*gmtime_r(&evlog->mDate, &date)), soci::use(evlog->mStatusCode),
soci::use(evlog->mReason), soci::use(completed), soci::use(evlog->mCallId);
soci::use(evlog->mReason), soci::use(completed), soci::use(evlog->mCallId), soci::use(evlog->mPriority);
}
// IMPORTANT
......
......@@ -90,15 +90,19 @@ void ForkMessageContext::checkFinished() {
}
}
void ForkMessageContext::logDeliveredToUserEvent(const std::shared_ptr<BranchInfo> &br,
const shared_ptr<ResponseSipEvent> &event) {
sip_t *sip = event->getMsgSip()->getSip();
void ForkMessageContext::logDeliveredToUserEvent(const std::shared_ptr<RequestSipEvent> &reqEv,
const shared_ptr<ResponseSipEvent> &respEv) {
sip_t *sip = respEv->getMsgSip()->getSip();
const sip_t *sipRequest = reqEv->getMsgSip()->getSip();
auto log = make_shared<MessageLog>(sip, MessageLog::DeliveredToUser);
log->setDestination(br->mRequest->getMsgSip()->getSip()->sip_request->rq_url);
log->setDestination(sipRequest->sip_request->rq_url);
log->setStatusCode(sip->sip_status->st_status, sip->sip_status->st_phrase);
if (sipRequest->sip_priority && sipRequest->sip_priority->g_string) {
log->setPriority(sipRequest->sip_priority->g_string);
}
log->setCompleted();
event->setEventLog(log);
event->flushLog();
respEv->setEventLog(log);
respEv->flushLog();
}
void ForkMessageContext::onResponse(const std::shared_ptr<BranchInfo> &br, const shared_ptr<ResponseSipEvent> &event) {
......@@ -111,33 +115,37 @@ void ForkMessageContext::onResponse(const std::shared_ptr<BranchInfo> &br, const
mDeliveredCount++;
if (mAcceptanceTimer) {
if (mIncoming && mIsMessage)
logReceivedFromUserEvent(event); /*in the sender's log will appear the status code from the receiver*/
logReceivedFromUserEvent(mEvent, event); /*in the sender's log will appear the status code from the receiver*/
su_timer_destroy(mAcceptanceTimer);
mAcceptanceTimer = NULL;
}
}
if (mIsMessage)
logDeliveredToUserEvent(br, event);
logDeliveredToUserEvent(br->mRequest, event);
forwardResponse(br);
} else if (code >= 300 && !mCfg->mForkLate && isUrgent(code, sUrgentCodes)){
/*expedite back any urgent replies if late forking is disabled */
if (mIsMessage)
logDeliveredToUserEvent(br, event);
logDeliveredToUserEvent(br->mRequest, event);
forwardResponse(br);
} else {
if (mIsMessage)
logDeliveredToUserEvent(br, event);
logDeliveredToUserEvent(br->mRequest, event);
}
checkFinished();
}
void ForkMessageContext::logReceivedFromUserEvent(const shared_ptr<ResponseSipEvent> &ev) {
sip_t *sip = ev->getMsgSip()->getSip();
void ForkMessageContext::logReceivedFromUserEvent(const std::shared_ptr<RequestSipEvent> &reqEv, const shared_ptr<ResponseSipEvent> &respEv) {
sip_t *sip = respEv->getMsgSip()->getSip();
const sip_t *sipRequest = reqEv->getMsgSip()->getSip();
auto log = make_shared<MessageLog>(sip, MessageLog::ReceivedFromUser);
log->setStatusCode(sip->sip_status->st_status, sip->sip_status->st_phrase);
if (sipRequest->sip_priority && sipRequest->sip_priority->g_string) {
log->setPriority(sipRequest->sip_priority->g_string);
}
log->setCompleted();
ev->setEventLog(log);
ev->flushLog();
respEv->setEventLog(log);
respEv->flushLog();
}
/*we are called here if no good response has been received from any branch, in fork-late mode only */
......@@ -151,7 +159,7 @@ void ForkMessageContext::acceptMessage() {
new ResponseSipEvent(dynamic_pointer_cast<OutgoingAgent>(mAgent->shared_from_this()), msgsip));
forwardResponse(ev);
if (mIsMessage)
logReceivedFromUserEvent(ev); /*in the sender's log will appear the 202 accepted from flexisip server*/
logReceivedFromUserEvent(mEvent, ev); /*in the sender's log will appear the 202 accepted from flexisip server*/
}
void ForkMessageContext::onAcceptanceTimer() {
......
......@@ -55,6 +55,26 @@ void StringUtils::strip(std::string::const_iterator &start, std::string::const_i
end--;
}
std::string StringUtils::stripAll(const char *str, char c) {
const char *start = str;
const char *end = index(str, '\0');
while (end > start && *end == c) end--;
while (end > start && *start == c) start++;
return string(start, end-start);
}
std::string StringUtils::stripAll(const std::string &str, char c) {
auto start = str.cbegin();
auto end = str.cend();
stripAll(start, end, c);
return string(start, end);
}
void StringUtils::stripAll(std::string::const_iterator &start, std::string::const_iterator &end, char c) {
while (end > start && *(end-1) == c) end--;
while (end > start && *start == c) start++;
}
std::string StringUtils::removePrefix(const std::string &str, const std::string &prefix) {
if (str.compare(0, prefix.size(), prefix) != 0) {
ostringstream os;
......
......@@ -33,6 +33,10 @@ public:
static std::string strip(const std::string &str, char c);
static void strip(std::string::const_iterator &start, std::string::const_iterator &end, char c);
static std::string stripAll(const char *str, char c = ' ');
static std::string stripAll(const std::string &str, char c = ' ');
static void stripAll(std::string::const_iterator &start, std::string::const_iterator &end, char c = ' ');
/**
* @brief Check whether the string 'str' starts with 'prefix' and returned the subsequent
* part of the string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment