1 2 /* 3 * pfqueue library interface 4 */ 5 6 #ifndef __PFQLIB_H 7 #define __PFQLIB_H 8 9 #include <time.h> 10 #include <regex.h> 11 #include <sys/types.h> 12 #include <sys/stat.h> 13 #include "pfregex.h" 14 #include <pthread.h> 15 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define PFQL_VERSION "1.4" 22 23 // Structure for configuration 24 struct pfql_conf_t { 25 int max_char; /* Max char buffer length */ 26 short initial_queue; /* Queue to start with */ 27 char backends_path[200]; /* Path to backends */ 28 char backend_name[200]; /* Backend to use */ 29 char backend_config[200]; /* Backend configuration path */ 30 char backend_progs[200]; /* Backend bin bath */ 31 int msg_max; /* Maximum number of messages */ 32 int scan_limit; /* Max secs for a single scan */ 33 int scan_delay; /* Secs between scans */ 34 char remote_host[200]; /* Remote host (for socket backend only) */ 35 int remote_port; /* Remote port (for socket backend only) */ 36 }; 37 38 // Status at runtime 39 struct pfql_status_t { 40 short auto_wrk_tagged; /* Automatically work on tagged messages, if any */ 41 short wrk_tagged; /* Work on tagged messages, if any */ 42 short ask_confirm; /* Ask for confirmations */ 43 short do_scan; /* Scan messages */ 44 short use_envelope; /* Use envelope for from/to */ 45 short use_colors; /* Use colors */ 46 short cur_queue; /* Current queue */ 47 short sort_field; /* Sort field */ 48 short sort_sense; /* Sort ascendent/descendent */ 49 short queue_status; /* Tells wether the queue is being digged or not */ 50 }; 51 52 // pfqlib context private structure 53 struct pfql_context_t { 54 struct msg_t *queue; 55 struct be_msg_t *queue_thread; 56 struct pfql_status_t pfql_status; 57 struct pfql_conf_t pfql_conf; 58 59 int dig_lastqueue; 60 time_t queue_last_changed; 61 int NUMMSG; 62 int NUMTAG; 63 64 int thread_control; 65 66 void *beptr; 67 char* (*pfqbe_id)(); 68 char* (*pfqbe_version)(); 69 int (*pfqbe_apiversion)(); 70 int (*pfqbe_init)(); 71 int (*pfqbe_setup)(struct msg_t*,struct be_msg_t*); 72 int (*pfqbe_close)(); 73 int (*pfqbe_fill_queue)(); 74 int (*pfqbe_retr_headers)(const char*); 75 int (*pfqbe_retr_status)(const char*); 76 int (*pfqbe_retr_body)(const char*,char*,size_t); 77 int (*pfqbe_message_delete)(const char*); 78 int (*pfqbe_message_hold)(const char*); 79 int (*pfqbe_message_release)(const char*); 80 int (*pfqbe_message_requeue)(const char*); 81 int (*pfqbe_set_queue)(int); 82 char* (*pfqbe_queue_name)(int); 83 void (*pfqbe_use_envelope)(int); 84 int (*pfqbe_get_caps)(); 85 int (*pfqbe_queue_count)(); 86 struct pfb_conf_t* (*pfqbe_getconf)(); 87 88 regex_t *regexp; 89 int search_mode; 90 91 pthread_t qfill_thread; 92 pthread_mutex_t qfill_mutex; 93 }; 94 95 /* ----------------- 96 * Library functions 97 * ----------------- */ 98 99 // Initializes library 100 int pfql_init(struct pfql_context_t *); 101 102 // Create context 103 int pfql_context_create ( struct pfql_context_t **); 104 105 // Destroy context 106 int pfql_context_destroy ( struct pfql_context_t *); 107 108 // Start using library 109 int pfql_start(struct pfql_context_t *); 110 111 // Returns library version 112 const char* pfql_version(); 113 114 // Returns status 115 struct pfql_status_t *pfql_getstatus(struct pfql_context_t *); 116 117 // Returns current configuration 118 struct pfql_conf_t *pfql_getconf(struct pfql_context_t *); 119 120 /* 121 * Backend functions 122 */ 123 124 // Returns backend API version 125 int pfql_backend_apiversion(struct pfql_context_t *); 126 127 // Returns backend identifier 128 const char* pfql_backend_id(struct pfql_context_t *); 129 130 // Returns backend version 131 const char* pfql_backend_version(struct pfql_context_t *); 132 133 // Sets backend configuration path/file 134 void pfql_backend_setconfig(struct pfql_context_t *,const char*); 135 136 // Sets backend MTA command 137 void pfql_backend_setcommand(struct pfql_context_t *,const char*); 138 139 // Sets MTA version 140 void pfql_backend_setversion(struct pfql_context_t *,const char*); 141 142 // Number of queues 143 int pfql_num_queues(struct pfql_context_t *); 144 145 // Returns queue name 146 const char* pfql_queue_name(struct pfql_context_t *,int); 147 148 // Set queue sorting 149 void pfql_queue_sort(struct pfql_context_t *); 150 151 // Sets current queue 152 int pfql_set_queue(struct pfql_context_t *,int); 153 154 // The last time the queue changed 155 time_t pfql_queue_last_changed(struct pfql_context_t *); 156 157 // Retreive message status 158 int pfql_retr_status(struct pfql_context_t *,const char*); 159 160 // Retreive message headers 161 int pfql_retr_headers(struct pfql_context_t *,const char*); 162 163 // Retreive message body 164 int pfql_retr_body(struct pfql_context_t *,const char*, void*, size_t); 165 166 // Returns the number of messages in the queue 167 int pfql_num_msg(struct pfql_context_t *); 168 169 // Returns the number of tagged messages 170 int pfql_num_tag(struct pfql_context_t *); 171 172 // Tags all messages 173 void pfql_tag_all(struct pfql_context_t *); 174 175 // Untag all messages 176 void pfql_tag_none(struct pfql_context_t *); 177 178 // Tags a single message 179 void pfql_msg_tag(struct pfql_context_t *,const char*); 180 181 // Untags a single message 182 void pfql_msg_untag(struct pfql_context_t *,const char*); 183 184 // Toggle tag flag on message 185 void pfql_msg_toggletag(struct pfql_context_t *,const char*); 186 187 // Returns wether the message is tagged or not 188 int pfql_msg_istagged(struct pfql_context_t *,const char*); 189 190 // Performs an action on the message 191 void pfql_msg_action(struct pfql_context_t *,const char*,int); 192 193 // Toggle reading from envelope, if the backend supports it 194 void pfql_toggle_envelope(struct pfql_context_t *); 195 196 // Search for a regexp (first occurence) 197 int pfql_msg_search(struct pfql_context_t *,const char*); 198 199 // Search message forward 200 int pfql_msg_searchnext(struct pfql_context_t *,const char*); 201 202 // Search message backward 203 int pfql_msg_searchprev(struct pfql_context_t *,const char*); 204 205 // Search next message and tag it 206 void pfql_msg_searchandtag(struct pfql_context_t *,const char*); 207 208 // Returns message at a given position in the queue 209 struct msg_t* pfql_msg_at(struct pfql_context_t *,int); 210 211 // Returns a message given its ID 212 struct msg_t* pfql_msg(struct pfql_context_t *,const char*); 213 214 // Store messages in a file 215 int pfql_dump(struct pfql_context_t *, const char* ); 216 217 // Queue status 218 #define PFQL_Q_FILLING 0 219 #define PFQL_Q_IDLE 1 220 #define PFQL_Q_SORTING 2 221 222 // Return codes 223 #define PFQL_OK 0 224 #define PFQL_ERROR -1 225 #define PFQL_INVREGEXP -1 226 #define PFQL_BENOTFOUND -2 227 #define PFQL_BEWRONGAPI -3 228 #define PFQL_BEMISSINGSYM -4 229 #define PFQL_MALLOC -5 230 #define PFQL_NOBE -6 231 #define PFQL_BEINIT -7 232 #define PFQL_MSGNOTEX -1 233 #define PFQL_NOFILE -8 234 235 // Sort fields 236 #define PFQL_SORT_UNSORTED 0 237 #define PFQL_SORT_FROM 1 238 #define PFQL_SORT_TO 2 239 #define PFQL_SORT_SUBJECT 3 240 241 #define PFQL_SORT_ASC 1 242 #define PFQL_SORT_DESC -1 243 244 #ifdef __cplusplus 245 } 246 #endif 247 248 #endif // __PFQLIB_H 249 250