- Timestamp:
- Nov 6, 2013 8:05:11 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp
r4639 r4644 1 1 /* $Id$ */ 2 2 /* 3 * Copyright (C) 201 2Teluu Inc. (http://www.teluu.com)3 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com) 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify … … 86 86 } 87 87 88 ///////////////////////////////////////////////////////////////////////////////89 90 AuthCredInfo::AuthCredInfo()91 : dataType(0)92 {93 }94 95 AuthCredInfo::AuthCredInfo(const string ¶m_scheme,96 const string ¶m_realm,97 const string ¶m_user_name,98 const int param_data_type,99 const string param_data)100 : scheme(param_scheme), realm(param_realm), username(param_user_name),101 dataType(param_data_type), data(param_data)102 {103 }104 105 106 ///////////////////////////////////////////////////////////////////////////////107 108 TlsConfig::TlsConfig()109 {110 pjsip_tls_setting ts;111 pjsip_tls_setting_default(&ts);112 this->fromPj(ts);113 }114 115 pjsip_tls_setting TlsConfig::toPj() const116 {117 pjsip_tls_setting ts;118 119 ts.ca_list_file = str2Pj(this->CaListFile);120 ts.cert_file = str2Pj(this->certFile);121 ts.privkey_file = str2Pj(this->privKeyFile);122 ts.password = str2Pj(this->password);123 ts.method = this->method;124 ts.ciphers_num = this->ciphers.size();125 // The following will only work if sizeof(enum)==sizeof(int)126 pj_assert(sizeof(ts.ciphers[0]) == sizeof(int));127 ts.ciphers = (pj_ssl_cipher*)&this->ciphers[0];128 ts.verify_server = this->verifyServer;129 ts.verify_client = this->verifyClient;130 ts.require_client_cert = this->requireClientCert;131 ts.timeout.sec = this->msecTimeout / 1000;132 ts.timeout.msec = this->msecTimeout % 1000;133 ts.qos_type = this->qosType;134 ts.qos_params = this->qosParams;135 ts.qos_ignore_error = this->qosIgnoreError;136 137 return ts;138 }139 140 void TlsConfig::fromPj(const pjsip_tls_setting &prm)141 {142 this->CaListFile = pj2Str(prm.ca_list_file);143 this->certFile = pj2Str(prm.cert_file);144 this->privKeyFile = pj2Str(prm.privkey_file);145 this->password = pj2Str(prm.password);146 this->method = (pjsip_ssl_method)prm.method;147 // The following will only work if sizeof(enum)==sizeof(int)148 pj_assert(sizeof(prm.ciphers[0]) == sizeof(int));149 this->ciphers = IntVector(prm.ciphers, prm.ciphers+prm.ciphers_num);150 this->verifyServer = prm.verify_server;151 this->verifyClient = prm.verify_client;152 this->requireClientCert = prm.require_client_cert;153 this->msecTimeout = PJ_TIME_VAL_MSEC(prm.timeout);154 this->qosType = prm.qos_type;155 this->qosParams = prm.qos_params;156 this->qosIgnoreError = prm.qos_ignore_error;157 }158 159 ///////////////////////////////////////////////////////////////////////////////160 161 TransportConfig::TransportConfig()162 {163 pjsua_transport_config tc;164 pjsua_transport_config_default(&tc);165 this->fromPj(tc);166 }167 168 void TransportConfig::fromPj(const pjsua_transport_config &prm)169 {170 this->port = prm.port;171 this->portRange = prm.port_range;172 this->publicAddress = pj2Str(prm.public_addr);173 this->boundAddress = pj2Str(prm.bound_addr);174 this->tlsConfig.fromPj(prm.tls_setting);175 this->qosType = prm.qos_type;176 this->qosParams = prm.qos_params;177 }178 179 pjsua_transport_config TransportConfig::toPj() const180 {181 pjsua_transport_config tc;182 183 tc.port = this->port;184 tc.port_range = this->portRange;185 tc.public_addr = str2Pj(this->publicAddress);186 tc.bound_addr = str2Pj(this->boundAddress);187 tc.tls_setting = this->tlsConfig.toPj();188 tc.qos_type = this->qosType;189 tc.qos_params = this->qosParams;190 191 return tc;192 }193 194 ///////////////////////////////////////////////////////////////////////////////195 196 TransportInfo::TransportInfo(const pjsua_transport_info &info)197 {198 this->id = info.id;199 this->type = info.type;200 this->typeName = pj2Str(info.type_name);201 this->info = pj2Str(info.info);202 this->flags = info.flag;203 204 char straddr[PJ_INET6_ADDRSTRLEN+10];205 pj_sockaddr_print(&info.local_addr, straddr, sizeof(straddr), 3);206 this->localAddress = straddr;207 208 pj_ansi_snprintf(straddr, sizeof(straddr), "%.*s:%d",209 (int)info.local_name.host.slen,210 info.local_name.host.ptr,211 info.local_name.port);212 this->localName = straddr;213 this->usageCount = info.usage_count;214 }215 216 ///////////////////////////////////////////////////////////////////////////////217 218 void SipRxData::fromPj(pjsip_rx_data &rdata)219 {220 info = pjsip_rx_data_get_info(&rdata);221 wholeMsg = string(rdata.msg_info.msg_buf, rdata.msg_info.len);222 srcIp = rdata.pkt_info.src_name;223 srcPort = rdata.pkt_info.src_port;224 }225 226 ///////////////////////////////////////////////////////////////////////////////227 228 void SipHeader::fromPj(const pjsip_hdr *hdr) throw(Error)229 {230 char buf[256];231 232 int len = pjsip_hdr_print_on((void*)hdr, buf, sizeof(buf)-1);233 if (len <= 0)234 PJSUA2_RAISE_ERROR(PJ_ETOOSMALL);235 buf[len] = '\0';236 237 char *pos = strchr(buf, ':');238 if (!pos)239 PJSUA2_RAISE_ERROR(PJSIP_EINVALIDHDR);240 241 // Trim white space after header name242 char *end_name = pos;243 while (end_name>buf && pj_isspace(*(end_name-1))) --end_name;244 245 // Trim whitespaces after colon246 char *start_val = pos+1;247 while (*start_val && pj_isspace(*start_val)) ++start_val;248 249 hName = string(buf, end_name);250 hValue = string(start_val);251 }252 253 pjsip_generic_string_hdr &SipHeader::toPj() const254 {255 pj_str_t hname = str2Pj(hName);256 pj_str_t hvalue = str2Pj(hValue);257 258 pjsip_generic_string_hdr_init2(&pjHdr, &hname, &hvalue);259 return pjHdr;260 }
Note: See TracChangeset
for help on using the changeset viewer.