RTS API Documentation  1.10.11
switch_apr.c
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2015, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/F
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Michael Jerris <mike@jerris.com>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Michael Jerris <mike@jerris.com>
27  * Eliot Gable <egable@gmail.com>
28  * William King <william.king@quentustech.com>
29  *
30  * switch_apr.c -- apr wrappers and extensions
31  *
32  */
33 
34 #include <switch.h>
35 #ifndef WIN32
36 #include <switch_private.h>
37 #endif
39 #include "private/switch_apr_pvt.h"
40 
41 /* apr headers*/
42 #include <fspr.h>
43 #include <fspr_atomic.h>
44 #include <fspr_pools.h>
45 #include <fspr_hash.h>
46 #include <fspr_network_io.h>
47 #include <fspr_errno.h>
48 #include <fspr_thread_proc.h>
49 #include <fspr_portable.h>
50 #include <fspr_thread_mutex.h>
51 #include <fspr_thread_cond.h>
52 #include <fspr_thread_rwlock.h>
53 #include <fspr_file_io.h>
54 #include <fspr_poll.h>
55 #include <fspr_strings.h>
56 #define APR_WANT_STDIO
57 #define APR_WANT_STRFUNC
58 #include <fspr_want.h>
59 #include <fspr_file_info.h>
60 #include <fspr_fnmatch.h>
61 #include <fspr_tables.h>
62 
63 #ifdef WIN32
64 #include "fspr_arch_networkio.h"
65 /* Missing socket symbols */
66 #ifndef SOL_TCP
67 #define SOL_TCP IPPROTO_TCP
68 #endif
69 #endif
70 
71 /* fspr_vformatter_buff_t definition*/
72 #include <fspr_lib.h>
73 
74 #if (defined(HAVE_LIBMD5) || defined(HAVE_LIBMD) || defined(HAVE_MD5INIT))
75 #include <md5.h>
76 #elif defined(HAVE_LIBCRYPTO)
77  #ifndef OPENSSL_VERSION_NUMBER
78  #include <openssl/opensslv.h>
79  #endif
80  #if OPENSSL_VERSION_NUMBER < 0x30000000
81  #include <openssl/md5.h>
82  #else
83  #include <openssl/evp.h>
84  #endif
85 #else
86  #include <apr_md5.h>
87 #endif
88 
89 #ifndef WIN32
90 #include <uuid/uuid.h>
91 #endif
92 
93 /* apr stubs */
94 
96 {
97  return APR_STATUS_IS_TIMEUP(status);
98 }
99 
100 /* Memory Pools */
101 
103 {
104 #ifndef WIN32
105  return fspr_os_thread_current();
106 #else
107  return (switch_thread_id_t) (GetCurrentThreadId());
108 #endif
109 }
110 
112 {
113 #ifdef WIN32
114  return (tid1 == tid2);
115 #else
116  return fspr_os_thread_equal(tid1, tid2);
117 #endif
118 
119 }
120 
121 SWITCH_DECLARE(unsigned int) switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
122 {
123  unsigned int hash = 0;
124  const unsigned char *key = (const unsigned char *) char_key;
125  const unsigned char *p;
126  fspr_ssize_t i;
127 
128  if (*klen == APR_HASH_KEY_STRING) {
129  for (p = key; *p; p++) {
130  hash = hash * 33 + tolower(*p);
131  }
132  *klen = p - key;
133  } else {
134  for (p = key, i = *klen; i; i--, p++) {
135  hash = hash * 33 + tolower(*p);
136  }
137  }
138 
139  return hash;
140 }
141 
142 
143 SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen)
144 {
145  return fspr_hashfunc_default(key, klen);
146 }
147 
148 /* string functions */
149 
151 {
152  const char *p = format;
153 
154  if (!p)
155  return SWITCH_STATUS_FALSE;
156 
157  while (*p) {
158  if (*p == '%') {
159  switch (*(++p)) {
160  case 'C':
161  case 'D':
162  case 'r':
163  case 'R':
164  case 'T':
165  case 'e':
166  case 'a':
167  case 'A':
168  case 'b':
169  case 'B':
170  case 'c':
171  case 'd':
172  case 'H':
173  case 'I':
174  case 'j':
175  case 'm':
176  case 'M':
177  case 'p':
178  case 'S':
179  case 'U':
180  case 'w':
181  case 'W':
182  case 'x':
183  case 'X':
184  case 'y':
185  case 'Y':
186  case 'z':
187  case 'Z':
188  case '%':
189  p++;
190  continue;
191  case '\0':
192  default:
193  return SWITCH_STATUS_FALSE;
194  }
195  }
196  p++;
197  }
198 
199  return fspr_strftime(s, retsize, max, format, (fspr_time_exp_t *) tm);
200 }
201 
203 {
204  return fspr_strftime(s, retsize, max, format, (fspr_time_exp_t *) tm);
205 }
206 
207 SWITCH_DECLARE(int) switch_snprintf(char *buf, switch_size_t len, const char *format, ...)
208 {
209  va_list ap;
210  int ret;
211  va_start(ap, format);
212  ret = fspr_vsnprintf(buf, len, format, ap);
213  va_end(ap);
214  return ret;
215 }
216 
217 SWITCH_DECLARE(int) switch_vsnprintf(char *buf, switch_size_t len, const char *format, va_list ap)
218 {
219  return fspr_vsnprintf(buf, len, format, ap);
220 }
221 
222 SWITCH_DECLARE(char *) switch_copy_string(char *dst, const char *src, switch_size_t dst_size)
223 {
224  if (!dst)
225  return NULL;
226  if (!src) {
227  *dst = '\0';
228  return dst;
229  }
230  return fspr_cpystrn(dst, src, dst_size);
231 }
232 
233 /* thread read write lock functions */
234 
236 {
237  return fspr_thread_rwlock_create(rwlock, pool);
238 }
239 
241 {
242  return fspr_thread_rwlock_destroy(rwlock);
243 }
244 
246 {
247  return fspr_thread_rwlock_pool_get(rwlock);
248 }
249 
251 {
252  return fspr_thread_rwlock_rdlock(rwlock);
253 }
254 
256 {
257  return fspr_thread_rwlock_tryrdlock(rwlock);
258 }
259 
261 {
262  return fspr_thread_rwlock_wrlock(rwlock);
263 }
264 
266 {
267  return fspr_thread_rwlock_trywrlock(rwlock);
268 }
269 
271 {
272  int sanity = timeout * 2;
273 
274  while (sanity) {
276  return SWITCH_STATUS_SUCCESS;
277  }
278  sanity--;
279  switch_yield(500000);
280  }
281 
282  return SWITCH_STATUS_FALSE;
283 }
284 
285 
287 {
288  return fspr_thread_rwlock_unlock(rwlock);
289 }
290 
291 /* thread mutex functions */
292 
294 {
295 #ifdef WIN32
296  /* Old version of APR misunderstands mutexes. On Windows, mutexes are cross-process.
297  APR has no reason to not use critical sections instead of mutexes. */
298  if (flags == SWITCH_MUTEX_NESTED) flags = SWITCH_MUTEX_DEFAULT;
299 #endif
300  return fspr_thread_mutex_create(lock, flags, pool);
301 }
302 
304 {
305  return fspr_thread_mutex_destroy(lock);
306 }
307 
309 {
310  return fspr_thread_mutex_lock(lock);
311 }
312 
314 {
315  return fspr_thread_mutex_unlock(lock);
316 }
317 
319 {
320  return fspr_thread_mutex_trylock(lock);
321 }
322 
323 /* time function stubs */
324 
326 {
327 #if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS)
328  struct timespec ts;
329  clock_gettime(CLOCK_REALTIME, &ts);
330  return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000);
331 #else
332  return (switch_time_t) fspr_time_now();
333 #endif
334 }
335 
337 {
338  return fspr_time_exp_gmt_get((fspr_time_t *) result, (fspr_time_exp_t *) input);
339 }
340 
342 {
343  return fspr_time_exp_get((fspr_time_t *) result, (fspr_time_exp_t *) input);
344 }
345 
347 {
348  return fspr_time_exp_lt((fspr_time_exp_t *) result, input);
349 }
350 
352 {
353  return fspr_time_exp_tz((fspr_time_exp_t *) result, input, (fspr_int32_t) offs);
354 }
355 
357 {
358  return fspr_time_exp_gmt((fspr_time_exp_t *) result, input);
359 }
360 
362 {
363  return fspr_rfc822_date(date_str, t);
364 }
365 
367 {
368  return ((switch_time_t) (sec) * APR_USEC_PER_SEC + (switch_time_t) (usec));
369 }
370 
371 /* Thread condition locks */
372 
374 {
375  return fspr_thread_cond_create(cond, pool);
376 }
377 
379 {
380  return fspr_thread_cond_wait(cond, mutex);
381 }
382 
384 {
385  fspr_status_t st = fspr_thread_cond_timedwait(cond, mutex, timeout);
386 
387  if (st == APR_TIMEUP) {
389  }
390 
391  return st;
392 }
393 
395 {
396  return fspr_thread_cond_signal(cond);
397 }
398 
400 {
401  return fspr_thread_cond_broadcast(cond);
402 }
403 
405 {
406  return fspr_thread_cond_destroy(cond);
407 }
408 
409 /* file i/o stubs */
410 
411 SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t ** newf, const char *fname, int32_t flag, switch_fileperms_t perm,
413 {
414  return fspr_file_open(newf, fname, flag, perm, pool);
415 }
416 
418 {
419  fspr_status_t rv;
420  fspr_off_t off = (fspr_off_t) (*offset);
421  rv = fspr_file_seek(thefile, where, &off);
422  *offset = (int64_t) off;
423  return rv;
424 }
425 
426 SWITCH_DECLARE(switch_status_t) switch_file_copy(const char *from_path, const char *to_path, switch_fileperms_t perms, switch_memory_pool_t *pool)
427 {
428  return fspr_file_copy(from_path, to_path, perms, pool);
429 }
430 
431 
433 {
434  return fspr_file_close(thefile);
435 }
436 
438 {
439  return fspr_file_trunc(thefile, offset);
440 }
441 
443 {
444  return fspr_file_lock(thefile, type);
445 }
446 
447 SWITCH_DECLARE(switch_status_t) switch_file_rename(const char *from_path, const char *to_path, switch_memory_pool_t *pool)
448 {
449  return fspr_file_rename(from_path, to_path, pool);
450 }
451 
453 {
454  return fspr_file_remove(path, pool);
455 }
456 
458 {
459  return fspr_file_read(thefile, buf, nbytes);
460 }
461 
463 {
464  return fspr_file_write(thefile, buf, nbytes);
465 }
466 
467 SWITCH_DECLARE(int) switch_file_printf(switch_file_t *thefile, const char *format, ...)
468 {
469  va_list ap;
470  int ret;
471  char *data;
472 
473  va_start(ap, format);
474 
475  if ((ret = switch_vasprintf(&data, format, ap)) != -1) {
476  switch_size_t bytes = strlen(data);
477  switch_file_write(thefile, data, &bytes);
478  free(data);
479  }
480 
481  va_end(ap);
482 
483  return ret;
484 }
485 
487 {
488  return fspr_file_mktemp(thefile, templ, flags, pool);
489 }
490 
492 {
493  struct fspr_finfo_t finfo;
494  return fspr_file_info_get(&finfo, APR_FINFO_SIZE, thefile) == SWITCH_STATUS_SUCCESS ? (switch_size_t) finfo.size : 0;
495 }
496 
498 {
499  fspr_dir_t *dir_handle;
500  switch_memory_pool_t *our_pool = NULL;
501  switch_status_t status;
502 
503  if (!pool) {
504  switch_core_new_memory_pool(&our_pool);
505  pool = our_pool;
506  }
507 
508  if ((status = fspr_dir_open(&dir_handle, dirname, pool)) == APR_SUCCESS) {
509  fspr_dir_close(dir_handle);
510  }
511 
512  if (our_pool) {
514  }
515 
516  return status;
517 }
518 
520 {
521  int32_t wanted = APR_FINFO_TYPE;
522  switch_memory_pool_t *our_pool = NULL;
524  fspr_finfo_t info = { 0 };
525 
526  if (zstr(filename)) {
527  return status;
528  }
529 
530  if (!pool) {
531  switch_core_new_memory_pool(&our_pool);
532  }
533 
534  fspr_stat(&info, filename, wanted, pool ? pool : our_pool);
535  if (info.filetype != APR_NOFILE) {
536  status = SWITCH_STATUS_SUCCESS;
537  }
538 
539  if (our_pool) {
541  }
542 
543  return status;
544 }
545 
547 {
548  return fspr_dir_make(path, perm, pool);
549 }
550 
552 {
553  return fspr_dir_make_recursive(path, perm, pool);
554 }
555 
556 struct switch_dir {
557  fspr_dir_t *dir_handle;
558  fspr_finfo_t finfo;
559 };
560 
562 {
563  switch_status_t status;
564  switch_dir_t *dir = malloc(sizeof(*dir));
565 
566  if (!dir) {
567  *new_dir = NULL;
568  return SWITCH_STATUS_FALSE;
569  }
570 
571  memset(dir, 0, sizeof(*dir));
572  if ((status = fspr_dir_open(&(dir->dir_handle), dirname, pool)) == APR_SUCCESS) {
573  *new_dir = dir;
574  } else {
575  free(dir);
576  *new_dir = NULL;
577  }
578 
579  return status;
580 }
581 
583 {
584  switch_status_t status = fspr_dir_close(thedir->dir_handle);
585 
586  free(thedir);
587  return status;
588 }
589 
591 {
592  const char *name;
593  fspr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
594  uint32_t count = 0;
595 
596  fspr_dir_rewind(thedir->dir_handle);
597 
598  while (fspr_dir_read(&(thedir->finfo), finfo_flags, thedir->dir_handle) == SWITCH_STATUS_SUCCESS) {
599 
600  if (thedir->finfo.filetype != APR_REG && thedir->finfo.filetype != APR_LNK) {
601  continue;
602  }
603 
604  if (!(name = thedir->finfo.fname)) {
605  name = thedir->finfo.name;
606  }
607 
608  if (name) {
609  count++;
610  }
611  }
612 
613  fspr_dir_rewind(thedir->dir_handle);
614 
615  return count;
616 }
617 
619 {
620  const char *fname = NULL;
621  fspr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
622  const char *name;
623 
624  while (fspr_dir_read(&(thedir->finfo), finfo_flags, thedir->dir_handle) == SWITCH_STATUS_SUCCESS) {
625 
626  if (thedir->finfo.filetype != APR_REG && thedir->finfo.filetype != APR_LNK) {
627  continue;
628  }
629 
630  if (!(name = thedir->finfo.fname)) {
631  name = thedir->finfo.name;
632  }
633 
634  if (name) {
635  switch_copy_string(buf, name, len);
636  fname = buf;
637  break;
638  } else {
639  continue;
640  }
641  }
642  return fname;
643 }
644 
645 /* thread stubs */
646 
647 #ifndef WIN32
649  fspr_pool_t *pool;
650  pthread_attr_t attr;
651  int priority;
652 };
653 #else
654 /* this needs to be revisited when apr for windows supports thread priority settings */
655 /* search for WIN32 in this file */
656 struct fspr_threadattr_t {
657  fspr_pool_t *pool;
658  fspr_int32_t detach;
659  fspr_size_t stacksize;
660  int priority;
661 };
662 #endif
663 
664 
666 {
667  switch_status_t status;
668 
669  if ((status = fspr_threadattr_create(new_attr, pool)) == SWITCH_STATUS_SUCCESS) {
670 
671  (*new_attr)->priority = SWITCH_PRI_LOW;
672 
673  }
674 
675  return status;
676 }
677 
679 {
680  return fspr_threadattr_detach_set(attr, on);
681 }
682 
684 {
685  return fspr_threadattr_stacksize_set(attr, stacksize);
686 }
687 
689 {
690 
691  attr->priority = priority;
692 
693  return SWITCH_STATUS_SUCCESS;
694 }
695 
696 static char TT_KEY[] = "1";
697 
699  switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
700 {
701  switch_core_memory_pool_set_data(cont, "_in_thread", TT_KEY);
702  return fspr_thread_create(new_thread, attr, func, data, cont);
703 }
704 
706 {
707  return ((switch_interval_time_t)tvp->tv_sec * 1000000) + tvp->tv_usec / 1000;
708 }
709 
710 /* socket stubs */
711 
713 {
714  return fspr_os_sock_get(thesock, sock);
715 }
716 
718 {
719  return fspr_os_sock_put(sock, thesock, pool);
720 }
721 
723 {
724  return fspr_socket_addr_get(sa, (fspr_interface_e) remote, sock);
725 }
726 
728 {
729  return fspr_socket_create(new_sock, family, type, protocol, pool);
730 }
731 
733 {
734  return fspr_socket_shutdown(sock, (fspr_shutdown_how_e) how);
735 }
736 
738 {
739  return fspr_socket_close(sock);
740 }
741 
743 {
744  return fspr_socket_bind(sock, sa);
745 }
746 
748 {
749  return fspr_socket_listen(sock, backlog);
750 }
751 
753 {
754  return fspr_socket_accept(new_sock, sock, pool);
755 }
756 
758 {
759  return fspr_socket_connect(sock, sa);
760 }
761 
763 {
764  int status = SWITCH_STATUS_SUCCESS;
765  switch_size_t req = *len, wrote = 0, need = *len;
766  int to_count = 0;
767 
768  while ((wrote < req && status == SWITCH_STATUS_SUCCESS) || (need == 0 && status == SWITCH_STATUS_BREAK) || status == 730035 || status == 35) {
769  need = req - wrote;
770  status = fspr_socket_send(sock, buf + wrote, &need);
771  if (status == SWITCH_STATUS_BREAK || status == 730035 || status == 35) {
772  if (++to_count > 60000) {
773  status = SWITCH_STATUS_FALSE;
774  break;
775  }
776  switch_yield(10000);
777  } else {
778  to_count = 0;
779  }
780  wrote += need;
781  }
782 
783  *len = wrote;
784  return (switch_status_t)status;
785 }
786 
788 {
789  if (!sock || !buf || !len) {
790  return SWITCH_STATUS_GENERR;
791  }
792 
793  return fspr_socket_send(sock, buf, len);
794 }
795 
797  switch_size_t *len)
798 {
799  if (!where || !buf || !len || !*len) {
800  return SWITCH_STATUS_GENERR;
801  }
802  return fspr_socket_sendto(sock, where, flags, buf, len);
803 }
804 
806 {
807  int r;
808 
809  r = fspr_socket_recv(sock, buf, len);
810 
811  if (r == 35 || r == 730035) {
813  }
814 
815  return (switch_status_t)r;
816 }
817 
819 {
820  switch_sockaddr_t *new_sa;
821  unsigned short family = APR_INET;
822 
823  new_sa = fspr_pcalloc(pool, sizeof(fspr_sockaddr_t));
824  switch_assert(new_sa);
825  new_sa->pool = pool;
826 
827  new_sa->family = family;
828  new_sa->sa.sin.sin_family = family;
829 
830  new_sa->salen = sizeof(struct sockaddr_in);
831  new_sa->addr_str_len = 16;
832  new_sa->ipaddr_ptr = &(new_sa->sa.sin.sin_addr);
833  new_sa->ipaddr_len = sizeof(struct in_addr);
834 
835  *sa = new_sa;
836  return SWITCH_STATUS_SUCCESS;
837 }
838 
839 SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa, const char *hostname, int32_t family,
840  switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
841 {
842  return fspr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
843 }
844 
846 {
848  fspr_sockaddr_t *new_sa;
849  int family;
850 
851  if (!sa || !pool || !ip) {
853  }
854 
855  new_sa = fspr_pcalloc(pool, sizeof(fspr_sockaddr_t));
856  switch_assert(new_sa);
857 
858  new_sa->pool = pool;
859 
860 #if APR_HAVE_IPV6
861  if (strchr(ip, ':')) {
862  struct sockaddr_in6 sa6 = { 0 };
863 
864  family = APR_INET6;
865  inet_pton(family, ip, &(sa6.sin6_addr));
866  memcpy(&new_sa->sa, &sa6, sizeof(struct sockaddr_in6));
867  } else
868 #endif
869  {
870  struct sockaddr_in sa4 = { 0 };
871 
872  family = APR_INET;
873  inet_pton(family, ip, &(sa4.sin_addr));
874  memcpy(&new_sa->sa, &sa4, sizeof(struct sockaddr_in));
875  }
876 
877  new_sa->hostname = fspr_pstrdup(pool, ip);
878  new_sa->family = family;
879  new_sa->sa.sin.sin_family = family;
880  if (port) {
881  /* XXX IPv6: assumes sin_port and sin6_port at same offset */
882  new_sa->sa.sin.sin_port = htons(port);
883  new_sa->port = port;
884  }
885 
886  if (family == APR_INET) {
887  new_sa->salen = sizeof(struct sockaddr_in);
888  new_sa->addr_str_len = 16;
889  new_sa->ipaddr_ptr = &(new_sa->sa.sin.sin_addr);
890  new_sa->ipaddr_len = sizeof(struct in_addr);
891  }
892 #if APR_HAVE_IPV6
893  else if (family == APR_INET6) {
894  new_sa->salen = sizeof(struct sockaddr_in6);
895  new_sa->addr_str_len = 46;
896  new_sa->ipaddr_ptr = &(new_sa->sa.sin6.sin6_addr);
897  new_sa->ipaddr_len = sizeof(struct in6_addr);
898  }
899 #endif
900 
901  *sa = new_sa;
902 
903 end:
904  return status;
905 }
906 
908 {
909  if (opt == SWITCH_SO_TCP_KEEPIDLE) {
910 #if defined(TCP_KEEPIDLE)
911  int r = -10;
912  r = setsockopt(sock->socketdes, SOL_TCP, TCP_KEEPIDLE, (void *)&on, sizeof(on));
914 #else
915  return SWITCH_STATUS_NOTIMPL;
916 #endif
917  }
918 
919  if (opt == SWITCH_SO_TCP_KEEPINTVL) {
920 #if defined(TCP_KEEPINTVL)
921  int r = -10;
922  r = setsockopt(sock->socketdes, SOL_TCP, TCP_KEEPINTVL, (void *)&on, sizeof(on));
924 #else
925  return SWITCH_STATUS_NOTIMPL;
926 #endif
927  }
928 
929  return fspr_socket_opt_set(sock, opt, on);
930 }
931 
933 {
934  fspr_interval_time_t at = 0;
935  switch_status_t status = fspr_socket_timeout_get(sock, &at);
936  *t = at;
937 
938  return status;
939 }
940 
942 {
943  return fspr_socket_timeout_set(sock, t);
944 }
945 
947 {
948  return fspr_sockaddr_ip_get(addr, sa);
949 }
950 
952 {
953  return fspr_sockaddr_equal(sa1, sa2);
954 }
955 
957 {
958  return fspr_mcast_join(sock, join, iface, source);
959 }
960 
962 {
963  return fspr_mcast_hops(sock, ttl);
964 }
965 
967 {
968  return fspr_mcast_loopback(sock, opt);
969 }
970 
972 {
973  return fspr_mcast_interface(sock, iface);
974 }
975 
976 
977 /* socket functions */
978 
980 {
981  if (!in) {
982  return SWITCH_BLANK_STRING;
983  }
984 
985  memset(buf, 0, len);
986 
987  if (in->family == AF_INET) {
988  get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
989  return buf;
990  }
991 
992  get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen);
993  return buf;
994 }
995 
997 {
998  return fspr_socket_fd_get(sock);
999 }
1000 
1002 {
1003  return sa->port;
1004 }
1005 
1007 {
1008  return sa->family;
1009 }
1010 
1012 {
1013  return fspr_getnameinfo(hostname, sa, flags);
1014 }
1015 
1017 {
1018  return fspr_socket_atmark(sock, atmark);
1019 }
1020 
1022 {
1023  int r = SWITCH_STATUS_GENERR;
1024 
1025  if (from && sock && (r = fspr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
1026  from->port = ntohs(from->sa.sin.sin_port);
1027  /* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
1028  * from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
1029  */
1030  }
1031 
1032  if (r == 35 || r == 730035) {
1033  r = SWITCH_STATUS_BREAK;
1034  }
1035 
1036  return (switch_status_t)r;
1037 }
1038 
1039 /* poll stubs */
1040 
1042 {
1043  return fspr_pollset_create(pollset, size, pool, flags);
1044 }
1045 
1047 {
1048  if (!pollset || !descriptor) {
1049  return SWITCH_STATUS_FALSE;
1050  }
1051 
1052  return fspr_pollset_add((fspr_pollset_t *) pollset, (const fspr_pollfd_t *) descriptor);
1053 }
1054 
1056 {
1057  if (!pollset || !descriptor) {
1058  return SWITCH_STATUS_FALSE;
1059  }
1060 
1061  return fspr_pollset_remove((fspr_pollset_t *) pollset, (const fspr_pollfd_t *) descriptor);
1062 }
1063 
1065 {
1066  if (!pollfd || !sock) {
1067  return SWITCH_STATUS_FALSE;
1068  }
1069 
1070  if ((*pollfd = (switch_pollfd_t*)fspr_palloc(pool, sizeof(switch_pollfd_t))) == 0) {
1071  return SWITCH_STATUS_MEMERR;
1072  }
1073 
1074  memset(*pollfd, 0, sizeof(switch_pollfd_t));
1075 
1076  (*pollfd)->desc_type = (switch_pollset_type_t) APR_POLL_SOCKET;
1077  (*pollfd)->reqevents = flags;
1078  (*pollfd)->desc.s = sock;
1079  (*pollfd)->client_data = client_data;
1080 
1081  return SWITCH_STATUS_SUCCESS;
1082 }
1083 
1084 
1086 {
1087  fspr_status_t st = SWITCH_STATUS_FALSE;
1088 
1089  if (pollset) {
1090  st = fspr_pollset_poll((fspr_pollset_t *) pollset, timeout, num, (const fspr_pollfd_t **) descriptors);
1091 
1092  if (st == APR_TIMEUP) {
1093  st = SWITCH_STATUS_TIMEOUT;
1094  }
1095  }
1096 
1097  return st;
1098 }
1099 
1100 SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
1101 {
1102  fspr_status_t st = SWITCH_STATUS_FALSE;
1103 
1104  if (aprset) {
1105  st = fspr_poll((fspr_pollfd_t *) aprset, numsock, nsds, timeout);
1106 
1107  if (numsock == 1 && ((aprset[0].rtnevents & APR_POLLERR) || (aprset[0].rtnevents & APR_POLLHUP) || (aprset[0].rtnevents & APR_POLLNVAL))) {
1108  st = SWITCH_STATUS_GENERR;
1109  } else if (st == APR_TIMEUP) {
1110  st = SWITCH_STATUS_TIMEOUT;
1111  }
1112  }
1113 
1114  return st;
1115 }
1116 
1118 {
1119  switch_pollset_t *pollset;
1120 
1121  if (switch_pollset_create(&pollset, 1, pool, 0) != SWITCH_STATUS_SUCCESS) {
1122  return SWITCH_STATUS_GENERR;
1123  }
1124 
1125  if (switch_socket_create_pollfd(poll, sock, flags, sock, pool) != SWITCH_STATUS_SUCCESS) {
1126  return SWITCH_STATUS_GENERR;
1127  }
1128 
1129  if (switch_pollset_add(pollset, *poll) != SWITCH_STATUS_SUCCESS) {
1130  return SWITCH_STATUS_GENERR;
1131  }
1132 
1133  return SWITCH_STATUS_SUCCESS;
1134 }
1135 
1136 /* apr-util stubs */
1137 
1138 /* UUID Handling (apr-util) */
1139 
1141 {
1142 #ifndef WIN32
1143  uuid_unparse_lower(uuid->data, buffer);
1144 #else
1145  RPC_CSTR buf;
1146  UuidToString((const UUID *) uuid, &buf);
1147  strcpy(buffer, (const char *) buf);
1148  RpcStringFree(&buf);
1149 #endif
1150 }
1151 
1153 {
1155 #ifndef WIN32
1156  uuid_generate(uuid->data);
1157 #else
1158  UuidCreate((UUID *) uuid);
1159 #endif
1161 }
1162 
1164 {
1165 #ifndef WIN32
1166  if (uuid_parse(uuid_str, uuid->data)) {
1167  return SWITCH_STATUS_FALSE;
1168  }
1169  return SWITCH_STATUS_SUCCESS;
1170 #else
1171  return UuidFromString((RPC_CSTR) uuid_str, (UUID *) uuid);
1172 #endif
1173 }
1174 
1175 SWITCH_DECLARE(switch_status_t) switch_md5(unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen)
1176 {
1177 #if (defined(HAVE_LIBMD5) || defined(HAVE_LIBMD) || defined(HAVE_MD5INIT))
1178  MD5_CTX md5_context;
1179 
1180  MD5Init(&md5_context);
1181  MD5Update(&md5_context, input, inputLen);
1182  MD5Final(digest, &md5_context);
1183 
1184  return SWITCH_STATUS_SUCCESS;
1185 #elif defined(HAVE_LIBCRYPTO)
1186  #if OPENSSL_VERSION_NUMBER < 0x30000000
1187  MD5_CTX md5_context;
1188 
1189  MD5_Init(&md5_context);
1190  MD5_Update(&md5_context, input, inputLen);
1191  MD5_Final(digest, &md5_context);
1192  #else
1193  EVP_MD_CTX *md5_context;
1194 
1195  /* MD5_Init */
1196  md5_context = EVP_MD_CTX_new();
1197  EVP_DigestInit_ex(md5_context, EVP_md5(), NULL);
1198  /* MD5_Update */
1199  EVP_DigestUpdate(md5_context, input, inputLen);
1200  /* MD5_Final */
1201  EVP_DigestFinal_ex(md5_context, digest, NULL);
1202  EVP_MD_CTX_free(md5_context);
1203  #endif
1204 
1205  return SWITCH_STATUS_SUCCESS;
1206 #else
1207  return SWITCH_STATUS_NOTIMPL;
1208 #endif
1209 }
1210 
1212 {
1213  unsigned char digest[SWITCH_MD5_DIGESTSIZE];
1214  switch_status_t status = switch_md5(digest, input, inputLen);
1215  short i, x;
1216  uint8_t b;
1217 
1218  digest_str[SWITCH_MD5_DIGEST_STRING_SIZE - 1] = '\0';
1219 
1220  for (x = i = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
1221  b = (digest[x] >> 4) & 15;
1222  digest_str[i++] = b + (b > 9 ? 'a' - 10 : '0');
1223  b = digest[x] & 15;
1224  digest_str[i++] = b + (b > 9 ? 'a' - 10 : '0');
1225  }
1226  digest_str[i] = '\0';
1227 
1228  return status;
1229 }
1230 
1231 /* FIFO queues (apr-util) */
1232 
1234 {
1235  return switch_apr_queue_create(queue, queue_capacity, pool);
1236 }
1237 
1239 {
1240  return switch_apr_queue_size(queue);
1241 }
1242 
1244 {
1245  return switch_apr_queue_pop(queue, data);
1246 }
1247 
1249 {
1250  return switch_apr_queue_pop_timeout(queue, data, timeout);
1251 }
1252 
1254 {
1255  fspr_status_t s;
1256 
1257  do {
1258  s = switch_apr_queue_push(queue, data);
1259  } while (s == APR_EINTR);
1260 
1261  return s;
1262 }
1263 
1265 {
1266  return switch_apr_queue_trypop(queue, data);
1267 }
1268 
1270 {
1271  return switch_apr_queue_interrupt_all(queue);
1272 }
1273 
1275 {
1276  return switch_apr_queue_term(queue);
1277 }
1278 
1280 {
1281  fspr_status_t s;
1282 
1283  do {
1284  s = switch_apr_queue_trypush(queue, data);
1285  } while (s == APR_EINTR);
1286 
1287  return s;
1288 }
1289 
1290 SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap)
1291 {
1292 #ifdef HAVE_VASPRINTF
1293  return vasprintf(ret, fmt, ap);
1294 #else
1295  char *buf;
1296  int len;
1297  size_t buflen;
1298  va_list ap2;
1299  char *tmp = NULL;
1300 
1301 #ifdef _MSC_VER
1302 #if _MSC_VER >= 1500
1303  /* hack for incorrect assumption in msvc header files for code analysis */
1304  __analysis_assume(tmp);
1305 #endif
1306  ap2 = ap;
1307 #else
1308  va_copy(ap2, ap);
1309 #endif
1310 
1311  len = vsnprintf(tmp, 0, fmt, ap2);
1312 
1313  if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) {
1314  len = vsnprintf(buf, buflen, fmt, ap);
1315  *ret = buf;
1316  } else {
1317  *ret = NULL;
1318  len = -1;
1319  }
1320 
1321  va_end(ap2);
1322  return len;
1323 #endif
1324 }
1325 
1327 {
1328  return fspr_match_glob(pattern, (fspr_array_header_t **) result, pool);
1329 }
1330 
1331 /**
1332  * Create an anonymous pipe.
1333  * @param in The file descriptor to use as input to the pipe.
1334  * @param out The file descriptor to use as output from the pipe.
1335  * @param pool The pool to operate on.
1336  */
1338 {
1339  return fspr_file_pipe_create((fspr_file_t **) in, (fspr_file_t **) out, pool);
1340 }
1341 
1342 /**
1343  * Get the timeout value for a pipe or manipulate the blocking state.
1344  * @param thepipe The pipe we are getting a timeout for.
1345  * @param timeout The current timeout value in microseconds.
1346  */
1348 {
1349  return fspr_file_pipe_timeout_get((fspr_file_t *) thepipe, (fspr_interval_time_t *) timeout);
1350 }
1351 
1352 /**
1353  * Set the timeout value for a pipe or manipulate the blocking state.
1354  * @param thepipe The pipe we are setting a timeout on.
1355  * @param timeout The timeout value in microseconds. Values < 0 mean wait
1356  * forever, 0 means do not wait at all.
1357  */
1359 {
1360  return fspr_file_pipe_timeout_set((fspr_file_t *) thepipe, (fspr_interval_time_t) timeout);
1361 }
1362 
1363 
1364 /**
1365  * stop the current thread
1366  * @param thd The thread to stop
1367  * @param retval The return value to pass back to any thread that cares
1368  */
1370 {
1371  return fspr_thread_exit((fspr_thread_t *) thd, retval);
1372 }
1373 
1374 /**
1375  * block until the desired thread stops executing.
1376  * @param retval The return value from the dead thread.
1377  * @param thd The thread to join
1378  */
1380 {
1381  if ( !thd ) {
1382  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: Attempting to join thread that does not exist\n");
1383  return SWITCH_STATUS_FALSE;
1384  }
1385 
1386  return fspr_thread_join((fspr_status_t *) retval, (fspr_thread_t *) thd);
1387 }
1388 
1389 
1391 {
1392  return fspr_atomic_init((fspr_pool_t *) pool);
1393 }
1394 
1396 {
1397 #ifdef fspr_atomic_t
1398  return fspr_atomic_read((fspr_atomic_t *)mem);
1399 #else
1400  return fspr_atomic_read32((fspr_uint32_t *)mem);
1401 #endif
1402 }
1403 
1404 SWITCH_DECLARE(void) switch_atomic_set(volatile switch_atomic_t *mem, uint32_t val)
1405 {
1406 #ifdef fspr_atomic_t
1407  fspr_atomic_set((fspr_atomic_t *)mem, val);
1408 #else
1409  fspr_atomic_set32((fspr_uint32_t *)mem, val);
1410 #endif
1411 }
1412 
1413 SWITCH_DECLARE(void) switch_atomic_add(volatile switch_atomic_t *mem, uint32_t val)
1414 {
1415 #ifdef fspr_atomic_t
1416  fspr_atomic_add((fspr_atomic_t *)mem, val);
1417 #else
1418  fspr_atomic_add32((fspr_uint32_t *)mem, val);
1419 #endif
1420 }
1421 
1423 {
1424 #ifdef fspr_atomic_t
1425  fspr_atomic_inc((fspr_atomic_t *)mem);
1426 #else
1427  fspr_atomic_inc32((fspr_uint32_t *)mem);
1428 #endif
1429 }
1430 
1432 {
1433 #ifdef fspr_atomic_t
1434  return fspr_atomic_dec((fspr_atomic_t *)mem);
1435 #else
1436  return fspr_atomic_dec32((fspr_uint32_t *)mem);
1437 #endif
1438 }
1439 
1441 {
1442  return fspr_strerror(statcode, buf, bufsize);
1443 }
1444 
1445 /* For Emacs:
1446  * Local Variables:
1447  * mode:c
1448  * indent-tabs-mode:t
1449  * tab-width:4
1450  * c-basic-offset:4
1451  * End:
1452  * For VIM:
1453  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
1454  */
switch_status_t switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:757
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1238
#define SWITCH_MUTEX_DEFAULT
Definition: switch_apr.h:317
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
switch_status_t switch_directory_exists(const char *dirname, switch_memory_pool_t *pool)
Definition: switch_apr.c:497
switch_status_t switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input)
Definition: switch_apr.c:341
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:373
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:1001
switch_thread_priority_t
switch_status_t switch_file_write(switch_file_t *thefile, const void *buf, switch_size_t *nbytes)
Definition: switch_apr.c:462
switch_status_t switch_mutex_destroy(switch_mutex_t *lock)
Definition: switch_apr.c:303
#define SWITCH_CHANNEL_LOG
int switch_status_is_timeup(int status)
Definition: switch_apr.c:95
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:318
switch_status_t switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:356
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:742
switch_status_t switch_mcast_hops(switch_socket_t *sock, uint8_t ttl)
Definition: switch_apr.c:961
switch_status_t switch_socket_create_pollfd(switch_pollfd_t **pollfd, switch_socket_t *sock, int16_t flags, void *client_data, switch_memory_pool_t *pool)
Create a pollfd out of a socket.
Definition: switch_apr.c:1064
switch_status_t switch_queue_pop_timeout(switch_queue_t *queue, void **data, switch_interval_time_t timeout)
Definition: switch_apr.c:1248
static char TT_KEY[]
Definition: switch_apr.c:696
switch_bool_t
Definition: switch_types.h:437
const cJSON *const b
Definition: switch_cJSON.h:243
switch_status_t switch_atomic_init(switch_memory_pool_t *pool)
Definition: switch_apr.c:1390
char * switch_copy_string(char *dst, const char *src, switch_size_t dst_size)
Definition: switch_apr.c:222
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:683
switch_status_t switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t)
Definition: switch_apr.c:941
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
void switch_atomic_inc(volatile switch_atomic_t *mem)
Definition: switch_apr.c:1422
#define SWITCH_SO_TCP_KEEPIDLE
Definition: switch_apr.h:1000
switch_status_t switch_pollset_remove(switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
Definition: switch_apr.c:1055
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1264
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:1006
switch_interval_time_t switch_interval_time_from_timeval(struct timeval *tvp)
Definition: switch_apr.c:705
int switch_seek_where_t
Definition: switch_apr.h:688
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
Definition: switch_apr.c:121
switch_pollset_type_t
Definition: switch_apr.h:1298
switch_status_t switch_thread_cond_timedwait(switch_thread_cond_t *cond, switch_mutex_t *mutex, switch_interval_time_t timeout)
Definition: switch_apr.c:383
switch_status_t switch_file_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset)
Definition: switch_apr.c:417
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:346
#define SWITCH_MD5_DIGEST_STRING_SIZE
Definition: switch_apr.h:548
switch_status_t switch_thread_cond_wait(switch_thread_cond_t *cond, switch_mutex_t *mutex)
Definition: switch_apr.c:378
switch_status_t switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
Definition: switch_apr.c:805
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1243
char const int const cJSON_bool format
Definition: switch_cJSON.h:153
int switch_socket_fd_get(switch_socket_t *sock)
Definition: switch_apr.c:996
switch_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
Definition: switch_apr.c:202
struct switch_runtime runtime
Definition: switch_core.c:86
switch_status_t switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:240
switch_status_t switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, int32_t flags, char *buf, size_t *len)
Definition: switch_apr.c:1021
switch_hash_t * hash
Definition: switch_event.c:76
fspr_status_t switch_apr_queue_trypop(switch_apr_queue_t *queue, void **data)
fspr_status_t switch_apr_queue_term(switch_apr_queue_t *queue)
#define zstr(x)
Definition: switch_utils.h:314
switch_status_t switch_file_remove(const char *path, switch_memory_pool_t *pool)
Definition: switch_apr.c:452
int cJSON_bool fmt
Definition: switch_cJSON.h:150
int switch_atomic_dec(volatile switch_atomic_t *mem)
Definition: switch_apr.c:1431
switch_status_t switch_socket_addr_get(switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock)
Definition: switch_apr.c:722
switch_status_t switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str)
Definition: switch_apr.c:1163
switch_status_t switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len)
Definition: switch_apr.c:762
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:250
switch_status_t switch_file_rename(const char *from_path, const char *to_path, switch_memory_pool_t *pool)
Definition: switch_apr.c:447
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
int switch_file_printf(switch_file_t *thefile, const char *format,...)
Definition: switch_apr.c:467
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
switch_status_t switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
Definition: switch_apr.c:752
switch_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
Definition: switch_apr.c:678
int64_t switch_time_t
Definition: switch_apr.h:188
switch_byte_t switch_byte_t * buf
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
Definition: switch_utils.h:998
switch_status_t switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa)
Definition: switch_apr.c:946
switch_byte_t in
switch_status_t switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len)
Definition: switch_apr.c:796
switch_status_t switch_thread_cond_destroy(switch_thread_cond_t *cond)
Definition: switch_apr.c:404
switch_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:102
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_file_pipe_timeout_get(switch_file_t *thepipe, switch_interval_time_t *timeout)
Definition: switch_apr.c:1347
switch_status_t switch_dir_make(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:546
switch_status_t switch_sockaddr_create(switch_sockaddr_t **sa, switch_memory_pool_t *pool)
Definition: switch_apr.c:818
intptr_t switch_ssize_t
void switch_atomic_set(volatile switch_atomic_t *mem, uint32_t val)
Definition: switch_apr.c:1404
switch_status_t switch_socket_create_pollset(switch_pollfd_t **poll, switch_socket_t *sock, int16_t flags, switch_memory_pool_t *pool)
Create a set of file descriptors to poll from a socket.
Definition: switch_apr.c:1117
switch_status_t switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:255
switch_status_t switch_socket_listen(switch_socket_t *sock, int32_t backlog)
Definition: switch_apr.c:747
int switch_os_socket_t
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
#define SWITCH_BLANK_STRING
Definition: switch_types.h:48
struct fspr_pollset_t switch_pollset_t
Definition: switch_apr.h:1331
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:907
switch_status_t switch_md5(unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen)
Definition: switch_apr.c:1175
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1379
switch_status_t switch_file_pipe_create(switch_file_t **in, switch_file_t **out, switch_memory_pool_t *pool)
Definition: switch_apr.c:1337
uintptr_t switch_size_t
switch_status_t switch_socket_atmark(switch_socket_t *sock, int *atmark)
Definition: switch_apr.c:1016
uint16_t switch_port_t
switch_shutdown_how_e
Definition: switch_apr.h:1031
switch_status_t switch_time_exp_gmt_get(switch_time_t *result, switch_time_exp_t *input)
Definition: switch_apr.c:336
switch_byte_t switch_byte_t uint32_t buflen
switch_status_t switch_dir_open(switch_dir_t **new_dir, const char *dirname, switch_memory_pool_t *pool)
Definition: switch_apr.c:561
switch_status_t switch_mcast_interface(switch_socket_t *sock, switch_sockaddr_t *iface)
Definition: switch_apr.c:971
pthread_t switch_thread_id_t
Definition: switch_apr.h:51
switch_status_t switch_rfc822_date(char *date_str, switch_time_t t)
Definition: switch_apr.c:361
int64_t switch_interval_time_t
Definition: switch_apr.h:191
fspr_status_t switch_apr_queue_push(switch_apr_queue_t *queue, void *data)
switch_status_t switch_file_pipe_timeout_set(switch_file_t *thepipe, switch_interval_time_t timeout)
Definition: switch_apr.c:1358
int32_t switch_fileperms_t
Definition: switch_apr.h:687
switch_status_t switch_file_read(switch_file_t *thefile, void *buf, switch_size_t *nbytes)
Definition: switch_apr.c:457
const char * switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len)
Definition: switch_apr.c:618
uint32_t switch_atomic_t
Definition: switch_apr.h:380
switch_status_t switch_time_exp_tz(switch_time_exp_t *result, switch_time_t input, switch_int32_t offs)
Definition: switch_apr.c:351
pthread_attr_t attr
Definition: switch_apr.c:650
switch_status_t switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
Definition: switch_apr.c:1100
switch_mutex_t * mutex
char * switch_strerror(switch_status_t statcode, char *buf, switch_size_t bufsize)
Definition: switch_apr.c:1440
struct fspr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
fspr_status_t switch_apr_queue_pop(switch_apr_queue_t *queue, void **data)
fspr_status_t switch_apr_queue_trypush(switch_apr_queue_t *queue, void *data)
struct fspr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_status_t switch_sockaddr_new(switch_sockaddr_t **sa, const char *ip, switch_port_t port, switch_memory_pool_t *pool)
Definition: switch_apr.c:845
switch_status_t switch_thread_cond_signal(switch_thread_cond_t *cond)
Definition: switch_apr.c:394
switch_status_t switch_os_sock_get(switch_os_socket_t *thesock, switch_socket_t *sock)
Definition: switch_apr.c:712
void *(SWITCH_THREAD_FUNC * switch_thread_start_t)(switch_thread_t *, void *)
Definition: switch_apr.h:950
switch_status_t switch_mcast_loopback(switch_socket_t *sock, uint8_t opt)
Definition: switch_apr.c:966
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:519
char * ip
Definition: switch_msrp.c:60
void switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
Definition: switch_apr.c:1140
switch_status_t switch_socket_create(switch_socket_t **new_sock, int family, int type, int protocol, switch_memory_pool_t *pool)
Definition: switch_apr.c:727
switch_thread_rwlock_t * rwlock
Definition: switch_event.c:75
switch_status_t switch_file_mktemp(switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:486
switch_status_t
Common return values.
const char *const const char *const path
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
#define SWITCH_SO_TCP_KEEPINTVL
Definition: switch_apr.h:1001
fspr_pool_t * pool
Definition: switch_apr.c:649
switch_status_t switch_file_trunc(switch_file_t *thefile, int64_t offset)
Definition: switch_apr.c:437
int switch_vasprintf(char **ret, const char *fmt, va_list ap)
Definition: switch_apr.c:1290
switch_status_t switch_pollset_create(switch_pollset_t **pollset, uint32_t size, switch_memory_pool_t *pool, uint32_t flags)
Definition: switch_apr.c:1041
switch_status_t switch_dir_make_recursive(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:551
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:737
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
Definition: switch_apr.c:1269
void switch_core_memory_pool_set_data(switch_memory_pool_t *pool, const char *key, void *data)
switch_status_t switch_socket_shutdown(switch_socket_t *sock, switch_shutdown_how_e how)
Definition: switch_apr.c:732
char * get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen)
find the char representation of an ip adress
switch_status_t switch_pollset_poll(switch_pollset_t *pollset, switch_interval_time_t timeout, int32_t *num, const switch_pollfd_t **descriptors)
Definition: switch_apr.c:1085
Main Library Header.
switch_status_t switch_pollset_add(switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
Definition: switch_apr.c:1046
switch_status_t switch_file_copy(const char *from_path, const char *to_path, switch_fileperms_t perms, switch_memory_pool_t *pool)
Definition: switch_apr.c:426
#define SWITCH_DECLARE(type)
const char * filename
struct fspr_thread_cond_t switch_thread_cond_t
Definition: switch_apr.h:463
unsigned int switch_hashfunc_default(const char *key, switch_ssize_t *klen)
Definition: switch_apr.c:143
void switch_uuid_get(switch_uuid_t *uuid)
Definition: switch_apr.c:1152
struct fspr_file_t switch_file_t
Definition: switch_apr.h:685
switch_status_t switch_file_lock(switch_file_t *thefile, int type)
Definition: switch_apr.c:442
uint32_t switch_dir_count(switch_dir_t *thedir)
Definition: switch_apr.c:590
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1279
fspr_status_t switch_apr_queue_pop_timeout(switch_apr_queue_t *queue, void **data, fspr_interval_time_t timeout)
switch_status_t switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *pool)
Definition: switch_apr.c:1326
char * buffer
Definition: switch_cJSON.h:153
switch_status_t switch_socket_send_nonblock(switch_socket_t *sock, const char *buf, switch_size_t *len)
Definition: switch_apr.c:787
switch_status_t switch_queue_term(switch_queue_t *queue)
Definition: switch_apr.c:1274
char * get_addr6(char *buf, switch_size_t len, struct sockaddr_in6 *sa, socklen_t salen)
switch_status_t switch_mcast_join(switch_socket_t *sock, switch_sockaddr_t *join, switch_sockaddr_t *iface, switch_sockaddr_t *source)
Definition: switch_apr.c:956
char * key
Definition: switch_msrp.c:64
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1253
switch_mutex_t * uuid_mutex
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:235
switch_status_t switch_thread_exit(switch_thread_t *thd, switch_status_t retval)
Definition: switch_apr.c:1369
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
Definition: switch_apr.c:150
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:665
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
Definition: switch_apr.c:698
uint32_t switch_atomic_read(volatile switch_atomic_t *mem)
Definition: switch_apr.c:1395
switch_time_t switch_time_make(switch_time_t sec, int32_t usec)
Definition: switch_apr.c:366
unsigned char data[16]
Definition: switch_apr.h:540
int count
Definition: switch_cJSON.h:204
struct fspr_pool_t switch_memory_pool_t
const char *const name
Definition: switch_cJSON.h:250
switch_status_t switch_thread_rwlock_trywrlock_timeout(switch_thread_rwlock_t *rwlock, int timeout)
Definition: switch_apr.c:270
switch_status_t switch_file_open(switch_file_t **newf, const char *fname, int32_t flag, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:411
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:979
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1233
switch_status_t switch_thread_cond_broadcast(switch_thread_cond_t *cond)
Definition: switch_apr.c:399
int switch_vsnprintf(char *buf, switch_size_t len, const char *format, va_list ap)
Definition: switch_apr.c:217
void switch_atomic_add(volatile switch_atomic_t *mem, uint32_t val)
Definition: switch_apr.c:1413
int switch_thread_equal(switch_thread_id_t tid1, switch_thread_id_t tid2)
Compare two thread ids.
Definition: switch_apr.c:111
struct fspr_socket_t switch_socket_t
Definition: switch_apr.h:1026
fspr_status_t switch_apr_queue_interrupt_all(switch_apr_queue_t *queue)
switch_status_t switch_getnameinfo(char **hostname, switch_sockaddr_t *sa, int32_t flags)
Definition: switch_apr.c:1011
switch_status_t switch_file_close(switch_file_t *thefile)
Definition: switch_apr.c:432
#define switch_assert(expr)
struct fspr_thread_t switch_thread_t
Definition: switch_apr.h:941
fspr_dir_t * dir_handle
Definition: switch_apr.c:557
switch_time_t switch_time_now(void)
Definition: switch_apr.c:325
switch_status_t switch_sockaddr_info_get(switch_sockaddr_t **sa, const char *hostname, int32_t family, switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:839
switch_status_t switch_socket_timeout_get(switch_socket_t *sock, switch_interval_time_t *t)
Definition: switch_apr.c:932
struct fspr_thread_rwlock_t switch_thread_rwlock_t
Definition: switch_apr.h:436
int switch_snprintf(char *buf, switch_size_t len, const char *format,...)
Definition: switch_apr.c:207
unsigned int switch_apr_queue_size(switch_apr_queue_t *queue)
switch_memory_pool_t * switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:245
memset(buf, 0, buflen)
fspr_finfo_t finfo
Definition: switch_apr.c:558
switch_status_t switch_os_sock_put(switch_socket_t **sock, switch_os_socket_t *thesock, switch_memory_pool_t *pool)
Definition: switch_apr.c:717
fspr_status_t switch_apr_queue_create(switch_apr_queue_t **q, unsigned int queue_capacity, fspr_pool_t *a)
#define SWITCH_MD5_DIGESTSIZE
Definition: switch_apr.h:547
switch_size_t switch_file_get_size(switch_file_t *thefile)
Definition: switch_apr.c:491
switch_status_t switch_md5_string(char digest_str[SWITCH_MD5_DIGEST_STRING_SIZE], const void *input, switch_size_t inputLen)
Definition: switch_apr.c:1211
switch_status_t switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:265
switch_status_t switch_dir_close(switch_dir_t *thedir)
Definition: switch_apr.c:582
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:688
int switch_sockaddr_equal(const switch_sockaddr_t *sa1, const switch_sockaddr_t *sa2)
Definition: switch_apr.c:951
int32_t switch_int32_t