ResultCode Store::connection_test() { ResultCode rc = OK; // Check that we can connect to cassandra by getting a client. This logs in // and switches to the specified keyspace, so is a good test of whether // cassandra is working properly. TRC_STATUS("Starting store"); try { get_client(); release_client(); } catch(TTransportException te) { TRC_ERROR("Store caught TTransportException: %s", te.what()); rc = CONNECTION_ERROR; } catch(NotFoundException nfe) { TRC_ERROR("Store caught NotFoundException: %s", nfe.what()); rc = NOT_FOUND; } catch(...) { TRC_ERROR("Store caught unknown exception!"); rc = UNKNOWN_ERROR; } return rc; }
/************************************************************ * * Initialize the alarmModelTable table by defining its contents * and how it's structured */ int initialize_table_alarmModelTable(void) { netsnmp_table_registration_info *table_info; if (my_handler) { // LCOV_EXCL_START TRC_ERROR("initialize_table_alarmModelTable called again"); return SNMP_ERR_NOERROR; // LCOV_EXCL_STOP } memset(&cb, 0x00, sizeof(cb)); /** create the table structure itself */ table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); my_handler = netsnmp_create_handler_registration("alarmModelTable", netsnmp_table_array_helper_handler, alarmModelTable_oid, alarmModelTable_oid_len, HANDLER_CAN_RONLY); if (!my_handler || !table_info) { // LCOV_EXCL_START TRC_ERROR("malloc failed: initialize_table_alarmModelTable"); return SNMP_ERR_GENERR; // LCOV_EXCL_STOP } /* * Setting up the table's definition */ /** index: alarmListName */ netsnmp_table_helper_add_index(table_info, ASN_OCTET_STR); /** index: alarmModelIndex */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); /** index: alarmModelState */ netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED); table_info->min_column = alarmModelTable_COL_MIN; table_info->max_column = alarmModelTable_COL_MAX; /* * registering the table with the master agent */ cb.get_value = alarmModelTable_get_value; cb.container = netsnmp_container_find("alarmModelTable_primary:" "alarmModelTable:" "table_container"); cb.can_set = 0; DEBUGMSGTL(("initialize_table_alarmModelTable", "Registering as table array\n")); netsnmp_table_container_register(my_handler, table_info, &cb, cb.container, 1); return SNMP_ERR_NOERROR; }
HTTPCode HSSConnection::get_registration_data(const std::string& public_user_identity, std::string& regstate, std::map<std::string, Ifcs >& ifcs_map, std::vector<std::string>& associated_uris, std::deque<std::string>& ccfs, std::deque<std::string>& ecfs, SAS::TrailId trail) { Utils::StopWatch stopWatch; stopWatch.start(); SAS::Event event(trail, SASEvent::HTTP_HOMESTEAD_GET_REG, 0); event.add_var_param(public_user_identity); SAS::report_event(event); std::string path = "/impu/" + Utils::url_escape(public_user_identity) + "/reg-data"; TRC_DEBUG("Making Homestead request for %s", path.c_str()); rapidxml::xml_document<>* root_underlying_ptr = NULL; HTTPCode http_code = get_xml_object(path, root_underlying_ptr, trail); // Needs to be a shared pointer - multiple Ifcs objects will need a reference // to it, so we want to delete the underlying document when they all go out // of scope. std::shared_ptr<rapidxml::xml_document<> > root (root_underlying_ptr); unsigned long latency_us = 0; // Only accumulate the latency if we haven't already applied a // penalty if ((http_code != HTTP_SERVER_UNAVAILABLE) && (http_code != HTTP_GATEWAY_TIMEOUT) && (stopWatch.read(latency_us))) { _latency_tbl->accumulate(latency_us); _sar_latency_tbl->accumulate(latency_us); } if (http_code != HTTP_OK) { // If get_xml_object has returned a HTTP error code, we have either not found // the subscriber on the HSS or been unable to communicate with // the HSS successfully. In either case we should fail. TRC_ERROR("Could not get subscriber data from HSS"); return http_code; } // Return whether the XML was successfully decoded. The XML can be decoded and // not return any IFCs (when the subscriber isn't registered), so a successful // response shouldn't be taken as a guarantee of IFCs. std::vector<std::string> unused_aliases; return decode_homestead_xml(public_user_identity, root, regstate, ifcs_map, associated_uris, unused_aliases, ccfs, ecfs, true) ? HTTP_OK : HTTP_SERVER_ERROR; }
HTTPCode SubscriberManager::get_cached_default_id(const std::string& public_id, std::string& aor_id, HSSConnection::irs_info& irs_info, SAS::TrailId trail) { HTTPCode rc = get_cached_subscriber_state(public_id, irs_info, trail); if (rc != HTTP_OK) { TRC_DEBUG("Failed to get cached default ID for IMPU %s with return code %d", public_id.c_str(), rc); return rc; } // Get the aor_id from the associated URIs. if (!irs_info._associated_uris.get_default_impu(aor_id, false)) { TRC_ERROR("No Default ID in IRS for IMPU %s", public_id.c_str()); return HTTP_BAD_REQUEST; } return rc; }
/************************************************************ * * Create a new row context and initialize its oid index. */ alarmModelTable_context* alarmModelTable_create_row_context(char* name, unsigned long index, unsigned long state) { alarmModelTable_context* ctx = SNMP_MALLOC_TYPEDEF(alarmModelTable_context); if (!ctx) { // LCOV_EXCL_START TRC_ERROR("malloc failed: alarmModelTable_create_row_context"); return NULL; // LCOV_EXCL_STOP } if (alarmModelTable_index_to_oid(name, index, state, &ctx->_index) != SNMP_ERR_NOERROR) { // LCOV_EXCL_START if (ctx->_index.oids != NULL) { free(ctx->_index.oids); } free(ctx); return NULL; // LCOV_EXCL_STOP } return ctx; }
bool AlarmTableDefs::initialize(std::string& path) { std::map<unsigned int, unsigned int> dup_check; _key_to_def.clear(); bool rc = true; boost::filesystem::path p(path); if ((boost::filesystem::exists(p)) && (boost::filesystem::is_directory(p))) { boost::filesystem::directory_iterator dir_it(p); boost::filesystem::directory_iterator end_it; while ((dir_it != end_it) && (rc)) { if ((boost::filesystem::is_regular_file(dir_it->status())) && (dir_it->path().extension() == ".json")) { rc = populate_map(dir_it->path().c_str(), dup_check); } dir_it++; } } else { TRC_ERROR("Unable to open directory at %s", path.c_str()); rc = false; } return rc; }
/// Get an Authentication Vector as JSON object. Caller is responsible for deleting. HTTPCode HSSConnection::get_auth_vector(const std::string& private_user_identity, const std::string& public_user_identity, const std::string& auth_type, const std::string& resync_auth, rapidjson::Document*& av, SAS::TrailId trail) { Utils::StopWatch stopWatch; stopWatch.start(); SAS::Event event(trail, SASEvent::HTTP_HOMESTEAD_VECTOR, 0); event.add_var_param(private_user_identity); event.add_var_param(public_user_identity); event.add_var_param(auth_type); SAS::report_event(event); std::string path = "/impi/" + Utils::url_escape(private_user_identity) + "/av"; if (!auth_type.empty()) { path += "/" + auth_type; } if (!public_user_identity.empty()) { path += "?impu=" + Utils::url_escape(public_user_identity); } if (!resync_auth.empty()) { path += public_user_identity.empty() ? "?" : "&"; path += "resync-auth=" + Utils::url_escape(resync_auth); } HTTPCode rc = get_json_object(path, av, trail); unsigned long latency_us = 0; // Only accumulate the latency if we haven't already applied a // penalty if ((rc != HTTP_SERVER_UNAVAILABLE) && (rc != HTTP_GATEWAY_TIMEOUT) && (stopWatch.read(latency_us))) { _latency_tbl->accumulate(latency_us); _mar_latency_tbl->accumulate(latency_us); } if (av == NULL) { TRC_ERROR("Failed to get Authentication Vector for %s", private_user_identity.c_str()); } return rc; }
// Parses the given User-Data XML to retrieve the single PrivateID element. std::string get_private_id(const std::string& user_data) { std::string impi; // Parse the XML document, saving off the passed-in string first (as parsing // is destructive). rapidxml::xml_document<> doc; // This doesn't need freeing - prev_doc is on the stack, and this // uses its memory pool. char* user_data_str = doc.allocate_string(user_data.c_str()); try { doc.parse<rapidxml::parse_strip_xml_namespaces>(user_data_str); } catch (rapidxml::parse_error err) { TRC_ERROR("Parse error in IMS Subscription document: %s\n\n%s", err.what(), user_data.c_str()); doc.clear(); } rapidxml::xml_node<>* is = doc.first_node("IMSSubscription"); if (is) { rapidxml::xml_node<>* id = is->first_node("PrivateID"); if (id) { impi = id->value(); } else { TRC_ERROR("Missing Private ID in IMS Subscription document: \n\n%s", user_data.c_str()); } } if (impi.compare("null") == 0) { impi = ""; // LCOV_EXCL_LINE } return impi; }
// Parses the given User-Data XML to retrieve a list of all the public IDs. std::vector<std::string> get_public_ids(const std::string& user_data) { std::vector<std::string> public_ids; // Parse the XML document, saving off the passed-in string first (as parsing // is destructive). rapidxml::xml_document<> doc; // This doesn't need freeing - doc is on the stack, and this // uses its memory pool. char* user_data_str = doc.allocate_string(user_data.c_str()); try { doc.parse<rapidxml::parse_strip_xml_namespaces>(user_data_str); } catch (rapidxml::parse_error err) { TRC_DEBUG("Parse error in IMS Subscription document: %s\n\n%s", err.what(), user_data.c_str()); doc.clear(); } // Walk through all nodes in the hierarchy IMSSubscription->ServiceProfile->PublicIdentity // ->Identity. rapidxml::xml_node<>* is = doc.first_node("IMSSubscription"); if (is) { for (rapidxml::xml_node<>* sp = is->first_node("ServiceProfile"); sp; sp = sp->next_sibling("ServiceProfile")) { for (rapidxml::xml_node<>* pi = sp->first_node("PublicIdentity"); pi; pi = pi->next_sibling("PublicIdentity")) { rapidxml::xml_node<>* id = pi->first_node("Identity"); if (id) { public_ids.push_back((std::string)id->value()); } else { TRC_WARNING("PublicIdentity node was missing Identity child: %s", user_data.c_str()); } } } } if (public_ids.size() == 0) { TRC_ERROR("Failed to extract any ServiceProfile/PublicIdentity/Identity nodes from %s", user_data.c_str()); } return public_ids; }
DNSEnumService::DNSEnumService(const std::vector<std::string>& dns_servers, const std::string& dns_suffix, const DNSResolverFactory* resolver_factory, CommunicationMonitor* comm_monitor) : _dns_suffix(dns_suffix), _resolver_factory(resolver_factory), _comm_monitor(comm_monitor) { // Initialize the ares library. This might have already been done by curl // but it's safe to do it twice. ares_library_init(ARES_LIB_INIT_ALL); struct addrinfo* res; for (std::vector<std::string>::const_iterator server = dns_servers.begin(); server != dns_servers.end(); server++) { struct IP46Address dns_server_addr; // Parse the DNS server's IP address. if (inet_pton(AF_INET, server->c_str(), &dns_server_addr.addr.ipv4)) { dns_server_addr.af = AF_INET; } else if (inet_pton(AF_INET6, server->c_str(), &dns_server_addr.addr.ipv6)) { dns_server_addr.af = AF_INET6; } else if ((getaddrinfo(server->c_str(), NULL, NULL, &res)) == 0) { dns_server_addr.af = res->ai_family; if (dns_server_addr.af == AF_INET) { dns_server_addr.addr.ipv4 = ((struct sockaddr_in*)res->ai_addr)->sin_addr; } else if (dns_server_addr.af == AF_INET6) { dns_server_addr.addr.ipv6 = ((struct sockaddr_in6*)res->ai_addr)->sin6_addr; } freeaddrinfo(res); } else { TRC_ERROR("Failed to parse '%s' as IP address or resolve host name - defaulting to 127.0.0.1", server->c_str()); dns_server_addr.af = AF_INET; (void)inet_aton("127.0.0.1", &dns_server_addr.addr.ipv4); } _servers.push_back(dns_server_addr); } // We store a DNSResolver in thread-local data, so create the thread-local // store. pthread_key_create(&_thread_local, (void(*)(void*))DNSResolver::destroy); }
std::string JSONEnumService::lookup_uri_from_user(const std::string &user, SAS::TrailId trail) const { std::string uri; TRC_DEBUG("Translating URI via JSON ENUM lookup"); if (user.empty()) { TRC_INFO("No dial string supplied, so don't do ENUM lookup"); return std::string(); } std::string aus = user_to_aus(user); // Take a read lock on the mutex in RAII style boost::shared_lock<boost::shared_mutex> read_lock(_number_prefixes_rw_lock); const struct NumberPrefix* pfix = prefix_match(aus); if (pfix == NULL) { TRC_WARNING("No matching number range %s from ENUM lookup", user.c_str()); SAS::Event event(trail, SASEvent::ENUM_INCOMPLETE, 0); event.add_var_param(user); SAS::report_event(event); return uri; } // Apply the regular expression to the user string to generate a new // URI. try { uri = boost::regex_replace(aus, pfix->match, pfix->replace); } catch(...) // LCOV_EXCL_START Only throws if expression too complex or similar hard-to-hit conditions { TRC_ERROR("Failed to translate number with regex"); SAS::Event event(trail, SASEvent::ENUM_INCOMPLETE, 1); event.add_var_param(user); SAS::report_event(event); return uri; // LCOV_EXCL_STOP } TRC_INFO("Number %s found, translated URI = %s", user.c_str(), uri.c_str()); SAS::Event event(trail, SASEvent::ENUM_COMPLETE, 0); event.add_var_param(user); event.add_var_param(uri); SAS::report_event(event); return uri; }
void BaseMemcachedStore::update_config() { MemcachedConfig cfg; if (_config_reader->read_config(cfg)) { new_view(cfg); _tombstone_lifetime = cfg.tombstone_lifetime; } else { TRC_ERROR("Failed to read config, keeping previous settings"); } }
bool AlarmTableDefs::populate_map(std::string path, std::map<unsigned int, unsigned int>& dup_check) { std::string error; std::vector<AlarmDef::AlarmDefinition> alarm_definitions; bool rc = JSONAlarms::validate_alarms_from_json(path, error, alarm_definitions); if (!rc) { TRC_ERROR("%s", error.c_str()); return rc; } std::vector<AlarmDef::AlarmDefinition>::const_iterator a_it; for (a_it = alarm_definitions.begin(); a_it != alarm_definitions.end(); a_it++) { if (dup_check.count(a_it->_index)) { TRC_ERROR("alarm %d.*: is multiply defined", a_it->_index); rc = false; break; } else { dup_check[a_it->_index] = 1; } std::vector<AlarmDef::SeverityDetails>::const_iterator s_it; for (s_it = a_it->_severity_details.begin(); s_it != a_it->_severity_details.end(); s_it++) { AlarmTableDef def(*a_it, *s_it); AlarmTableDefs::insert_def(def); } } return rc; }
/// Loads the Memento plug-in, returning the supported Sproutlets. bool MementoPlugin::load(struct options& opt, std::list<Sproutlet*>& sproutlets) { bool plugin_loaded = true; if (opt.enabled_memento) { SNMP::SuccessFailCountByRequestTypeTable* incoming_sip_transactions_tbl = SNMP::SuccessFailCountByRequestTypeTable::create("memento_as_incoming_sip_transactions", "1.2.826.0.1.1578918.9.8.1.4"); SNMP::SuccessFailCountByRequestTypeTable* outgoing_sip_transactions_tbl = SNMP::SuccessFailCountByRequestTypeTable::create("memento_as_outgoing_sip_transactions", "1.2.826.0.1.1578918.9.8.1.5"); if (((opt.max_call_list_length == 0) && (opt.call_list_ttl == 0))) { TRC_ERROR("Can't have an unlimited maximum call length and a unlimited TTL for the call list store - disabling Memento"); } else { _cass_comm_monitor = new CommunicationMonitor(new Alarm(alarm_manager, "memento", AlarmDef::MEMENTO_AS_CASSANDRA_COMM_ERROR, AlarmDef::CRITICAL), "Memento", "Memcached"); _call_list_store = new CallListStore::Store(); _call_list_store->configure_connection("localhost", 9160, _cass_comm_monitor); _memento = new MementoAppServer(opt.prefix_memento, _call_list_store, opt.home_domain, opt.max_call_list_length, opt.memento_threads, opt.call_list_ttl, stack_data.stats_aggregator, opt.cass_target_latency_us, opt.max_tokens, opt.init_token_rate, opt.min_token_rate, exception_handler, http_resolver, opt.memento_notify_url); _memento_sproutlet = new SproutletAppServerShim(_memento, opt.port_memento, incoming_sip_transactions_tbl, outgoing_sip_transactions_tbl); sproutlets.push_back(_memento_sproutlet); } } return plugin_loaded; }
void Store::do_async(Operation*& op, Transaction*& trx) { if (_thread_pool == NULL) { TRC_ERROR("Can't process async operation as no thread pool has been configured"); assert(!"Can't process async operation as no thread pool has been configured"); } std::pair<Operation*, Transaction*> params(op, trx); _thread_pool->add_work(params); // The caller no longer owns the operation or transaction, so null them out. op = NULL; trx = NULL; }
// Request a digest from Homestead, store it in memcached, and generate // the WWW-Authenticate header. HTTPCode HTTPDigestAuthenticate::request_digest_and_store(std::string& www_auth_header, bool include_stale, Response* response) { HTTPCode rc = HTTP_BAD_REQUEST; std::string ha1; std::string realm; TRC_DEBUG("Request digest for IMPU: %s, IMPI: %s", _impu.c_str(), _impi.c_str()); // Request the digest from homestead rc = _homestead_conn->get_digest_data(_impi, _impu, ha1, realm, _trail); if (rc == HTTP_OK) { // Generate the digest structure and store it in memcached TRC_DEBUG("Store digest for IMPU: %s, IMPI: %s", _impu.c_str(), _impi.c_str()); AuthStore::Digest* digest = new AuthStore::Digest(); generate_digest(ha1, realm, digest); Store::Status status = _auth_store->set_digest(_impi, digest->_nonce, digest, _trail); if (status == Store::OK) { // Update statistics - either stale or (initial) challenge. if (include_stale) { _stat_auth_stale_count->increment(); } else { _stat_auth_challenge_count->increment(); } // Create the WWW-Authenticate header generate_www_auth_header(www_auth_header, include_stale, digest); rc = HTTP_UNAUTHORIZED; } else { // LCOV_EXCL_START - Store used in UT never fails TRC_ERROR("Unable to write digest to store"); rc = HTTP_SERVER_ERROR; // LCOV_EXCL_STOP } delete digest; digest = NULL; } return rc; }
/************************************************************ * * Convert table index components to an oid. */ int alarmModelTable_index_to_oid(char* name, unsigned long index, unsigned long state, netsnmp_index *oid_idx) { int err = SNMP_ERR_NOERROR; netsnmp_variable_list var_alarmListName; netsnmp_variable_list var_alarmModelIndex; netsnmp_variable_list var_alarmModelState; /* * set up varbinds */ memset(&var_alarmListName, 0x00, sizeof(var_alarmListName)); var_alarmListName.type = ASN_OCTET_STR; memset(&var_alarmModelIndex, 0x00, sizeof(var_alarmModelIndex)); var_alarmModelIndex.type = ASN_UNSIGNED; memset(&var_alarmModelState, 0x00, sizeof(var_alarmModelState)); var_alarmModelState.type = ASN_UNSIGNED; /* * chain index varbinds together */ var_alarmListName.next_variable = &var_alarmModelIndex; var_alarmModelIndex.next_variable = &var_alarmModelState; var_alarmModelState.next_variable = NULL; DEBUGMSGTL(("verbose:alarmModelTable:alarmModelTable_index_to_oid", "called\n")); snmp_set_var_value(&var_alarmListName, (u_char*) name, strlen(name)); snmp_set_var_value(&var_alarmModelIndex, (u_char*) &index, sizeof(index)); snmp_set_var_value(&var_alarmModelState, (u_char*) &state, sizeof(state)); err = build_oid(&oid_idx->oids, &oid_idx->len, NULL, 0, &var_alarmListName); if (err) { TRC_ERROR("error %d converting index to oid: alarmModelTable_index_to_oid", err); // LCOV_EXCL_LINE } /* * parsing may have allocated memory. free it. */ snmp_reset_var_buffers(&var_alarmListName); return err; }
bool ICSCFSproutlet::init() { bool init_success = true; // Convert the BGCF routing URI to a form suitable for PJSIP, so we're // not continually converting from a string. _bgcf_uri = PJUtils::uri_from_string(_bgcf_uri_str, stack_data.pool, false); if (_bgcf_uri == NULL) { TRC_ERROR("Invalid BGCF URI %s", _bgcf_uri_str.c_str()); //LCOV_EXCL_LINE init_success = false; } return init_success; }
int foo(int n) { TRC_ENTER(UNIT_FOO, TRC1, ("n=%d", n)); if(n <= 0){ TRC_ERROR(UNIT_FOO, ("Invalid argument: %d", n)); TRC_RETURN(UNIT_FOO, TRC1, ("%d", 1), 1); } int i; for(i=n; i>0; i--){ sleep(1); TRC_PRINT(UNIT_FOO, TRC0, ("Hello world[%d]", i)); } TRC_RETURN(UNIT_FOO, TRC1, ("%d", 0), 0); }
void BaseMemcachedStore::log_delete_failure(const std::string& fqkey, int replica_ix, int replica_count, SAS::TrailId trail, uint32_t instance) { TRC_ERROR("Delete failed to replica %d", replica_ix); if (trail != 0) { SAS::Event event(trail, SASEvent::MEMCACHED_DELETE_FAILURE, instance); event.add_var_param(fqkey); event.add_static_param(replica_ix); event.add_static_param(replica_count); SAS::report_event(event); } }
pj_status_t ConnectionPool::resolve_host(const pj_str_t* host, int port, pj_sockaddr* addr) { pj_status_t status = PJ_ENOTFOUND; // Select a server for this connection. std::vector<AddrInfo> servers; PJUtils::resolve(std::string(host->ptr, host->slen), port, IPPROTO_TCP, 1, servers); memset(addr, 0, sizeof(pj_sockaddr)); if (!servers.empty()) { if (servers[0].address.af == AF_INET) { TRC_DEBUG("Successfully resolved %.*s to IPv4 address", host->slen, host->ptr); addr->ipv4.sin_family = AF_INET; addr->ipv4.sin_addr.s_addr = servers[0].address.addr.ipv4.s_addr; pj_sockaddr_set_port(addr, servers[0].port); status = PJ_SUCCESS; } else if (servers[0].address.af == AF_INET6) { TRC_DEBUG("Successfully resolved %.*s to IPv6 address", host->slen, host->ptr); addr->ipv6.sin6_family = AF_INET6; memcpy((char*)&addr->ipv6.sin6_addr, (char*)&servers[0].address.addr.ipv6, sizeof(struct in6_addr)); pj_sockaddr_set_port(addr, servers[0].port); status = PJ_SUCCESS; } else { TRC_ERROR("Resolved %.*s to address of unknown family %d - failing connection!", host->slen, host->ptr); //LCOV_EXCL_LINE } } return status; }
void *bar(void *arg) { int n = *(int *)arg; TRC_ADD_THREAD("bar", 0); TRC_ENTER(UNIT_BAR, TRC1, ("arg=0x%x", arg)); if(n <= 0){ TRC_ERROR(UNIT_FOO, ("Invalid argument: %d", n)); TRC_RETURN(UNIT_FOO, TRC1, ("0x%x", NULL), NULL); } int i; for(i=n; i>0; i--){ sleep(1); TRC_PRINT(UNIT_BAR, TRC0, ("Goodbye cruel world[%d]", i)); } TRC_RETURN(UNIT_BAR, TRC1, ("0x%x", NULL), NULL); }
void HTTPCallback::start(TimerHandler* handler) { _handler = handler; _running = true; // Create a pool of worker threads for (int ii = 0; ii < HTTPCALLBACK_THREAD_COUNT; ++ii) { pthread_t thread; int thread_rc = pthread_create(&thread, NULL, HTTPCallback::worker_thread_entry_point, (void*)this); if (thread_rc != 0) { TRC_ERROR("Failed to start callback worker thread: %s", strerror(thread_rc)); } _worker_threads[ii] = thread; } }
TrustBoundary::TrustBoundary(std::string description, pj_bool_t strip_request, pj_bool_t strip_response, pj_bool_t strip_p_charging, pj_bool_t add_p_charging, pj_bool_t add_p_charging_rsp) : _strip_request(strip_request), _strip_response(strip_response), _strip_p_charging(strip_p_charging), _add_p_charging(add_p_charging), _add_p_charging_rsp(add_p_charging_rsp), _description(description) { if ((_add_p_charging && !_strip_p_charging) || (_add_p_charging_rsp && !_strip_request)) { // LCOV_EXCL_START TRC_ERROR("Trust boundary configured to add P-Charging headers without stripping existing ones, inconsistent configuration"); _strip_p_charging = PJ_TRUE; // LCOV_EXCL_STOP } }
/// Utility method for converting a call fragment type to the string /// representation used in cassandra. /// /// @param type - The type of fragment. /// @return - The string representation. std::string fragment_type_to_string(CallFragment::Type type) { switch(type) { case CallFragment::BEGIN: return STR_BEGIN; case CallFragment::END: return STR_END; case CallFragment::REJECTED: return STR_REJECTED; default: // LCOV_EXCL_START - We should never reach this code. The function must // be passed a value in the enumeration, and we have already handled all // of them. TRC_ERROR("Unexpected call fragment type %d", (int)type); return (std::string("UNKNOWN (") + std::to_string(type) + std::string(")")); // LCOV_EXCL_STOP } }
std::string JSONEnumService::lookup_uri_from_user(const std::string &user, SAS::TrailId trail) const { std::string uri; TRC_DEBUG("Translating URI via JSON ENUM lookup"); if (user.empty()) { TRC_INFO("No dial string supplied, so don't do ENUM lookup"); return std::string(); } std::string aus = user_to_aus(user); struct NumberPrefix* pfix = prefix_match(aus); if (pfix == NULL) { TRC_INFO("No matching number range %s from ENUM lookup", user.c_str()); return uri; } // Apply the regular expression to the user string to generate a new // URI. try { uri = boost::regex_replace(aus, pfix->match, pfix->replace); } catch(...) // LCOV_EXCL_START Only throws if expression too complex or similar hard-to-hit conditions { TRC_ERROR("Failed to translate number with regex"); return uri; // LCOV_EXCL_STOP } TRC_INFO("Number %s found, translated URI = %s", user.c_str(), uri.c_str()); return uri; }
Store::Status AuthStore::set_digest(const std::string& impi, const std::string& nonce, const AuthStore::Digest* digest, SAS::TrailId trail) { std::string key = impi + '\\' + nonce; std::string data = serialize_digest(digest); TRC_DEBUG("Set digest for %s\n%s", key.c_str(), data.c_str()); Store::Status status = _data_store->set_data("AuthStore", key, data, digest->_cas, _expiry, trail); if (status != Store::Status::OK) { // LCOV_EXCL_START - Store used in UTs doesn't fail TRC_ERROR("Failed to write digest for key %s", key.c_str()); SAS::Event event(trail, SASEvent::AUTHSTORE_SET_FAILURE, 0); event.add_var_param(key); event.add_var_param(data); SAS::report_event(event); // LCOV_EXCL_STOP } else { SAS::Event event(trail, SASEvent::AUTHSTORE_SET_SUCCESS, 0); event.add_var_param(key); event.add_var_param(data); SAS::report_event(event); } return status; }
static void sas_log_tx_msg(pjsip_tx_data *tdata) { // For outgoing messages always use the trail identified in the module data SAS::TrailId trail = get_trail(tdata); if (trail == DONT_LOG_TO_SAS) { TRC_DEBUG("Skipping SAS logging for OPTIONS response"); return; } else if (trail != 0) { // Raise SAS markers on initial requests only - responses in the same // transaction will have the same trail ID so don't need additional markers if (tdata->msg->type == PJSIP_REQUEST_MSG) { PJUtils::report_sas_to_from_markers(trail, tdata->msg); PJUtils::mark_sas_call_branch_ids(trail, NULL, tdata->msg); } // Log the message event. SAS::Event event(trail, SASEvent::TX_SIP_MSG, 0); event.add_static_param(pjsip_transport_get_type_from_flag(tdata->tp_info.transport->flag)); event.add_static_param(tdata->tp_info.dst_port); event.add_var_param(tdata->tp_info.dst_name); event.add_compressed_param((int)(tdata->buf.cur - tdata->buf.start), tdata->buf.start, &SASEvent::PROFILE_SIP); SAS::report_event(event); } else { TRC_ERROR("Transmitting message with no SAS trail identifier\n%.*s", (int)(tdata->buf.cur - tdata->buf.start), tdata->buf.start); } }
void Store::Pool::process_work(std::pair<Operation*, Transaction*>& params) { bool success = false; // Extract the operation and transaction. Operation* op = params.first; Transaction* trx = params.second; // Run the operation. Catch all exceptions to stop an error from killing the // worker thread. try { trx->start_timer(); success = _store->do_sync(op, trx->trail); } // LCOV_EXCL_START Transaction catches all exceptions so the thread pool // fallback code is never triggered. catch(...) { TRC_ERROR("Unhandled exception when processing cassandra request"); } trx->stop_timer(); // LCOV_EXCL_STOP // Call the application back via the transaction. if (success) { trx->on_success(op); } else { trx->on_failure(op); } // We own the transaction and operation so have to free them. delete trx; trx = NULL; delete op; op = NULL; }
void ConnectionPool::init() { // Create an initial set of connections. for (int ii = 0; ii < _num_connections; ++ii) { create_connection(ii); } if (_recycle_period != 0) { // Spawn a thread to recycle connections pj_status_t status = pj_thread_create(_pool, "recycler", &recycle_thread, (void*)this, 0, 0, &_recycler); if (status != PJ_SUCCESS) { TRC_ERROR("Error creating recycler thread, %s", PJUtils::pj_status_to_string(status).c_str()); } } TRC_DEBUG("Started %d connections to %.*s:%d", _num_connections, _target.host.slen, _target.host.ptr, _target.port); }