21 static mutex_t msglock;
22 static unsigned keysize = 177;
23 static unsigned pending = 0;
27 static unsigned volatile allocated = 0;
28 static time_t
volatile duration = 900;
49 shell::log(shell::INFO,
"checking messages...");
57 linked_pointer<message> mp;
59 unsigned msgcount = 0;
65 while(msgcount < keysize) {
70 msgnext = mp->getNext();
71 if(mp->expires < now) {
72 mp->delist(&msgs[msgcount]);
73 mp->enlist(&freelist);
87 linked_pointer<service::keynode> sp = cfg->
getList(
"messages");
91 value = sp->getPointer();
94 keysize = atoi(value);
95 else if(!stricmp(key,
"expires"))
96 duration = atoi(value) * 60;
111 fprintf(fp,
"Messaging:\n");
112 fprintf(fp,
" allocated messages: %d\n", allocated);
113 fprintf(fp,
" pending messages: %d\n", pending);
118 assert(uid == NULL || *uid != 0);
120 linked_pointer<message> mp;
127 path = NamedObject::keyindex(uid, keysize);
132 next = mp->getNext();
133 if(!stricmp(mp->user, uid)) {
135 mp->delist(&msgs[path]);
136 if(mp->expires < now)
137 mp->enlist(&freelist);
139 mp->enlist(&sending);
146 int messages::deliver(
const char *to,
const char *reply,
const char *from, caddr_t text,
size_t len,
const char *msgtype,
const char *digest)
151 msgtype =
"text/plain";
153 if(len >
sizeof(msg->
body))
157 msg =
static_cast<message *
>(freelist);
159 freelist = msg->getNext();
166 String::set(msg->
reply,
sizeof(msg->
reply), reply);
167 String::set(msg->
from,
sizeof(msg->
from), from);
168 String::set(msg->
type,
sizeof(msg->
type), msgtype);
169 memset(msg->
body, 0,
sizeof(msg->
body));
171 memcpy(msg->
body, text, len);
174 if(!strchr(to,
'@')) {
175 String::set(msg->
user,
sizeof(msg->
user), to);
178 return remote(to, msg, digest);
202 if(strchr(host,
':'))
203 snprintf(from,
sizeof(from),
"<%s:%s@[%s]:%u>",
204 scheme, sysid, host, port);
206 snprintf(from,
sizeof(from),
"<%s:%s@%s:%u>",
207 scheme, sysid, host, port);
209 return deliver(to, sysid, from, (caddr_t)text, strlen(text),
"text/plain");
214 shell::debug(3,
"instant message delivered to %s from %s", to, msg->
reply);
222 const char *schema = NULL;
227 if(eq(to,
"tcp:", 4)) {
231 else if(eq(to,
"udp:", 4)) {
237 snprintf(rewrite,
sizeof(rewrite),
"%s:%s", schema, to);
242 char *authbuf =
new char[1024];
243 stringbuf<64> response;
248 snprintf(authbuf, 1024,
"%s:%s", im->
sip_method, req);
249 Random::uuid(nounce);
251 digest_t auth(
"md5");
257 snprintf(authbuf, 1024,
"%s:%s:%s", digest, *once, *response);
261 snprintf(authbuf, 1024,
262 "Digest username=\"%s\""
286 linked_pointer<registry::target> tp;
290 unsigned msgcount = 0;
299 shell::debug(3,
"instant message failed for %s from %s; error=%d", msg->
user, msg->
reply, error);
303 shell::debug(3,
"instant message delivered to %s from %s", msg->
user, msg->
reply);
306 if(!rr->
expires || tp->expires > now) {
309 String::add(to,
sizeof(to),
";lr>");
315 String::add(to,
sizeof(to),
">");
336 msg->enlist(&freelist);
352 sending = msg->getNext();
355 msg->enlist(&freelist);
Structure for SIP Message (REQUEST and RESPONSE).
int osip_uri_to_str(const osip_uri_t *url, char **dest)
Get a string representation of a url element.
void reload(service *cfg)
static void automatic(void)
static void update(const char *userid)
const char *volatile published
void osip_to_free(osip_to_t *header)
Free a To element.
char reply[MAX_USERID_SIZE]
keynode * getList(const char *path)
static bool make_request_message(context_t ctx, const char *method, const char *to, const char *from, msg_t *msg, const char *route=NULL)
union sipwitch::MappedRegistry::@6 source
static int deliver(message *msg)
int osip_message_set_to(osip_message_t *sip, const char *hvalue)
Set the To header.
#define SIP_MESSAGE_TOO_LARGE
static const char * getRealm(void)
osip_uri_t * req_uri
Request-Uri (SIP request only)
struct sipwitch::MappedRegistry::@6::@8 internal
static bool is_configured(void)
static void siplog(voip::msg_t msg)
static void attach(msg_t msg, const char *type, const char *body)
static void detach(mapped *m)
char user[MAX_USERID_SIZE]
static const char * getDigest(void)
static int system(const char *to, const char *message)
voip::context_t route(const char *uri, char *buf, size_t size)
static char * sipAddress(struct sockaddr_internet *addr, char *buf, const char *user=NULL, size_t size=MAX_URI_SIZE)
static void send_request_message(context_t ctx, msg_t msg)
static mapped * access(const char *id)
static int remote(const char *to, message *msg, const char *digest=NULL)
System configuration instance and service functions.
static unsigned short sip_port
char * sip_method
METHOD (SIP request only)
static void header(msg_t msg, const char *key, const char *value)