ims_tool.h
9.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* CC/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __IMS_TOOLS_H_
#define __IMS_TOOLS_H_
#include <stdint.h>
#include <string>
#include <stdio.h>
#include <sys/types.h>
#include <ims_conf.h>
#include "common.h"
#include <vector>
#include <boost/pool/object_pool.hpp>
typedef struct ims_route_info ims_route_info_t;
class ims_tool_t {
public:
/**
* @brief
*
* @param [in/out] num : uint64_t
* @return string
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 12:22:11
**/
static std::string decimal_to_binary(uint64_t num);
/**
* @brief sessionid的结构 | (8bit) fs_id | (40bit) timestamp_ms | (16bit) random_num |
*
* @param [in/out] fs_id : uint32_t
* @return uint64_t
* @retval
* @see
* @note
* @author dangdawei
* @date 2013/1/21 16:32:24
**/
static uint64_t get_sessionid(uint32_t fs_id);
/**
* @brief reqid的结构 | (8bit) reqtype | (32bit) reqip | (16bit) redport | (8bit) random_num |
*
* @param [in/out] reqtype : ServiceTypeT
* @param [in/out] reqid : uint32_t
* @param [in/out] reqport : uint32_t
* @return uint64_t
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 12:22:16
**/
static uint64_t get_reqid(const ims::ServiceTypeT& reqtype, uint32_t reqip, uint32_t reqport);
/**
* @brief requestid的结构 :
* | (8bit) RouteRequestType | (40bit) timestamp_ms | (16bit) random_num of sessionid
*
* @param [in] sessionid : uint64_t
* @param [in] requestType : RouteRequestType
* @return uint64_t
* @retval
* @see
* @note
* @author dangdawei
* @date 2013/4/7 18:22:14
**/
static ims::RouteRequestIDT get_requestid(const ims::SessionIdT& sessionid,
const ims::RouteRequestTypeT& requestType);
/**
* @brief
*
* @return uint64_t
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 12:22:20
**/
static uint64_t get_timestamp_ms();
/**
* @brief
*
* @return uint64_t
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 12:22:24
**/
static uint64_t get_timestamp_s();
/**
* @brief 整型IP地址转换为字符串
*
* @param [in/out] src : uint32_t
* @param [in/out] dest : char*
* @param [in/out] dest_len : uint32_t
* @return const char*
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 10:48:22
**/
static const char* inet_ntop(uint32_t src, char* dest, uint32_t dest_len);
/**
* @brief 字符串IP地址转换为整型
*
* @param [in/out] src : const char*
* @return uint32_t
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 10:48:43
**/
static uint32_t inet_pton(const char* src);
/**
* @brief 获取本机ipv4地址,非127.0.0.1
*
* @param naddr : uint32_t
* @return bool
* @retval
* @see
* @note
* @author dangdawei
* @date 2012/7/14 10:52:30
**/
static bool is_local_ipv4(uint32_t naddr);
/**
* @brief 复制字符串
*
* @param [in/out] src : const char*
* @param [in/out] pool : object_pool&
* @return const char*
* @retval
* @see
* @note
* @author chenyuzhen
* @date 2011/11/21 10:53:04
**/
static const char* strdup(const char* src, boost::object_pool<std::string>* pool);
static void safe_sleeps(uint32_t s);
static void safe_sleepms(uint32_t ms);
/**
* @brief parse_proxy ip地址解析 src 格式(-h ip -p port)
*
* @param [in] src : std::string parse_prixy地址字符串
* @param [in/out] ipstr : std::string& 解析出来的ip地址字符串
* @param [in/out] port : uint32_t& 解析出来的端口号
*
* @return ip和端口格式正确返回true,否则返回false
* @author wangsilan
* @date 2011-11-22 20:20:39
**/
static bool parse_proxy_info(const std::string& src, std::string& ipstr, uint32_t& port);
/**
* @breif ip地址合法性判断,并转换为整型
*
* @param [in] src : const char*
* @param [in/out] result : uint32_t& IP转换的整型
*
* @rerurn ip地址合法返回true,否则返回false
* @author wangsilan
* @date 2011-11-22 20:23:54
**/
static bool pa_chkip(const char* src, uint32_t& result);
/**
* @breif ip地址合法性判断,并转换为整型
*
* @param [in] src : const char*
*
* @rerurn ip地址合法返回true,否则返回false
* @author wangsilan
* @date 2011-11-22 20:34:08
**/
static bool pa_chkip(const char* src);
/**
* @breif 通过配置文件得到实际外呼和呼入号码
*
* @param [in] caller_no : const std::string& 主叫号码
* @param [in] cadded_no : const std::string& 被叫号码
* @param [in] dn : const std::string& 外呼坐席或IVR通道(assign的号码)
* @param [in] conf : const ims_conf_t& 配置项
* @param [in/out] disp_caller : std::string& 通过配置项匹配后的disp
* @param [in/out] caller : std::string& 通过配置相匹配后的caller
* @param [in/out] called : std::string& 通过配置相匹配后的called
*
* @return 找到对应route配置项返回true,否则返回false
* @author wangsilan
* @date 2011-11-24 14:37:12
**/
static bool set_callno(const std::string& caller_no, const std::string& called_no,
const std::string& dn, const ims_conf_t& conf,
std::string& disp_caller, std::string& caller, std::string& called);
/**
* @breif 字符串字串替换,将字符串dest中所有子串substr_replaced,替换为字符串src
*
* @param [in/out] dest : std::string&
* @param [in] substr_replaced : std::string&
* @param [in] src : std::string&
*
* @return 字符串dest存在substr_replace,返回true,否则返回false
* @author wangsilan
* @date 2011-11-24 14:46:49
*
**/
static bool replace_substring(std::string& dest, const std::string& substr_replaced,
const std::string& src);
/**
* @breif 根据res替换callno中的变量,例如callno中的$1用res[1]的值替换
*
* @param [in/out] callno : std::string&
* @param [in] res : const std::vector<std::string>&
*
* @return callno中存在要替换的变量返回true,否则返回false
* @author wangsilan
* date 2011-11-24 14:54:15
*
**/
static bool replace_callno(std::string& callno, const std::vector<std::string>& res);
/**
* @breif 输入:xxxx/yyyy/12345@123.12.3123.132:9000, 输出:12345
*
* @param [in] src : const std::string& xxxx/yyyy/12345@123.12.3123.132:9000
* @param [in/out] dest : std::string& 12345
*
* @result 转换是否成功
* @author wangsilan
* @date 2011-11-28 13:08:51
*
**/
static bool chlname2no(const std::string& src, std::string& dest);
static std::string chlname2no(const std::string& src);
static bool pa_chkport(const char* src, uint32_t& port);
static uint32_t get_fsno(uint64_t sessionid);
static uint32_t str_to_uint32(const char* src);
static bool ip_mask_parse(const char* src , uint32_t& ip, uint32_t& mask, uint32_t& bit);
static std::string num2str(uint64_t num);
static void prepare_call_event(ims::CallEventT& call_event,
const uint64_t time,
const ims::SessionIdT sid,
const ims::CallIdT callid,
const std::string& device,
ims::CallStateT state);
static void prepare_route_event(ims::RouteEventT& ims_event,
ims::SessionIdT sessionid, const ims_route_info_t& info);
static bool push_cancel_route_event(ims::SessionIdT sessionid);
static void print_conf_DEBUGLOG(const ims_conf_t& conf);
/*
* @breif 根据配置文件得到实际主叫号码
*
* @param [in] dn : 坐席或IVR号码
* @param [in] ani : 主叫号码
*
* @return 实际主叫号码
* @author wangsilan
* @date 2011-11-30 19:50:21
**/
static std::string get_assigned_caller(const std::string& dn, const std::string& ani);
/*
* @breif 根据配置文件得到实际被叫号码
*
* @param [in] dnis : 被叫号码
* @param [in] ani : 主叫号码
*
* @return 实际被叫号码
* @author wangsilan
* @date 2011-11-30 19:51:58
**/
static std::string get_assigned_called(const std::string& dnis, const std::string& ani);
static std::string generate_uuid();
/**
* @brief ip是不是可以在IMS上注册
* @param [in] addr : ip地址
* @param [in] type : 服务单元类型
* @return bool
* @author dangdawei
* @date 2012/7/4 14:47:30
**/
static bool is_accessible_ip(const std::string& addr, ims::ServiceTypeT type);
};
#endif //__IMS_TOOLS_H_
/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */