// Do preliminary processing of message to log it, // clean up its data, and extract any needed source address. void SipClient::preprocessMessage(SipMessage& msg, const UtlString& msgText, int msgLength) { // Canonicalize short field names. msg.replaceShortFieldNames(); // Get the send address. UtlString fromIpAddress; int fromPort; msg.getSendAddress(&fromIpAddress, &fromPort); // Log the message. // Only bother processing if the logs are enabled if ( mpSipUserAgent->isMessageLoggingEnabled() || Os::Logger::instance().willLog(FAC_SIP_INCOMING, PRI_INFO) ) { UtlString logMessage; logMessage.append("Read SIP message:\n"); logMessage.append("----Local Host:"); logMessage.append(mLocalHostAddress); logMessage.append("---- Port: "); logMessage.appendNumber( portIsValid(mLocalHostPort) ? mLocalHostPort : defaultPort()); logMessage.append("----\n"); logMessage.append("----Remote Host:"); logMessage.append(fromIpAddress); logMessage.append("---- Port: "); logMessage.appendNumber( portIsValid(fromPort) ? fromPort : defaultPort()); logMessage.append("----\n"); logMessage.append(msgText.data(), msgLength); UtlString messageString; logMessage.append(messageString); logMessage.append("====================END====================\n"); // Send the message to the SipUserAgent for its internal log. mpSipUserAgent->logMessage(logMessage.data(), logMessage.length()); // Write the message to the syslog. Os::Logger::instance().log(FAC_SIP_INCOMING, PRI_INFO, "%s", logMessage.data()); } // Set the date field if not present long epochDate; if (!msg.getDateField(&epochDate)) { msg.setDateField(); } // Set the protocol and time. msg.setSendProtocol(mSocketType); msg.setTransportTime(touchedTime); // Keep track of where this message came from msg.setSendAddress(fromIpAddress.data(), fromPort); // Keep track of the interface on which this message was // received. msg.setInterfaceIpPort(mClientSocket->getLocalIp(), mClientSocket->getLocalHostPort()); if (mReceivedAddress.isNull()) { mReceivedAddress = fromIpAddress; mRemoteReceivedPort = fromPort; } // If this is a request... if (!msg.isResponse()) { UtlString lastAddress; int lastPort; UtlString lastProtocol; int receivedPort; UtlBoolean receivedSet; UtlBoolean maddrSet; UtlBoolean receivedPortSet; // Fill in 'received' and 'rport' in top Via if needed. msg.setReceivedViaParams(fromIpAddress, fromPort); // Derive information about the other end of the connection // from the Via that the other end provided. // Get the addresses from the topmost Via. msg.getTopVia(&lastAddress, &lastPort, &lastProtocol, &receivedPort, &receivedSet, &maddrSet, &receivedPortSet); // :QUERY: Should this test be mClientSocket->isConnected()? if ( ( mSocketType == OsSocket::TCP || mSocketType == OsSocket::SSL_SOCKET ) && !receivedPortSet ) { // we can use this socket as if it were // connected to the port specified in the // via field mRemoteReceivedPort = lastPort; } // Keep track of the address the other // side said they sent from. Note, this cannot // be trusted unless this transaction is // authenticated if (mRemoteViaAddress.isNull()) { mRemoteViaAddress = lastAddress; mRemoteViaPort = portIsValid(lastPort) ? lastPort : defaultPort(); } } // // Call all sip input processors // system_tap_sip_rx(fromIpAddress.data(), portIsValid(fromPort) ? fromPort : defaultPort(), mLocalHostAddress.data(), portIsValid(mLocalHostPort) ? mLocalHostPort : defaultPort(), msgText.data(), msgLength); mpSipUserAgent->executeAllSipInputProcessors(msg, fromIpAddress.data(), portIsValid(fromPort) ? fromPort : defaultPort()); }