1 /* This file is part of GNU Dico. 2 Copyright (C) 1998-2020 Sergey Poznyakoff 3 4 GNU Dico is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 3, or (at your option) 7 any later version. 8 9 GNU Dico is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifndef __xdico_h 18 #define __xdico_h 19 20 #ifndef _GNU_SOURCE 21 # define _GNU_SOURCE 22 #endif 23 #include <dico.h> 24 25 26 struct sockaddr; 27 void sockaddr_to_str(const struct sockaddr *sa, int salen, 28 char *bufptr, size_t buflen, 29 size_t *plen); 30 char *sockaddr_to_astr(const struct sockaddr *sa, int salen); 31 32 33 int switch_to_privs (uid_t uid, gid_t gid, dico_list_t retain_groups); 34 35 36 /* Utility functions */ 37 char *make_full_file_name(const char *dir, const char *file); 38 void trimnl(char *buf, size_t len); 39 40 dico_list_t xdico_list_create(void); 41 dico_iterator_t xdico_list_iterator(dico_list_t list); 42 void xdico_list_append(struct dico_list *list, void *data); 43 void xdico_list_prepend(struct dico_list *list, void *data); 44 dico_assoc_list_t xdico_assoc_create(int); 45 void xdico_assoc_append(dico_assoc_list_t assoc, const char *key, 46 const char *value); 47 int xdico_assoc_add(dico_assoc_list_t assoc, const char *key, 48 const char *value, size_t count, int replace); 49 char *xdico_assign_string(char **dest, char *str); 50 51 char *xdico_sasl_mech_to_capa(char *mech); 52 int xdico_sasl_capa_match_p(const char *mech, const char *capa); 53 54 int dicod_free_item (void *item, void *data); 55 56 57 /* Timer */ 58 typedef struct timer_slot *xdico_timer_t; 59 60 xdico_timer_t timer_get(const char *name); 61 xdico_timer_t timer_start(const char *name); 62 xdico_timer_t timer_stop(const char *name); 63 xdico_timer_t timer_reset(const char *name); 64 double timer_get_real(xdico_timer_t t); 65 double timer_get_user(xdico_timer_t t); 66 double timer_get_system(xdico_timer_t t); 67 void timer_format_time(dico_stream_t stream, double t); 68 69 /* xstript */ 70 dico_stream_t xdico_transcript_stream_create(dico_stream_t transport, 71 dico_stream_t logstr, 72 const char *prefix[]); 73 74 /* xstream.c */ 75 int stream_writez(dico_stream_t str, const char *buf); 76 int stream_printf(dico_stream_t str, const char *fmt, ...); 77 void stream_write_multiline(dico_stream_t str, const char *text); 78 79 /* xtkn.c */ 80 void xdico_tokenize_string(struct dico_tokbuf *tb, char *str); 81 82 /* appi18n.c */ 83 void appi18n_init(void); 84 85 /* xhostname.c */ 86 char *xdico_local_hostname(void); 87 88 /* xdebug.c */ 89 extern int debug_level; 90 extern int debug_source_info; 91 extern dico_stream_t debug_stream; 92 93 #define XDICO_DEBUG(l, s) \ 94 do { \ 95 if (debug_level >= l) { \ 96 if (debug_source_info) \ 97 DICO_DEBUG_SINFO(debug_stream); \ 98 dico_stream_write(debug_stream, s, strlen(s)); \ 99 } \ 100 } while (0) 101 102 #define XDICO_DEBUG_F1(l,f,a1) \ 103 do { \ 104 if (debug_level >= l) { \ 105 if (debug_source_info) \ 106 DICO_DEBUG_SINFO(debug_stream); \ 107 stream_printf(debug_stream, f, a1); \ 108 } \ 109 } while (0) 110 111 #define XDICO_DEBUG_F2(l,f,a1,a2) \ 112 do { \ 113 if (debug_level >= l) { \ 114 if (debug_source_info) \ 115 DICO_DEBUG_SINFO(debug_stream); \ 116 stream_printf(debug_stream, f, a1, a2); \ 117 } \ 118 } while (0) 119 120 #define XDICO_DEBUG_F3(l,f,a1,a2,a3) \ 121 do { \ 122 if (debug_level >= l) { \ 123 if (debug_source_info) \ 124 DICO_DEBUG_SINFO(debug_stream); \ 125 stream_printf(debug_stream, f, a1, a2, a3); \ 126 } \ 127 } while (0) 128 129 #define XDICO_DEBUG_F4(l,f,a1,a2,a3,a4) \ 130 do { \ 131 if (debug_level >= l) { \ 132 if (debug_source_info) \ 133 DICO_DEBUG_SINFO(debug_stream); \ 134 stream_printf(debug_stream, f, a1, a2, a3, a4); \ 135 } \ 136 } while (0) 137 138 #endif 139 140