diff options
author | mannol <eniz_vukovic@hotmail.com> | 2014-01-25 01:32:33 +0100 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2014-01-25 01:32:33 +0100 |
commit | 65d320e31daa4709bb48b7f2a52c269dde0927e9 (patch) | |
tree | 45081a96be413d850a837d6afcee19fcfbfe7aca /toxrtp/toxrtp_helper.c | |
parent | 51d8c41390be853a13693476802a834daf8d156a (diff) |
Done with encryption and core adaptations.
Diffstat (limited to 'toxrtp/toxrtp_helper.c')
-rw-r--r-- | toxrtp/toxrtp_helper.c | 208 |
1 files changed, 0 insertions, 208 deletions
diff --git a/toxrtp/toxrtp_helper.c b/toxrtp/toxrtp_helper.c deleted file mode 100644 index 6f952359..00000000 --- a/toxrtp/toxrtp_helper.c +++ /dev/null | |||
@@ -1,208 +0,0 @@ | |||
1 | /* rtp_helper.c | ||
2 | * | ||
3 | * Has some standard functions. !Red! | ||
4 | * | ||
5 | * | ||
6 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
7 | * | ||
8 | * This file is part of Tox. | ||
9 | * | ||
10 | * Tox is free software: you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation, either version 3 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * Tox is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | |||
26 | |||
27 | #ifdef HAVE_CONFIG_H | ||
28 | #include "config.h" | ||
29 | #endif /* HAVE_CONFIG_H */ | ||
30 | |||
31 | #include "toxrtp_helper.h" | ||
32 | #include "../toxcore/network.h" | ||
33 | |||
34 | #include <assert.h> | ||
35 | |||
36 | #ifdef WIN | ||
37 | #include <windows.h> | ||
38 | #endif /* WIN */ | ||
39 | |||
40 | |||
41 | static int _seed = 0; /* Not initiated */ | ||
42 | |||
43 | int t_setipport ( const char *_ip, unsigned short _port, void *_dest ) | ||
44 | { | ||
45 | assert(_dest); | ||
46 | |||
47 | IP_Port *_dest_c = ( IP_Port * ) _dest; | ||
48 | ip_init(&_dest_c->ip, 0); | ||
49 | |||
50 | IP_Port _ipv6_garbage; | ||
51 | |||
52 | if ( !addr_resolve(_ip, &_dest_c->ip, &_ipv6_garbage.ip) ) | ||
53 | return FAILURE; | ||
54 | |||
55 | _dest_c->port = htons ( _port ); | ||
56 | |||
57 | return SUCCESS; | ||
58 | } | ||
59 | |||
60 | uint32_t t_random ( uint32_t _max ) | ||
61 | { | ||
62 | if ( !_seed ) { | ||
63 | srand ( t_time() ); | ||
64 | _seed++; | ||
65 | } | ||
66 | |||
67 | if ( _max <= 0 ) { | ||
68 | return ( unsigned ) rand(); | ||
69 | } else { | ||
70 | return ( unsigned ) rand() % _max; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | void t_memcpy ( uint8_t *_dest, const uint8_t *_source, size_t _size ) | ||
75 | { | ||
76 | /* | ||
77 | * Using countdown to zero method | ||
78 | * It's faster than for(_it = 0; _it < _size; _it++); | ||
79 | */ | ||
80 | size_t _it = _size; | ||
81 | |||
82 | do { | ||
83 | _it--; | ||
84 | _dest[_it] = _source[_it]; | ||
85 | } while ( _it ); | ||
86 | |||
87 | } | ||
88 | |||
89 | uint8_t *t_memset ( uint8_t *_dest, uint8_t _valu, size_t _size ) | ||
90 | { | ||
91 | /* | ||
92 | * Again using countdown to zero method | ||
93 | */ | ||
94 | size_t _it = _size; | ||
95 | |||
96 | do { | ||
97 | _it--; | ||
98 | _dest[_it] = _valu; | ||
99 | } while ( _it ); | ||
100 | |||
101 | return _dest; | ||
102 | } | ||
103 | |||
104 | size_t t_memlen ( const uint8_t *_valu) | ||
105 | { | ||
106 | const uint8_t *_it; | ||
107 | size_t _retu = 0; | ||
108 | |||
109 | for ( _it = _valu; *_it; ++_it ) ++_retu; | ||
110 | |||
111 | return _retu; | ||
112 | } | ||
113 | |||
114 | uint8_t *t_strallcpy ( const uint8_t *_source ) /* string alloc and copy */ | ||
115 | { | ||
116 | assert(_source); | ||
117 | |||
118 | size_t _length = t_memlen(_source) + 1; /* make space for null character */ | ||
119 | |||
120 | uint8_t *_dest = calloc( sizeof ( uint8_t ), _length ); | ||
121 | assert(_dest); | ||
122 | |||
123 | t_memcpy(_dest, _source, _length); | ||
124 | |||
125 | return _dest; | ||
126 | } | ||
127 | |||
128 | size_t t_strfind ( const uint8_t *_str, const uint8_t *_substr ) | ||
129 | { | ||
130 | size_t _pos = 0; | ||
131 | size_t _it, _delit = 0; | ||
132 | |||
133 | for ( _it = 0; _str[_it] != '\0'; _it++ ) { | ||
134 | if ( _str[_it] == _substr[_delit] ) { | ||
135 | _pos = _it; | ||
136 | |||
137 | while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ) { | ||
138 | _it ++; | ||
139 | _delit++; | ||
140 | |||
141 | if ( _substr[_delit] == '\0' ) { | ||
142 | return _pos; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | _delit = 0; | ||
147 | _pos = 0; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | return _pos; | ||
152 | } | ||
153 | |||
154 | #ifdef WIN | ||
155 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) | ||
156 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 | ||
157 | #else | ||
158 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL | ||
159 | #endif | ||
160 | |||
161 | struct timezone { | ||
162 | int tz_minuteswest; /* minutes W of Greenwich */ | ||
163 | int tz_dsttime; /* type of dst correction */ | ||
164 | }; | ||
165 | |||
166 | int gettimeofday(struct timeval *tv, struct timezone *tz) | ||
167 | { | ||
168 | FILETIME ft; | ||
169 | unsigned __int64 tmpres = 0; | ||
170 | static int tzflag; | ||
171 | |||
172 | if (NULL != tv) { | ||
173 | GetSystemTimeAsFileTime(&ft); | ||
174 | |||
175 | tmpres |= ft.dwHighDateTime; | ||
176 | tmpres <<= 32; | ||
177 | tmpres |= ft.dwLowDateTime; | ||
178 | |||
179 | /*converting file time to unix epoch*/ | ||
180 | tmpres -= DELTA_EPOCH_IN_MICROSECS; | ||
181 | tmpres /= 10; /*convert into microseconds*/ | ||
182 | tv->tv_sec = (long)(tmpres / 1000000UL); | ||
183 | tv->tv_usec = (long)(tmpres % 1000000UL); | ||
184 | } | ||
185 | |||
186 | if (NULL != tz) { | ||
187 | if (!tzflag) { | ||
188 | _tzset(); | ||
189 | tzflag++; | ||
190 | } | ||
191 | |||
192 | tz->tz_minuteswest = _timezone / 60; | ||
193 | tz->tz_dsttime = _daylight; | ||
194 | } | ||
195 | |||
196 | return 0; | ||
197 | } | ||
198 | #endif /* WIN */ | ||
199 | |||
200 | |||
201 | uint64_t t_time() | ||
202 | { | ||
203 | struct timeval _tv; | ||
204 | gettimeofday(&_tv, NULL); | ||
205 | uint64_t _retu_usec = _tv.tv_sec % 1000000; /* get 6 digits an leave space for 3 more */ | ||
206 | _retu_usec = _retu_usec * 1000 + (_tv.tv_usec / 1000 ); | ||
207 | return _retu_usec; | ||
208 | } | ||