140 lines
4.8 KiB
C
140 lines
4.8 KiB
C
/*
|
|
* Mbuni - Open Source MMS Gateway
|
|
*
|
|
* Queue management functions
|
|
*
|
|
* Copyright (C) 2003 - 2005, Digital Solutions Ltd. - http://www.dsmagic.com
|
|
*
|
|
* Paul Bagyenda <bagyenda@dsmagic.com>
|
|
*
|
|
* This program is free software, distributed under the terms of
|
|
* the GNU General Public License, with a few exceptions granted (see LICENSE)
|
|
*/
|
|
|
|
#ifndef _MMS_QUEUE_INCLUDED__
|
|
#define _MMS_QUEUE_INCLUDED__
|
|
|
|
#include "mms_msg.h"
|
|
#include "mms_util.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. */
|
|
|
|
Octstr *vaspid; /* VASPID (if any) */
|
|
Octstr *vasid; /* VASID (if any) */
|
|
|
|
Octstr *url1; /* Generic URLs (2) associated with message. */
|
|
Octstr *url2;
|
|
|
|
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. */
|
|
|
|
void *_x; /* Generic storage field used by module clients. */
|
|
|
|
/* DO NOT MODIFY ANYTHING BEYOND THIS POINT. */
|
|
struct { /* Name of the queue file, pointer to it (locked). DO NOT USE THESE! */
|
|
char name[QFNAMEMAX]; /* Name of the file. */
|
|
char dir[QFNAMEMAX]; /* Directory in which file is .*/
|
|
char subdir[64]; /* and the sub-directory. */
|
|
char _pad[16];
|
|
int fd;
|
|
} qf;
|
|
char xqfname[64+QFNAMEMAX]; /* The full ID for the queue. Use this. */
|
|
} MmsEnvelope;
|
|
|
|
/* Given a queue directory, initialise it. Must be called at least once on each queue dir. */
|
|
int mms_init_queuedir(Octstr *qdir);
|
|
/*
|
|
* 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 *subject,
|
|
Octstr *fromproxy, Octstr *viaproxy,
|
|
time_t senddate, time_t expirydate, MmsMsg *m, Octstr *token,
|
|
Octstr *vaspid, Octstr *vasid,
|
|
Octstr *url1, Octstr *url2,
|
|
int dlr,
|
|
char *directory, Octstr *mmscname);
|
|
|
|
/*
|
|
* 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);
|
|
|
|
/* Replace data for this queue item -- used by mm7 interface. */
|
|
int mms_queue_replacedata(MmsEnvelope *e, MmsMsg *m);
|
|
|
|
/*
|
|
* 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
|