FreeSWITCH API Documentation  1.7.0
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 
40 /* apr headers*/
41 #include <apr.h>
42 #include <apr_atomic.h>
43 #include <apr_pools.h>
44 #include <apr_hash.h>
45 #include <apr_network_io.h>
46 #include <apr_errno.h>
47 #include <apr_thread_proc.h>
48 #include <apr_portable.h>
49 #include <apr_thread_mutex.h>
50 #include <apr_thread_cond.h>
51 #include <apr_thread_rwlock.h>
52 #include <apr_file_io.h>
53 #include <apr_poll.h>
54 #include <apr_strings.h>
55 #define APR_WANT_STDIO
56 #define APR_WANT_STRFUNC
57 #include <apr_want.h>
58 #include <apr_file_info.h>
59 #include <apr_fnmatch.h>
60 #include <apr_tables.h>
61 
62 /* apr_vformatter_buff_t definition*/
63 #include <apr_lib.h>
64 
65 /* apr-util headers */
66 #include <apr_queue.h>
67 #include <apr_uuid.h>
68 #include <apr_md5.h>
69 
70 /* apr stubs */
71 
73 {
74  return APR_STATUS_IS_TIMEUP(status);
75 }
76 
77 /* Memory Pools */
78 
80 {
81 #ifndef WIN32
82  return apr_os_thread_current();
83 #else
84  return (switch_thread_id_t) (GetCurrentThreadId());
85 #endif
86 }
87 
89 {
90 #ifdef WIN32
91  return (tid1 == tid2);
92 #else
93  return apr_os_thread_equal(tid1, tid2);
94 #endif
95 
96 }
97 
98 SWITCH_DECLARE(unsigned int) switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
99 {
100  unsigned int hash = 0;
101  const unsigned char *key = (const unsigned char *) char_key;
102  const unsigned char *p;
103  apr_ssize_t i;
104 
105  if (*klen == APR_HASH_KEY_STRING) {
106  for (p = key; *p; p++) {
107  hash = hash * 33 + tolower(*p);
108  }
109  *klen = p - key;
110  } else {
111  for (p = key, i = *klen; i; i--, p++) {
112  hash = hash * 33 + tolower(*p);
113  }
114  }
115 
116  return hash;
117 }
118 
119 
120 SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen)
121 {
122  return apr_hashfunc_default(key, klen);
123 }
124 
125 /* string functions */
126 
128 {
129  const char *p = format;
130 
131  if (!p)
132  return SWITCH_STATUS_FALSE;
133 
134  while (*p) {
135  if (*p == '%') {
136  switch (*(++p)) {
137  case 'C':
138  case 'D':
139  case 'r':
140  case 'R':
141  case 'T':
142  case 'e':
143  case 'a':
144  case 'A':
145  case 'b':
146  case 'B':
147  case 'c':
148  case 'd':
149  case 'H':
150  case 'I':
151  case 'j':
152  case 'm':
153  case 'M':
154  case 'p':
155  case 'S':
156  case 'U':
157  case 'w':
158  case 'W':
159  case 'x':
160  case 'X':
161  case 'y':
162  case 'Y':
163  case 'z':
164  case 'Z':
165  case '%':
166  p++;
167  continue;
168  case '\0':
169  default:
170  return SWITCH_STATUS_FALSE;
171  }
172  }
173  p++;
174  }
175 
176  return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
177 }
178 
180 {
181  return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
182 }
183 
184 SWITCH_DECLARE(int) switch_snprintf(char *buf, switch_size_t len, const char *format, ...)
185 {
186  va_list ap;
187  int ret;
188  va_start(ap, format);
189  ret = apr_vsnprintf(buf, len, format, ap);
190  va_end(ap);
191  return ret;
192 }
193 
194 SWITCH_DECLARE(int) switch_vsnprintf(char *buf, switch_size_t len, const char *format, va_list ap)
195 {
196  return apr_vsnprintf(buf, len, format, ap);
197 }
198 
199 SWITCH_DECLARE(char *) switch_copy_string(char *dst, const char *src, switch_size_t dst_size)
200 {
201  if (!dst)
202  return NULL;
203  if (!src) {
204  *dst = '\0';
205  return dst;
206  }
207  return apr_cpystrn(dst, src, dst_size);
208 }
209 
210 /* thread read write lock functions */
211 
213 {
214  return apr_thread_rwlock_create(rwlock, pool);
215 }
216 
218 {
219  return apr_thread_rwlock_destroy(rwlock);
220 }
221 
223 {
224  return apr_thread_rwlock_pool_get(rwlock);
225 }
226 
228 {
229  return apr_thread_rwlock_rdlock(rwlock);
230 }
231 
233 {
234  return apr_thread_rwlock_tryrdlock(rwlock);
235 }
236 
238 {
239  return apr_thread_rwlock_wrlock(rwlock);
240 }
241 
243 {
244  return apr_thread_rwlock_trywrlock(rwlock);
245 }
246 
248 {
249  int sanity = timeout * 2;
250 
251  while (sanity) {
253  return SWITCH_STATUS_SUCCESS;
254  }
255  sanity--;
256  switch_yield(500000);
257  }
258 
259  return SWITCH_STATUS_FALSE;
260 }
261 
262 
264 {
265  return apr_thread_rwlock_unlock(rwlock);
266 }
267 
268 /* thread mutex functions */
269 
271 {
272 #ifdef WIN32
273  /* Old version of APR misunderstands mutexes. On Windows, mutexes are cross-process.
274  APR has no reason to not use critical sections instead of mutexes. */
275  if (flags == SWITCH_MUTEX_NESTED) flags = SWITCH_MUTEX_DEFAULT;
276 #endif
277  return apr_thread_mutex_create(lock, flags, pool);
278 }
279 
281 {
282  return apr_thread_mutex_destroy(lock);
283 }
284 
286 {
287  return apr_thread_mutex_lock(lock);
288 }
289 
291 {
292  return apr_thread_mutex_unlock(lock);
293 }
294 
296 {
297  return apr_thread_mutex_trylock(lock);
298 }
299 
300 /* time function stubs */
301 
303 {
304 #if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS)
305  struct timespec ts;
306  clock_gettime(CLOCK_REALTIME, &ts);
307  return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000);
308 #else
309  return (switch_time_t) apr_time_now();
310 #endif
311 }
312 
314 {
315  return apr_time_exp_gmt_get((apr_time_t *) result, (apr_time_exp_t *) input);
316 }
317 
319 {
320  return apr_time_exp_get((apr_time_t *) result, (apr_time_exp_t *) input);
321 }
322 
324 {
325  return apr_time_exp_lt((apr_time_exp_t *) result, input);
326 }
327 
329 {
330  return apr_time_exp_tz((apr_time_exp_t *) result, input, (apr_int32_t) offs);
331 }
332 
334 {
335  return apr_time_exp_gmt((apr_time_exp_t *) result, input);
336 }
337 
339 {
340  return apr_rfc822_date(date_str, t);
341 }
342 
344 {
345  return ((switch_time_t) (sec) * APR_USEC_PER_SEC + (switch_time_t) (usec));
346 }
347 
348 /* Thread condition locks */
349 
351 {
352  return apr_thread_cond_create(cond, pool);
353 }
354 
356 {
357  return apr_thread_cond_wait(cond, mutex);
358 }
359 
361 {
362  apr_status_t st = apr_thread_cond_timedwait(cond, mutex, timeout);
363 
364  if (st == APR_TIMEUP) {
366  }
367 
368  return st;
369 }
370 
372 {
373  return apr_thread_cond_signal(cond);
374 }
375 
377 {
378  return apr_thread_cond_broadcast(cond);
379 }
380 
382 {
383  return apr_thread_cond_destroy(cond);
384 }
385 
386 /* file i/o stubs */
387 
388 SWITCH_DECLARE(switch_status_t) switch_file_open(switch_file_t ** newf, const char *fname, int32_t flag, switch_fileperms_t perm,
390 {
391  return apr_file_open(newf, fname, flag, perm, pool);
392 }
393 
395 {
396  apr_status_t rv;
397  apr_off_t off = (apr_off_t) (*offset);
398  rv = apr_file_seek(thefile, where, &off);
399  *offset = (int64_t) off;
400  return rv;
401 }
402 
403 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)
404 {
405  return apr_file_copy(from_path, to_path, perms, pool);
406 }
407 
408 
410 {
411  return apr_file_close(thefile);
412 }
413 
415 {
416  return apr_file_trunc(thefile, offset);
417 }
418 
420 {
421  return apr_file_lock(thefile, type);
422 }
423 
424 SWITCH_DECLARE(switch_status_t) switch_file_rename(const char *from_path, const char *to_path, switch_memory_pool_t *pool)
425 {
426  return apr_file_rename(from_path, to_path, pool);
427 }
428 
430 {
431  return apr_file_remove(path, pool);
432 }
433 
435 {
436  return apr_file_read(thefile, buf, nbytes);
437 }
438 
440 {
441  return apr_file_write(thefile, buf, nbytes);
442 }
443 
444 SWITCH_DECLARE(int) switch_file_printf(switch_file_t *thefile, const char *format, ...)
445 {
446  va_list ap;
447  int ret;
448  char *data;
449 
450  va_start(ap, format);
451 
452  if ((ret = switch_vasprintf(&data, format, ap)) != -1) {
453  switch_size_t bytes = strlen(data);
454  switch_file_write(thefile, data, &bytes);
455  free(data);
456  }
457 
458  va_end(ap);
459 
460  return ret;
461 }
462 
464 {
465  return apr_file_mktemp(thefile, templ, flags, pool);
466 }
467 
469 {
470  struct apr_finfo_t finfo;
471  return apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile) == SWITCH_STATUS_SUCCESS ? (switch_size_t) finfo.size : 0;
472 }
473 
475 {
476  apr_dir_t *dir_handle;
477  switch_memory_pool_t *our_pool = NULL;
478  switch_status_t status;
479 
480  if (!pool) {
481  switch_core_new_memory_pool(&our_pool);
482  pool = our_pool;
483  }
484 
485  if ((status = apr_dir_open(&dir_handle, dirname, pool)) == APR_SUCCESS) {
486  apr_dir_close(dir_handle);
487  }
488 
489  if (our_pool) {
491  }
492 
493  return status;
494 }
495 
497 {
498  int32_t wanted = APR_FINFO_TYPE;
499  switch_memory_pool_t *our_pool = NULL;
501  apr_finfo_t info = { 0 };
502 
503  if (zstr(filename)) {
504  return status;
505  }
506 
507  if (!pool) {
508  switch_core_new_memory_pool(&our_pool);
509  }
510 
511  apr_stat(&info, filename, wanted, pool ? pool : our_pool);
512  if (info.filetype != APR_NOFILE) {
513  status = SWITCH_STATUS_SUCCESS;
514  }
515 
516  if (our_pool) {
518  }
519 
520  return status;
521 }
522 
524 {
525  return apr_dir_make(path, perm, pool);
526 }
527 
529 {
530  return apr_dir_make_recursive(path, perm, pool);
531 }
532 
533 struct switch_dir {
534  apr_dir_t *dir_handle;
535  apr_finfo_t finfo;
536 };
537 
539 {
540  switch_status_t status;
541  switch_dir_t *dir = malloc(sizeof(*dir));
542 
543  if (!dir) {
544  *new_dir = NULL;
545  return SWITCH_STATUS_FALSE;
546  }
547 
548  memset(dir, 0, sizeof(*dir));
549  if ((status = apr_dir_open(&(dir->dir_handle), dirname, pool)) == APR_SUCCESS) {
550  *new_dir = dir;
551  } else {
552  free(dir);
553  *new_dir = NULL;
554  }
555 
556  return status;
557 }
558 
560 {
561  switch_status_t status = apr_dir_close(thedir->dir_handle);
562 
563  free(thedir);
564  return status;
565 }
566 
568 {
569  const char *name;
570  apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
571  uint32_t count = 0;
572 
573  apr_dir_rewind(thedir->dir_handle);
574 
575  while (apr_dir_read(&(thedir->finfo), finfo_flags, thedir->dir_handle) == SWITCH_STATUS_SUCCESS) {
576 
577  if (thedir->finfo.filetype != APR_REG && thedir->finfo.filetype != APR_LNK) {
578  continue;
579  }
580 
581  if (!(name = thedir->finfo.fname)) {
582  name = thedir->finfo.name;
583  }
584 
585  if (name) {
586  count++;
587  }
588  }
589 
590  apr_dir_rewind(thedir->dir_handle);
591 
592  return count;
593 }
594 
596 {
597  const char *fname = NULL;
598  apr_int32_t finfo_flags = APR_FINFO_DIRENT | APR_FINFO_TYPE | APR_FINFO_NAME;
599  const char *name;
600 
601  while (apr_dir_read(&(thedir->finfo), finfo_flags, thedir->dir_handle) == SWITCH_STATUS_SUCCESS) {
602 
603  if (thedir->finfo.filetype != APR_REG && thedir->finfo.filetype != APR_LNK) {
604  continue;
605  }
606 
607  if (!(name = thedir->finfo.fname)) {
608  name = thedir->finfo.name;
609  }
610 
611  if (name) {
612  switch_copy_string(buf, name, len);
613  fname = buf;
614  break;
615  } else {
616  continue;
617  }
618  }
619  return fname;
620 }
621 
622 /* thread stubs */
623 
624 #ifndef WIN32
626  apr_pool_t *pool;
627  pthread_attr_t attr;
628  int priority;
629 };
630 #else
631 /* this needs to be revisited when apr for windows supports thread priority settings */
632 /* search for WIN32 in this file */
633 struct apr_threadattr_t {
634  apr_pool_t *pool;
635  apr_int32_t detach;
636  apr_size_t stacksize;
637  int priority;
638 };
639 #endif
640 
641 
643 {
644  switch_status_t status;
645 
646  if ((status = apr_threadattr_create(new_attr, pool)) == SWITCH_STATUS_SUCCESS) {
647 
648  (*new_attr)->priority = SWITCH_PRI_LOW;
649 
650  }
651 
652  return status;
653 }
654 
656 {
657  return apr_threadattr_detach_set(attr, on);
658 }
659 
661 {
662  return apr_threadattr_stacksize_set(attr, stacksize);
663 }
664 
666 {
667 
668  attr->priority = priority;
669 
670  return SWITCH_STATUS_SUCCESS;
671 }
672 
673 static char TT_KEY[] = "1";
674 
676  switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
677 {
678  switch_core_memory_pool_set_data(cont, "_in_thread", TT_KEY);
679  return apr_thread_create(new_thread, attr, func, data, cont);
680 }
681 
683 {
684  return ((switch_interval_time_t)tvp->tv_sec * 1000000) + tvp->tv_usec / 1000;
685 }
686 
687 /* socket stubs */
688 
690 {
691  return apr_os_sock_get(thesock, sock);
692 }
693 
695 {
696  return apr_os_sock_put(sock, thesock, pool);
697 }
698 
700 {
701  return apr_socket_addr_get(sa, (apr_interface_e) remote, sock);
702 }
703 
705 {
706  return apr_socket_create(new_sock, family, type, protocol, pool);
707 }
708 
710 {
711  return apr_socket_shutdown(sock, (apr_shutdown_how_e) how);
712 }
713 
715 {
716  return apr_socket_close(sock);
717 }
718 
720 {
721  return apr_socket_bind(sock, sa);
722 }
723 
725 {
726  return apr_socket_listen(sock, backlog);
727 }
728 
730 {
731  return apr_socket_accept(new_sock, sock, pool);
732 }
733 
735 {
736  return apr_socket_connect(sock, sa);
737 }
738 
740 {
741  int status = SWITCH_STATUS_SUCCESS;
742  switch_size_t req = *len, wrote = 0, need = *len;
743  int to_count = 0;
744 
745  while ((wrote < req && status == SWITCH_STATUS_SUCCESS) || (need == 0 && status == SWITCH_STATUS_BREAK) || status == 730035 || status == 35) {
746  need = req - wrote;
747  status = apr_socket_send(sock, buf + wrote, &need);
748  if (status == SWITCH_STATUS_BREAK || status == 730035 || status == 35) {
749  if (++to_count > 60000) {
750  status = SWITCH_STATUS_FALSE;
751  break;
752  }
753  switch_yield(10000);
754  } else {
755  to_count = 0;
756  }
757  wrote += need;
758  }
759 
760  *len = wrote;
761  return (switch_status_t)status;
762 }
763 
765 {
766  if (!sock || !buf || !len) {
767  return SWITCH_STATUS_GENERR;
768  }
769 
770  return apr_socket_send(sock, buf, len);
771 }
772 
774  switch_size_t *len)
775 {
776  if (!where || !buf || !len || !*len) {
777  return SWITCH_STATUS_GENERR;
778  }
779  return apr_socket_sendto(sock, where, flags, buf, len);
780 }
781 
783 {
784  int r;
785 
786  r = apr_socket_recv(sock, buf, len);
787 
788  if (r == 35 || r == 730035) {
790  }
791 
792  return (switch_status_t)r;
793 }
794 
796 {
797  switch_sockaddr_t *new_sa;
798  unsigned short family = APR_INET;
799 
800  new_sa = apr_pcalloc(pool, sizeof(apr_sockaddr_t));
801  switch_assert(new_sa);
802  new_sa->pool = pool;
803  memset(new_sa, 0, sizeof(*new_sa));
804 
805  new_sa->family = family;
806  new_sa->sa.sin.sin_family = family;
807 
808  new_sa->salen = sizeof(struct sockaddr_in);
809  new_sa->addr_str_len = 16;
810  new_sa->ipaddr_ptr = &(new_sa->sa.sin.sin_addr);
811  new_sa->ipaddr_len = sizeof(struct in_addr);
812 
813  *sa = new_sa;
814  return SWITCH_STATUS_SUCCESS;
815 }
816 
817 SWITCH_DECLARE(switch_status_t) switch_sockaddr_info_get(switch_sockaddr_t ** sa, const char *hostname, int32_t family,
818  switch_port_t port, int32_t flags, switch_memory_pool_t *pool)
819 {
820  return apr_sockaddr_info_get(sa, hostname, family, port, flags, pool);
821 }
822 
824 {
825  if (opt == SWITCH_SO_TCP_KEEPIDLE) {
826  int r = -10;
827 
828 #if defined(TCP_KEEPIDLE)
829  r = setsockopt(jsock->client_socket, SOL_TCP, TCP_KEEPIDLE, (void *)&on, sizeof(on));
830 #endif
831  if (r == -10) {
832  return SWITCH_STATUS_NOTIMPL;
833  }
834 
835 
837  }
838 
839  if (opt == SWITCH_SO_TCP_KEEPINTVL) {
840  int r = -10;
841 
842 #if defined(TCP_KEEPINTVL)
843  r = setsockopt(jsock->client_socket, SOL_TCP, TCP_KEEPINTVL, (void *)&on, sizeof(on));
844 #endif
845 
846  if (r == -10) {
847  return SWITCH_STATUS_NOTIMPL;
848  }
849 
851  }
852 
853  return apr_socket_opt_set(sock, opt, on);
854 }
855 
857 {
858  return apr_socket_timeout_set(sock, t);
859 }
860 
862 {
863  return apr_sockaddr_ip_get(addr, sa);
864 }
865 
867 {
868  return apr_sockaddr_equal(sa1, sa2);
869 }
870 
872 {
873  return apr_mcast_join(sock, join, iface, source);
874 }
875 
877 {
878  return apr_mcast_hops(sock, ttl);
879 }
880 
882 {
883  return apr_mcast_loopback(sock, opt);
884 }
885 
887 {
888  return apr_mcast_interface(sock, iface);
889 }
890 
891 
892 /* socket functions */
893 
895 {
896  if (!in) {
897  return SWITCH_BLANK_STRING;
898  }
899 
900  memset(buf, 0, len);
901 
902  if (in->family == AF_INET) {
903  get_addr(buf, len, (struct sockaddr *) &in->sa, in->salen);
904  return buf;
905  }
906 
907  get_addr6(buf, len, (struct sockaddr_in6 *) &in->sa, in->salen);
908  return buf;
909 }
910 
912 {
913  return apr_socket_fd_get(sock);
914 }
915 
917 {
918  return sa->port;
919 }
920 
922 {
923  return sa->family;
924 }
925 
927 {
928  return apr_getnameinfo(hostname, sa, flags);
929 }
930 
932 {
933  return apr_socket_atmark(sock, atmark);
934 }
935 
937 {
938  int r = SWITCH_STATUS_GENERR;
939 
940  if (from && sock && (r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) {
941  from->port = ntohs(from->sa.sin.sin_port);
942  /* from->ipaddr_ptr = &(from->sa.sin.sin_addr);
943  * from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr);
944  */
945  }
946 
947  if (r == 35 || r == 730035) {
949  }
950 
951  return (switch_status_t)r;
952 }
953 
954 /* poll stubs */
955 
957 {
958  return apr_pollset_create(pollset, size, pool, flags);
959 }
960 
962 {
963  if (!pollset || !descriptor) {
964  return SWITCH_STATUS_FALSE;
965  }
966 
967  return apr_pollset_add((apr_pollset_t *) pollset, (const apr_pollfd_t *) descriptor);
968 }
969 
971 {
972  if (!pollset || !descriptor) {
973  return SWITCH_STATUS_FALSE;
974  }
975 
976  return apr_pollset_remove((apr_pollset_t *) pollset, (const apr_pollfd_t *) descriptor);
977 }
978 
980 {
981  if (!pollfd || !sock) {
982  return SWITCH_STATUS_FALSE;
983  }
984 
985  if ((*pollfd = (switch_pollfd_t*)apr_palloc(pool, sizeof(switch_pollfd_t))) == 0) {
986  return SWITCH_STATUS_MEMERR;
987  }
988 
989  memset(*pollfd, 0, sizeof(switch_pollfd_t));
990 
991  (*pollfd)->desc_type = (switch_pollset_type_t) APR_POLL_SOCKET;
992  (*pollfd)->reqevents = flags;
993  (*pollfd)->desc.s = sock;
994  (*pollfd)->client_data = client_data;
995 
996  return SWITCH_STATUS_SUCCESS;
997 }
998 
999 
1001 {
1002  apr_status_t st = SWITCH_STATUS_FALSE;
1003 
1004  if (pollset) {
1005  st = apr_pollset_poll((apr_pollset_t *) pollset, timeout, num, (const apr_pollfd_t **) descriptors);
1006 
1007  if (st == APR_TIMEUP) {
1008  st = SWITCH_STATUS_TIMEOUT;
1009  }
1010  }
1011 
1012  return st;
1013 }
1014 
1015 SWITCH_DECLARE(switch_status_t) switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
1016 {
1017  apr_status_t st = SWITCH_STATUS_FALSE;
1018 
1019  if (aprset) {
1020  st = apr_poll((apr_pollfd_t *) aprset, numsock, nsds, timeout);
1021 
1022  if (numsock == 1 && ((aprset[0].rtnevents & APR_POLLERR) || (aprset[0].rtnevents & APR_POLLHUP) || (aprset[0].rtnevents & APR_POLLNVAL))) {
1023  st = SWITCH_STATUS_GENERR;
1024  } else if (st == APR_TIMEUP) {
1025  st = SWITCH_STATUS_TIMEOUT;
1026  }
1027  }
1028 
1029  return st;
1030 }
1031 
1033 {
1034  switch_pollset_t *pollset;
1035 
1036  if (switch_pollset_create(&pollset, 1, pool, 0) != SWITCH_STATUS_SUCCESS) {
1037  return SWITCH_STATUS_GENERR;
1038  }
1039 
1040  if (switch_socket_create_pollfd(poll, sock, flags, sock, pool) != SWITCH_STATUS_SUCCESS) {
1041  return SWITCH_STATUS_GENERR;
1042  }
1043 
1044  if (switch_pollset_add(pollset, *poll) != SWITCH_STATUS_SUCCESS) {
1045  return SWITCH_STATUS_GENERR;
1046  }
1047 
1048  return SWITCH_STATUS_SUCCESS;
1049 }
1050 
1051 /* apr-util stubs */
1052 
1053 /* UUID Handling (apr-util) */
1054 
1055 SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
1056 {
1057 #ifndef WIN32
1058  apr_uuid_format(buffer, (const apr_uuid_t *) uuid);
1059 #else
1060  RPC_CSTR buf;
1061  UuidToString((const UUID *) uuid, &buf);
1062  strcpy(buffer, (const char *) buf);
1063  RpcStringFree(&buf);
1064 #endif
1065 }
1066 
1068 {
1070 #ifndef WIN32
1071  apr_uuid_get((apr_uuid_t *) uuid);
1072 #else
1073  UuidCreate((UUID *) uuid);
1074 #endif
1076 }
1077 
1079 {
1080 #ifndef WIN32
1081  return apr_uuid_parse((apr_uuid_t *) uuid, uuid_str);
1082 #else
1083  return UuidFromString((RPC_CSTR) uuid_str, (UUID *) uuid);
1084 #endif
1085 }
1086 
1087 SWITCH_DECLARE(switch_status_t) switch_md5(unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen)
1088 {
1089  return apr_md5(digest, input, inputLen);
1090 }
1091 
1093 {
1094  unsigned char digest[SWITCH_MD5_DIGESTSIZE];
1095  apr_status_t status = apr_md5(digest, input, inputLen);
1096  int x;
1097 
1098  digest_str[SWITCH_MD5_DIGEST_STRING_SIZE - 1] = '\0';
1099 
1100  for (x = 0; x < SWITCH_MD5_DIGESTSIZE; x++) {
1101  switch_snprintf(digest_str + (x * 2), 3, "%02x", digest[x]);
1102  }
1103 
1104  return status;
1105 }
1106 
1107 /* FIFO queues (apr-util) */
1108 
1110 {
1111  return apr_queue_create(queue, queue_capacity, pool);
1112 }
1113 
1115 {
1116  return apr_queue_size(queue);
1117 }
1118 
1120 {
1121  return apr_queue_pop(queue, data);
1122 }
1123 
1125 {
1126  return apr_queue_pop_timeout(queue, data, timeout);
1127 }
1128 
1130 {
1131  apr_status_t s;
1132 
1133  do {
1134  s = apr_queue_push(queue, data);
1135  } while (s == APR_EINTR);
1136 
1137  return s;
1138 }
1139 
1141 {
1142  return apr_queue_trypop(queue, data);
1143 }
1144 
1146 {
1147  return apr_queue_interrupt_all(queue);
1148 }
1149 
1151 {
1152  return apr_queue_term(queue);
1153 }
1154 
1156 {
1157  apr_status_t s;
1158 
1159  do {
1160  s = apr_queue_trypush(queue, data);
1161  } while (s == APR_EINTR);
1162 
1163  return s;
1164 }
1165 
1166 SWITCH_DECLARE(int) switch_vasprintf(char **ret, const char *fmt, va_list ap)
1167 {
1168 #ifdef HAVE_VASPRINTF
1169  return vasprintf(ret, fmt, ap);
1170 #else
1171  char *buf;
1172  int len;
1173  size_t buflen;
1174  va_list ap2;
1175  char *tmp = NULL;
1176 
1177 #ifdef _MSC_VER
1178 #if _MSC_VER >= 1500
1179  /* hack for incorrect assumption in msvc header files for code analysis */
1180  __analysis_assume(tmp);
1181 #endif
1182  ap2 = ap;
1183 #else
1184  va_copy(ap2, ap);
1185 #endif
1186 
1187  len = vsnprintf(tmp, 0, fmt, ap2);
1188 
1189  if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) {
1190  len = vsnprintf(buf, buflen, fmt, ap);
1191  *ret = buf;
1192  } else {
1193  *ret = NULL;
1194  len = -1;
1195  }
1196 
1197  va_end(ap2);
1198  return len;
1199 #endif
1200 }
1201 
1203 {
1204  return apr_match_glob(pattern, (apr_array_header_t **) result, pool);
1205 }
1206 
1207 /**
1208  * Create an anonymous pipe.
1209  * @param in The file descriptor to use as input to the pipe.
1210  * @param out The file descriptor to use as output from the pipe.
1211  * @param pool The pool to operate on.
1212  */
1214 {
1215  return apr_file_pipe_create((apr_file_t **) in, (apr_file_t **) out, pool);
1216 }
1217 
1218 /**
1219  * Get the timeout value for a pipe or manipulate the blocking state.
1220  * @param thepipe The pipe we are getting a timeout for.
1221  * @param timeout The current timeout value in microseconds.
1222  */
1224 {
1225  return apr_file_pipe_timeout_get((apr_file_t *) thepipe, (apr_interval_time_t *) timeout);
1226 }
1227 
1228 /**
1229  * Set the timeout value for a pipe or manipulate the blocking state.
1230  * @param thepipe The pipe we are setting a timeout on.
1231  * @param timeout The timeout value in microseconds. Values < 0 mean wait
1232  * forever, 0 means do not wait at all.
1233  */
1235 {
1236  return apr_file_pipe_timeout_set((apr_file_t *) thepipe, (apr_interval_time_t) timeout);
1237 }
1238 
1239 
1240 /**
1241  * stop the current thread
1242  * @param thd The thread to stop
1243  * @param retval The return value to pass back to any thread that cares
1244  */
1246 {
1247  return apr_thread_exit((apr_thread_t *) thd, retval);
1248 }
1249 
1250 /**
1251  * block until the desired thread stops executing.
1252  * @param retval The return value from the dead thread.
1253  * @param thd The thread to join
1254  */
1256 {
1257  if ( !thd ) {
1258  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: Attempting to join thread that does not exist\n");
1259  return SWITCH_STATUS_FALSE;
1260  }
1261 
1262  return apr_thread_join((apr_status_t *) retval, (apr_thread_t *) thd);
1263 }
1264 
1265 
1267 {
1268  return apr_atomic_init((apr_pool_t *) pool);
1269 }
1270 
1272 {
1273 #ifdef apr_atomic_t
1274  return apr_atomic_read((apr_atomic_t *)mem);
1275 #else
1276  return apr_atomic_read32((apr_uint32_t *)mem);
1277 #endif
1278 }
1279 
1280 SWITCH_DECLARE(void) switch_atomic_set(volatile switch_atomic_t *mem, uint32_t val)
1281 {
1282 #ifdef apr_atomic_t
1283  apr_atomic_set((apr_atomic_t *)mem, val);
1284 #else
1285  apr_atomic_set32((apr_uint32_t *)mem, val);
1286 #endif
1287 }
1288 
1289 SWITCH_DECLARE(void) switch_atomic_add(volatile switch_atomic_t *mem, uint32_t val)
1290 {
1291 #ifdef apr_atomic_t
1292  apr_atomic_add((apr_atomic_t *)mem, val);
1293 #else
1294  apr_atomic_add32((apr_uint32_t *)mem, val);
1295 #endif
1296 }
1297 
1299 {
1300 #ifdef apr_atomic_t
1301  apr_atomic_inc((apr_atomic_t *)mem);
1302 #else
1303  apr_atomic_inc32((apr_uint32_t *)mem);
1304 #endif
1305 }
1306 
1308 {
1309 #ifdef apr_atomic_t
1310  return apr_atomic_dec((apr_atomic_t *)mem);
1311 #else
1312  return apr_atomic_dec32((apr_uint32_t *)mem);
1313 #endif
1314 }
1315 
1317 {
1318  return apr_strerror(statcode, buf, bufsize);
1319 }
1320 
1321 /* For Emacs:
1322  * Local Variables:
1323  * mode:c
1324  * indent-tabs-mode:t
1325  * tab-width:4
1326  * c-basic-offset:4
1327  * End:
1328  * For VIM:
1329  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
1330  */
struct apr_queue_t switch_queue_t
Definition: switch_apr.h:590
switch_status_t switch_socket_connect(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:734
unsigned int switch_queue_size(switch_queue_t *queue)
Definition: switch_apr.c:1114
#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's master pool.
Definition: switch_core.h:631
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
switch_status_t switch_directory_exists(const char *dirname, switch_memory_pool_t *pool)
Definition: switch_apr.c:474
switch_status_t switch_time_exp_get(switch_time_t *result, switch_time_exp_t *input)
Definition: switch_apr.c:318
switch_status_t switch_thread_cond_create(switch_thread_cond_t **cond, switch_memory_pool_t *pool)
Definition: switch_apr.c:350
uint16_t switch_sockaddr_get_port(switch_sockaddr_t *sa)
Definition: switch_apr.c:916
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:439
switch_status_t switch_mutex_destroy(switch_mutex_t *lock)
Definition: switch_apr.c:280
#define SWITCH_CHANNEL_LOG
int switch_status_is_timeup(int status)
Definition: switch_apr.c:72
switch_status_t switch_mutex_trylock(switch_mutex_t *lock)
Definition: switch_apr.c:295
switch_status_t switch_time_exp_gmt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:333
switch_status_t switch_socket_bind(switch_socket_t *sock, switch_sockaddr_t *sa)
Definition: switch_apr.c:719
switch_status_t switch_mcast_hops(switch_socket_t *sock, uint8_t ttl)
Definition: switch_apr.c:876
switch_status_t switch_queue_pop_timeout(switch_queue_t *queue, void **data, switch_interval_time_t timeout)
Definition: switch_apr.c:1124
static char TT_KEY[]
Definition: switch_apr.c:673
switch_bool_t
Definition: switch_types.h:405
switch_status_t switch_poll(switch_pollfd_t *aprset, int32_t numsock, int32_t *nsds, switch_interval_time_t timeout)
Definition: switch_apr.c:1015
switch_status_t switch_atomic_init(switch_memory_pool_t *pool)
Definition: switch_apr.c:1266
char * switch_copy_string(char *dst, const char *src, switch_size_t dst_size)
Definition: switch_apr.c:199
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
Definition: switch_apr.c:660
switch_status_t switch_socket_timeout_set(switch_socket_t *sock, switch_interval_time_t t)
Definition: switch_apr.c:856
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
void switch_atomic_inc(volatile switch_atomic_t *mem)
Definition: switch_apr.c:1298
switch_status_t switch_pollset_add(switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
Definition: switch_apr.c:961
#define SWITCH_SO_TCP_KEEPIDLE
Definition: switch_apr.h:1000
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1140
int32_t switch_sockaddr_get_family(switch_sockaddr_t *sa)
Definition: switch_apr.c:921
switch_status_t switch_pollset_remove(switch_pollset_t *pollset, const switch_pollfd_t *descriptor)
Definition: switch_apr.c:970
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:98
switch_pollset_type_t
Definition: switch_apr.h:1283
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:360
switch_status_t switch_file_seek(switch_file_t *thefile, switch_seek_where_t where, int64_t *offset)
Definition: switch_apr.c:394
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:323
switch_status_t switch_os_sock_get(switch_os_socket_t *thesock, switch_socket_t *sock)
Definition: switch_apr.c:689
#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:355
switch_status_t switch_socket_recv(switch_socket_t *sock, char *buf, switch_size_t *len)
Definition: switch_apr.c:782
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
Definition: switch_apr.c:1119
pthread_attr_t attr
Definition: switch_apr.c:627
int switch_socket_fd_get(switch_socket_t *sock)
Definition: switch_apr.c:911
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:179
struct switch_runtime runtime
Definition: switch_core.c:64
switch_status_t switch_thread_rwlock_destroy(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:217
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:936
switch_hash_t * hash
Definition: switch_event.c:74
struct apr_thread_cond_t switch_thread_cond_t
Definition: switch_apr.h:463
struct apr_pollset_t switch_pollset_t
Definition: switch_apr.h:1316
#define zstr(x)
Definition: switch_utils.h:281
switch_status_t switch_file_remove(const char *path, switch_memory_pool_t *pool)
Definition: switch_apr.c:429
int switch_atomic_dec(volatile switch_atomic_t *mem)
Definition: switch_apr.c:1307
switch_status_t switch_uuid_parse(switch_uuid_t *uuid, const char *uuid_str)
Definition: switch_apr.c:1078
switch_status_t switch_socket_send(switch_socket_t *sock, const char *buf, switch_size_t *len)
Definition: switch_apr.c:739
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_thread_exit(switch_thread_t *thd, switch_status_t retval)
Definition: switch_apr.c:1245
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:227
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
Definition: switch_apr.c:1255
switch_status_t switch_file_rename(const char *from_path, const char *to_path, switch_memory_pool_t *pool)
Definition: switch_apr.c:424
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
int switch_file_printf(switch_file_t *thefile, const char *format,...)
Definition: switch_apr.c:444
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:237
switch_status_t switch_socket_accept(switch_socket_t **new_sock, switch_socket_t *sock, switch_memory_pool_t *pool)
Definition: switch_apr.c:729
switch_status_t switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
Definition: switch_apr.c:655
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:908
switch_status_t switch_sockaddr_ip_get(char **addr, switch_sockaddr_t *sa)
Definition: switch_apr.c:861
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:773
struct apr_sockaddr_t switch_sockaddr_t
Definition: switch_apr.h:1029
switch_status_t switch_thread_cond_destroy(switch_thread_cond_t *cond)
Definition: switch_apr.c:381
switch_thread_id_t switch_thread_self(void)
Definition: switch_apr.c:79
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_status_t switch_match_glob(const char *pattern, switch_array_header_t **result, switch_memory_pool_t *pool)
Definition: switch_apr.c:1202
switch_status_t switch_dir_make(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:523
switch_status_t switch_sockaddr_create(switch_sockaddr_t **sa, switch_memory_pool_t *pool)
Definition: switch_apr.c:795
intptr_t switch_ssize_t
void switch_atomic_set(volatile switch_atomic_t *mem, uint32_t val)
Definition: switch_apr.c:1280
switch_status_t switch_file_pipe_timeout_get(switch_file_t *thepipe, switch_interval_time_t *timeout)
Definition: switch_apr.c:1223
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:694
switch_status_t switch_thread_rwlock_tryrdlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:232
switch_status_t switch_socket_listen(switch_socket_t *sock, int32_t backlog)
Definition: switch_apr.c:724
struct apr_thread_rwlock_t switch_thread_rwlock_t
Definition: switch_apr.h:436
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:270
#define SWITCH_BLANK_STRING
Definition: switch_types.h:47
switch_status_t switch_socket_opt_set(switch_socket_t *sock, int32_t opt, int32_t on)
Definition: switch_apr.c:823
switch_status_t switch_md5(unsigned char digest[SWITCH_MD5_DIGESTSIZE], const void *input, switch_size_t inputLen)
Definition: switch_apr.c:1087
uintptr_t switch_size_t
switch_status_t switch_socket_atmark(switch_socket_t *sock, int *atmark)
Definition: switch_apr.c:931
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:313
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:538
switch_status_t switch_mcast_interface(switch_socket_t *sock, switch_sockaddr_t *iface)
Definition: switch_apr.c:886
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:338
int64_t switch_interval_time_t
Definition: switch_apr.h:191
struct apr_file_t switch_file_t
Definition: switch_apr.h:685
switch_status_t switch_file_pipe_timeout_set(switch_file_t *thepipe, switch_interval_time_t timeout)
Definition: switch_apr.c:1234
apr_finfo_t finfo
Definition: switch_apr.c:535
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:434
const char * switch_dir_next_file(switch_dir_t *thedir, char *buf, switch_size_t len)
Definition: switch_apr.c:595
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:328
switch_mutex_t * mutex
apr_pool_t * pool
Definition: switch_apr.c:626
switch_status_t switch_thread_cond_signal(switch_thread_cond_t *cond)
Definition: switch_apr.c:371
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:1000
switch_status_t switch_mcast_loopback(switch_socket_t *sock, uint8_t opt)
Definition: switch_apr.c:881
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:496
char * switch_strerror(switch_status_t statcode, char *buf, switch_size_t bufsize)
Definition: switch_apr.c:1316
void switch_uuid_format(char *buffer, const switch_uuid_t *uuid)
Definition: switch_apr.c:1055
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:704
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_thread_rwlock_t * rwlock
Definition: switch_event.c:73
switch_status_t switch_file_mktemp(switch_file_t **thefile, char *templ, int32_t flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:463
switch_status_t
Common return values.
#define SWITCH_SO_TCP_KEEPINTVL
Definition: switch_apr.h:1001
switch_status_t switch_file_trunc(switch_file_t *thefile, int64_t offset)
Definition: switch_apr.c:414
int switch_vasprintf(char **ret, const char *fmt, va_list ap)
Definition: switch_apr.c:1166
switch_status_t switch_dir_make_recursive(const char *path, switch_fileperms_t perm, switch_memory_pool_t *pool)
Definition: switch_apr.c:528
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:1032
switch_status_t switch_socket_close(switch_socket_t *sock)
Definition: switch_apr.c:714
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
Definition: switch_apr.c:1145
void *SWITCH_THREAD_FUNC * switch_thread_start_t(switch_thread_t *, void *)
Definition: switch_apr.h:950
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:709
char * get_addr(char *buf, switch_size_t len, struct sockaddr *sa, socklen_t salen)
find the char representation of an ip adress
struct apr_thread_t switch_thread_t
Definition: switch_apr.h:941
Main Library Header.
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:403
#define SWITCH_DECLARE(type)
unsigned int switch_hashfunc_default(const char *key, switch_ssize_t *klen)
Definition: switch_apr.c:120
void switch_uuid_get(switch_uuid_t *uuid)
Definition: switch_apr.c:1067
switch_status_t switch_file_lock(switch_file_t *thefile, int type)
Definition: switch_apr.c:419
uint32_t switch_dir_count(switch_dir_t *thedir)
Definition: switch_apr.c:567
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1155
switch_status_t switch_file_pipe_create(switch_file_t **in, switch_file_t **out, switch_memory_pool_t *pool)
Definition: switch_apr.c:1213
switch_status_t switch_socket_send_nonblock(switch_socket_t *sock, const char *buf, switch_size_t *len)
Definition: switch_apr.c:764
switch_status_t switch_queue_term(switch_queue_t *queue)
Definition: switch_apr.c:1150
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:871
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
Definition: switch_apr.c:1129
switch_mutex_t * uuid_mutex
struct apr_pool_t switch_memory_pool_t
switch_interval_time_t switch_interval_time_from_timeval(struct timeval *tvp)
Definition: switch_apr.c:682
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
Definition: switch_apr.c:212
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:127
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
Definition: switch_apr.c:642
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:675
uint32_t switch_atomic_read(volatile switch_atomic_t *mem)
Definition: switch_apr.c:1271
switch_time_t switch_time_make(switch_time_t sec, int32_t usec)
Definition: switch_apr.c:343
switch_status_t switch_thread_rwlock_trywrlock_timeout(switch_thread_rwlock_t *rwlock, int timeout)
Definition: switch_apr.c:247
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:388
const char * switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in)
Definition: switch_apr.c:894
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
Definition: switch_apr.c:1109
switch_status_t switch_thread_cond_broadcast(switch_thread_cond_t *cond)
Definition: switch_apr.c:376
int switch_vsnprintf(char *buf, switch_size_t len, const char *format, va_list ap)
Definition: switch_apr.c:194
void switch_atomic_add(volatile switch_atomic_t *mem, uint32_t val)
Definition: switch_apr.c:1289
int switch_thread_equal(switch_thread_id_t tid1, switch_thread_id_t tid2)
Compare two thread ids.
Definition: switch_apr.c:88
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:979
char * filename
switch_status_t switch_getnameinfo(char **hostname, switch_sockaddr_t *sa, int32_t flags)
Definition: switch_apr.c:926
switch_status_t switch_file_close(switch_file_t *thefile)
Definition: switch_apr.c:409
struct apr_socket_t switch_socket_t
Definition: switch_apr.h:1026
#define switch_assert(expr)
switch_time_t switch_time_now(void)
Definition: switch_apr.c:302
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:817
int switch_snprintf(char *buf, switch_size_t len, const char *format,...)
Definition: switch_apr.c:184
switch_memory_pool_t * switch_thread_rwlock_pool_get(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:222
apr_dir_t * dir_handle
Definition: switch_apr.c:534
memset(buf, 0, buflen)
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:956
#define SWITCH_MD5_DIGESTSIZE
Definition: switch_apr.h:547
switch_size_t switch_file_get_size(switch_file_t *thefile)
Definition: switch_apr.c:468
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:1092
switch_status_t switch_thread_rwlock_trywrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:242
switch_status_t switch_dir_close(switch_dir_t *thedir)
Definition: switch_apr.c:559
switch_status_t switch_socket_addr_get(switch_sockaddr_t **sa, switch_bool_t remote, switch_socket_t *sock)
Definition: switch_apr.c:699
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
Definition: switch_apr.c:665
int switch_sockaddr_equal(const switch_sockaddr_t *sa1, const switch_sockaddr_t *sa2)
Definition: switch_apr.c:866
int32_t switch_int32_t