MT#56772 AmSdp: covert sessId / sessV to llu

Use `unsigned long long` for SDP session id and version
instead of unsigned int.

Refactor all usage of them accordingly.

Additionally intrdouce new utils functions for conversion:
- `ulonglong2str()` - converts `unsigned long long` to `string`
- `str2ull()` - converts `string` to `unsigned long long`

Change-Id: I4210349a5442d4173b14227497f4a01d68cad7a4
mr12.5.1
Donat Zenichev 2 years ago
parent 760ef73385
commit ced4a52c5d

@ -1891,7 +1891,7 @@ void CallLeg::createResumeRequest(AmSdp &sdp)
* be good enough for unholding (might be held already with zero conncetions) */
/* keep sessV incremented each time sending SDP offer (hold/resume) */
non_hold_sdp.origin.sessV++;
DBG("Increasing session version in SDP origin line to %lld", non_hold_sdp.origin.sessV);
DBG("Increasing session version in SDP origin line to %llu", non_hold_sdp.origin.sessV);
if (!non_hold_sdp.media.empty()) {
sdp = non_hold_sdp;

@ -1847,7 +1847,7 @@ void SBCCallLeg::createHoldRequest(AmSdp &sdp)
} else {
/* increase sessV */
sdp.origin.sessV++;
TRACE("Increasing session version in SDP origin line to %lld", sdp.origin.sessV);
TRACE("Increasing session version in SDP origin line to %llu", sdp.origin.sessV);
}
AmB2BMedia *ms = getMediaSession();

@ -616,7 +616,7 @@ void AmB2BSession::saveLocalSdpOrigin(const AmSdp& sdp)
previous_origin_sessId = sdp.origin.sessId;
previous_origin_sessV = sdp.origin.sessV;
DBG("Remembering initial SDP Origin (Id %s V %s)\n",
longlong2str(sdp.origin.sessId).c_str(), longlong2str(sdp.origin.sessV).c_str());
ulonglong2str(sdp.origin.sessId).c_str(), ulonglong2str(sdp.origin.sessV).c_str());
}
}
@ -656,10 +656,10 @@ void AmB2BSession::updateLocalSdpOrigin(AmSdp& sdp) {
// remember the current SDP for the next time
previous_sdp = sdp;
DBG("SDP changed; updating Origin (Id %s V %s)\n",
longlong2str(sdp.origin.sessId).c_str(), longlong2str(sdp.origin.sessV).c_str());
ulonglong2str(sdp.origin.sessId).c_str(), ulonglong2str(sdp.origin.sessV).c_str());
} else {
DBG("SDP unchanged; keeping Origin (Id %s V %s)\n",
longlong2str(sdp.origin.sessId).c_str(), longlong2str(sdp.origin.sessV).c_str());
ulonglong2str(sdp.origin.sessId).c_str(), ulonglong2str(sdp.origin.sessV).c_str());
}
}
}

@ -380,7 +380,7 @@ int AmOfferAnswer::onReplyOut(AmSipReply& reply)
} else {
force_no_sdp_update = (sdp_local.origin.sessV == parser_sdp.origin.sessV);
if (force_no_sdp_update)
DBG("Forcing no OA state update (no SDP changes, same session version: was <%u>, now is <%u>).\n",
DBG("Forcing no OA state update (no SDP changes, same session version: was <%llu>, now is <%llu>).\n",
sdp_local.origin.sessV, parser_sdp.origin.sessV);
}
}

@ -315,8 +315,8 @@ int AmSdp::parse(const char* _sdp_msg)
void AmSdp::print(string& body) const
{
string out_buf = "v="+int2str(version)+"\r\n"
"o="+origin.user+" "+int2str(origin.sessId)+" "+
int2str(origin.sessV)+" IN ";
"o="+origin.user+" "+ulonglong2str(origin.sessId)+" "+
ulonglong2str(origin.sessV)+" IN ";
if (!origin.conn.address.empty())
if (origin.conn.address.find(".") != std::string::npos)
@ -1285,7 +1285,7 @@ static void parse_sdp_origin(AmSdp* sdp_msg, char* s)
break;
}
string id(origin_line, int(next-origin_line)-1);
str2i(id, origin.sessId);
str2ull(id, origin.sessId);
origin_line = next;
origin_st = VERSION_ST;
break;
@ -1300,7 +1300,7 @@ static void parse_sdp_origin(AmSdp* sdp_msg, char* s)
break;
}
string version(origin_line, int(next-origin_line)-1);
str2i(version, origin.sessV);
str2ull(version, origin.sessV);
origin_line = next;
origin_st = NETTYPE;
break;

