Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

utils.h File Reference

#include <netdb.h>

Go to the source code of this file.

Data Structures

struct  ast_hostent

Defines

#define inet_ntoa   __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__

Functions

hostent * ast_gethostbyname (const char *host, struct ast_hostent *hp)
int ast_base64encode (char *dst, unsigned char *src, int srclen, int max)
int ast_base64decode (unsigned char *dst, char *src, int max)
int test_for_thread_safety (void)
const char * ast_inet_ntoa (char *buf, int bufsiz, struct in_addr ia)
int ast_utils_init (void)


Define Documentation

#define inet_ntoa   __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
 

Definition at line 38 of file utils.h.


Function Documentation

int ast_base64decode unsigned char *  dst,
char *  src,
int  max
 

Definition at line 221 of file utils.c.

00222 { 00223 int cnt = 0; 00224 unsigned int byte = 0; 00225 unsigned int bits = 0; 00226 int incnt = 0; 00227 #if 0 00228 unsigned char *odst = dst; 00229 #endif 00230 while(*src && (cnt < max)) { 00231 /* Shift in 6 bits of input */ 00232 byte <<= 6; 00233 byte |= (b2a[(int)(*src)]) & 0x3f; 00234 bits += 6; 00235 #if 0 00236 printf("Add: %c %s\n", *src, binary(b2a[(int)(*src)] & 0x3f, 6)); 00237 #endif 00238 src++; 00239 incnt++; 00240 /* If we have at least 8 bits left over, take that character 00241 off the top */ 00242 if (bits >= 8) { 00243 bits -= 8; 00244 *dst = (byte >> bits) & 0xff; 00245 #if 0 00246 printf("Remove: %02x %s\n", *dst, binary(*dst, 8)); 00247 #endif 00248 dst++; 00249 cnt++; 00250 } 00251 } 00252 #if 0 00253 dump(odst, cnt); 00254 #endif 00255 /* Dont worry about left over bits, they're extra anyway */ 00256 return cnt; 00257 }

int ast_base64encode char *  dst,
unsigned char *  src,
int  srclen,
int  max
 

Definition at line 259 of file utils.c.

00260 { 00261 int cnt = 0; 00262 unsigned int byte = 0; 00263 int bits = 0; 00264 int index; 00265 int cntin = 0; 00266 #if 0 00267 char *odst = dst; 00268 dump(src, srclen); 00269 #endif 00270 /* Reserve one bit for end */ 00271 max--; 00272 while((cntin < srclen) && (cnt < max)) { 00273 byte <<= 8; 00274 #if 0 00275 printf("Add: %02x %s\n", *src, binary(*src, 8)); 00276 #endif 00277 byte |= *(src++); 00278 bits += 8; 00279 cntin++; 00280 while((bits >= 6) && (cnt < max)) { 00281 bits -= 6; 00282 /* We want only the top */ 00283 index = (byte >> bits) & 0x3f; 00284 *dst = base64[index]; 00285 #if 0 00286 printf("Remove: %c %s\n", *dst, binary(index, 6)); 00287 #endif 00288 dst++; 00289 cnt++; 00290 } 00291 } 00292 if (bits && (cnt < max)) { 00293 /* Add one last character for the remaining bits, 00294 padding the rest with 0 */ 00295 byte <<= (6 - bits); 00296 index = (byte) & 0x3f; 00297 *(dst++) = base64[index]; 00298 cnt++; 00299 } 00300 *dst = '\0'; 00301 return cnt; 00302 }

struct hostent* ast_gethostbyname const char *  host,
struct ast_hostent hp
 

Definition at line 134 of file utils.c.

References ast_hostent::buf, ast_hostent::hp, and s.

Referenced by ast_get_ip().

00135 { 00136 int res; 00137 int herrno; 00138 const char *s; 00139 struct hostent *result = NULL; 00140 /* Although it is perfectly legitimate to lookup a pure integer, for 00141 the sake of the sanity of people who like to name their peers as 00142 integers, we break with tradition and refuse to look up a 00143 pure integer */ 00144 s = host; 00145 while(s && *s) { 00146 if (!isdigit(*s)) 00147 break; 00148 s++; 00149 } 00150 if (!s || !*s) 00151 return NULL; 00152 res = gethostbyname_r(host, &hp->hp, hp->buf, sizeof(hp->buf), &result, &herrno); 00153 00154 if (res || !result || !hp->hp.h_addr_list || !hp->hp.h_addr_list[0]) 00155 return NULL; 00156 return &hp->hp; 00157 }

const char* ast_inet_ntoa char *  buf,
int  bufsiz,
struct in_addr  ia
 

Definition at line 337 of file utils.c.

Referenced by ast_apply_ha(), ast_ouraddrfor(), ast_rtcp_read(), ast_rtp_bridge(), ast_rtp_read(), and ast_rtp_senddigit().

00338 { 00339 return inet_ntop(AF_INET, &ia, buf, bufsiz); 00340 }

int ast_utils_init void   ) 
 

Definition at line 342 of file utils.c.

Referenced by main().

00343 { 00344 base64_init(); 00345 return 0; 00346 }

int test_for_thread_safety void   ) 
 

Definition at line 193 of file utils.c.

References ast_mutex_lock, and ast_mutex_unlock.

Referenced by main().

00194 { 00195 ast_mutex_lock(&test_lock2); 00196 ast_mutex_lock(&test_lock); 00197 lock_count += 1; 00198 ast_mutex_lock(&test_lock); 00199 lock_count += 1; 00200 pthread_create(&test_thread, NULL, test_thread_body, NULL); 00201 usleep(100); 00202 if (lock_count != 2) 00203 test_errors++; 00204 ast_mutex_unlock(&test_lock); 00205 lock_count -= 1; 00206 usleep(100); 00207 if (lock_count != 1) 00208 test_errors++; 00209 ast_mutex_unlock(&test_lock); 00210 lock_count -= 1; 00211 if (lock_count != 0) 00212 test_errors++; 00213 ast_mutex_unlock(&test_lock2); 00214 usleep(100); 00215 if (lock_count != 0) 00216 test_errors++; 00217 pthread_join(test_thread, NULL); 00218 return(test_errors); /* return 0 on success. */ 00219 }


Generated on Tue Aug 17 16:13:57 2004 for Asterisk by doxygen 1.3.8