summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2015-12-12 10:08:50 -0700
committerGeorge Joseph <george.joseph@fairview5.com>2015-12-12 11:16:08 -0600
commit3e6637feb581fd8488227e78ae4823be560aafce (patch)
tree70a42a498ddd5d3372691a5fd8c942df30d2a15c /main/utils.c
parentceebdfce40d278d17ecfb82afdffc41a8cc1cc94 (diff)
pjsip/config_transport: Check pjproject version at runtime for async ops
pjproject < 2.5.0 will segfault on a tls transport if async_operations is greater than 1. A runtime version check has been added to throw an error if the version is < 2.5.0 and async_operations > 1. To assist in the check, a new api "ast_compare_versions" was added to utils which compares 2 major.minor.patch.extra version strings. ASTERISK-25615 #close Change-Id: I8e88bb49cbcfbca88d9de705496d6f6a8c938a98 Reported-by: George Joseph Tested-by: George Joseph
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/main/utils.c b/main/utils.c
index 74932b8c2..87241f197 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2944,3 +2944,26 @@ int ast_file_is_readable(const char *filename)
return 1;
#endif
}
+
+int ast_compare_versions(const char *version1, const char *version2)
+{
+ u_int64_t major[2] = { 0 };
+ u_int64_t minor[2] = { 0 };
+ u_int64_t patch[2] = { 0 };
+ u_int64_t extra[2] = { 0 };
+ u_int64_t v1, v2;
+
+ sscanf(version1, "%lu.%lu.%lu.%lu", &major[0], &minor[0], &patch[0], &extra[0]);
+ sscanf(version2, "%lu.%lu.%lu.%lu", &major[1], &minor[1], &patch[1], &extra[1]);
+
+ v1 = major[0] << 48 | minor[0] << 32 | patch[0] << 16 | extra[0];
+ v2 = major[1] << 48 | minor[1] << 32 | patch[1] << 16 | extra[1];
+
+ if (v1 < v2) {
+ return -1;
+ } else if (v1 > v2) {
+ return 1;
+ } else {
+ return 0;
+ }
+}