108 lines
3.6 KiB
C
108 lines
3.6 KiB
C
|
#ifndef _MMSQUEUE_INCLUDED__
|
||
|
#define _MMSQUEUE_INCLUDED__
|
||
|
|
||
|
#include "mms_msg.h"
|
||
|
|
||
|
#define QFNAMEMAX 32
|
||
|
|
||
|
typedef struct MmsEnvelopeTo {
|
||
|
Octstr *rcpt; /* Recipient address. */
|
||
|
int process; /* 1 if delivery to this recipient should be attempted.
|
||
|
* Flags below for details.
|
||
|
*/
|
||
|
enum {SFailed=0, SSuccess, SDefered, SUnknown} flag;
|
||
|
} MmsEnvelopeTo;
|
||
|
|
||
|
typedef struct MmsEnvelope {
|
||
|
int msgtype; /* type of message. */
|
||
|
Octstr *msgId; /* message id (for reference). */
|
||
|
Octstr *token; /* User level token, may be null. */
|
||
|
Octstr *from; /* from address. */
|
||
|
|
||
|
List *to; /* List of recipients: MmsEnvelopeTo */
|
||
|
|
||
|
Octstr *subject; /* Message subject (if any). */
|
||
|
|
||
|
time_t created; /* date/time this queue entry was made. */
|
||
|
time_t sendt; /* date/time attempt should be made to send this message.*/
|
||
|
time_t lasttry; /* date/time this queue item was last run. */
|
||
|
time_t expiryt; /* date/time when this message expires. */
|
||
|
time_t lastaccess; /* Last fetch of the corresponding data. */
|
||
|
|
||
|
int dlr; /* Whether to send delivery receipts or not. */
|
||
|
|
||
|
long attempts; /* Delivery attempts made so far. */
|
||
|
|
||
|
unsigned long msize; /* Size of message in octets. */
|
||
|
|
||
|
struct {
|
||
|
int billed;
|
||
|
double amt;
|
||
|
} bill; /* Whether this has been billed and how much. */
|
||
|
|
||
|
Octstr *mdata; /* Generic string data used by any interface. */
|
||
|
Octstr *fromproxy; /* Which proxy sent us this message.*/
|
||
|
Octstr *viaproxy; /* Which proxy must we send this message through. */
|
||
|
struct { /* Name of the queue file, pointer to it (locked). DO NOT MUCK WITH THESE! */
|
||
|
char name[QFNAMEMAX]; /* Name of the file. */
|
||
|
char dir[QFNAMEMAX]; /* Directory in which file is .*/
|
||
|
char _pad[16];
|
||
|
int fd;
|
||
|
} qf;
|
||
|
} MmsEnvelope;
|
||
|
|
||
|
|
||
|
/*
|
||
|
* Add a message to the queue, returns 0 on success -1 otherwise (error is logged).
|
||
|
* 'to' is a list of Octstr * *.
|
||
|
* Returns a queue file name.
|
||
|
*/
|
||
|
extern Octstr *mms_queue_add(Octstr *from, List *to, Octstr *msgid,
|
||
|
Octstr *subject,
|
||
|
Octstr *fromproxy, Octstr *viaproxy,
|
||
|
time_t senddate, time_t expirydate, MmsMsg *m, Octstr *token,
|
||
|
int dlr,
|
||
|
char *directory);
|
||
|
|
||
|
/*
|
||
|
* Update queue status. Returns -1 on error, 0 if queue is updated fine and
|
||
|
* envelope is still valid, 1 if envelope is no longer valid (no more recipients.)
|
||
|
*/
|
||
|
extern int mms_queue_update(MmsEnvelope *e);
|
||
|
|
||
|
/*
|
||
|
* Get the message associated with this queue entry.
|
||
|
*/
|
||
|
extern MmsMsg *mms_queue_getdata(MmsEnvelope *e);
|
||
|
|
||
|
/*
|
||
|
* Reads queue, returns up to lim queue entries that are ready for processing. send 0 for no limit.
|
||
|
*/
|
||
|
|
||
|
/*
|
||
|
* Attempt to read an envelope from queue file:
|
||
|
* - opens and locks the file.
|
||
|
* - if the lock succeeds, check that file hasn't changed since opening. If it has
|
||
|
* return NULL (i.e. file is being processed elsewhere -- race condition), otherwise read it.
|
||
|
* - If should block is 1, then does a potentially blocking attempt to lock the file.
|
||
|
*/
|
||
|
|
||
|
MmsEnvelope *mms_queue_readenvelope(char *qf, char *dir, int shouldblock);
|
||
|
|
||
|
/*
|
||
|
* Run the queue in the given directory. For each envelope that is due for sending, call
|
||
|
* deliver(). If deliver() returns 0, then queue_run needs to destroy envelope
|
||
|
* structure it passed to deliver()
|
||
|
* if deliver() returns 1, it has deleted envelope.
|
||
|
* Also if rstop becomes true, queue run must stop.
|
||
|
*/
|
||
|
void mms_queue_run(char *dir,
|
||
|
int (*deliver)(MmsEnvelope *),
|
||
|
double sleepsecs,
|
||
|
int num_threads,
|
||
|
int *rstop);
|
||
|
|
||
|
/* Get rid of memory used by this. */
|
||
|
extern int mms_queue_free_env(MmsEnvelope *e);
|
||
|
#endif
|