@ -81,8 +81,8 @@ struct SdpConnection
struct SdpOrigin
{
string user;
unsigned int sessId;
unsigned int sessV;
unsigned long long sessId;
unsigned long long sessV;
SdpConnection conn;
SdpOrigin() : user(), conn() {}

@ -57,6 +57,13 @@
static char _int2str_lookup[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', '9' };
string ull2str(unsigned long long val)
{
char buffer[64] = {0};
sprintf(buffer, "%llu", val);
return string((char*)(buffer));
}
string int2str(unsigned int val)
{
char buffer[64] = {0};
@ -96,6 +103,7 @@ string signed2str(T val, T (*abs_func) (T), DT (*div_func) (T, T))
string int2str(int val) { return signed2str<int, div_t>(val, abs, div); }
string long2str(long int val) { return signed2str<long, ldiv_t>(val, labs, ldiv); }
string longlong2str(long long int val) { return signed2str<long long, lldiv_t>(val, llabs, lldiv); }
string ulonglong2str(unsigned long long val) { return ull2str(val); }
static char _int2hex_lookup[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', '9','A','B','C','D','E','F' };
static char _int2hex_lookup_l[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', '9','a','b','c','d','e','f' };
@ -367,6 +375,61 @@ bool str2long(char*& str, long& result, char sep)
return false;
}
// long int could probably be the same size as int
bool str2ull(const string& str, unsigned long long& result)
{
char* s = (char*)str.c_str();
return str2ull(s,result);
}
bool str2ull(char*& str, unsigned long long& result, char sep)
{
unsigned long long ret=0;
int i=0;
char* init = str;
long sign = 1;
for(; (*str != '\0') && (*str == ' '); str++);
if (*str == '-') {
sign = -1;
str++;
for(; (*str != '\0') && (*str == ' '); str++);
}
for(; *str != '\0';str++){
if ( (*str <= '9' ) && (*str >= '0') ){
ret=ret*10+*str-'0';
i++;
if (i>20) goto error_digits;
} else {
bool eol = false;
switch(*str){
case 0xd:
case 0xa:
case 0x0:
eol = true;
}
if( (*str != sep) && !eol )
goto error_char;
break;
}
}
result = ret * sign;
return true;
error_digits:
DBG("str2ull: too many digits in [%s]\n", init);
return false;
error_char:
DBG("str2ull: unexpected char 0x%x in %s\n", *str, init);
return false;
}
bool str2bool(const string &s, bool &dst)
{
// TODO: optimize

@ -59,6 +59,11 @@ typedef unsigned char HASHHEX[HASHHEXLEN+1];
/** @file AmUtils.h */
/**
* Convert an unsigned unsigned long long to a string.
*/
string ull2str(unsigned long long val);
/**
* Convert an int to a string.
*/
@ -79,6 +84,11 @@ string long2str(long int val);
*/
string longlong2str(long long int val);
/**
* Convert a unsigned long long to a string.
*/
string ulonglong2str(unsigned long long val);
/**
* Convert a a byte to a string using hexdecimal representation.
*/
@ -160,6 +170,23 @@ bool str2long(const string& str, long& result);
*/
bool str2long(char*& str, long& result, char sep = ' ');
/**
* Convert a string to a unsigned long long int.
* @param str [in] string to convert.
* @param result [out] result integer.
* @return true if on success (!!!).
*/
bool str2ull(const string& str, unsigned long long& result);
/**
* Internal version of preceeding 'std2ull' method.
* @param str [in,out] gets incremented until sep char or error occurs
* @param result [out] result of the function
* @param sep [in] character seprating the number to convert and the next token
* @return true on success
*/
bool str2ull(char*& str, unsigned long long& result, char sep = ' ');
/* translates string value into bool, returns false on error */
bool str2bool(const string &s, bool &dst);

Loading…
Cancel
Save