[asterisk-commits] mmichelson: branch group/CCSS r229604 - /team/group/CCSS/channels/chan_sip.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Nov 11 17:24:50 CST 2009
Author: mmichelson
Date: Wed Nov 11 17:24:46 2009
New Revision: 229604
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=229604
Log:
Got the PUBLISH refresh written.
Tried to put scheduler operations in a single place if
possible. I'll probably end up moving the scheduler replacements
to a single spot if at all possible. I like chocolate.
Modified:
team/group/CCSS/channels/chan_sip.c
Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=229604&r1=229603&r2=229604
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Wed Nov 11 17:24:46 2009
@@ -1831,14 +1831,25 @@
return 0;
}
-static struct sip_esc_entry *create_esc_entry(struct event_state_compositor *esc, struct sip_request *req)
+static int publish_expire(const void *data)
+{
+ struct sip_esc_entry *esc_entry = (struct sip_esc_entry *) data;
+ /* XXX Need to get the ESC and unlink the entry */
+ ao2_ref(esc_entry, -1);
+ return 0;
+}
+
+static struct sip_esc_entry *create_esc_entry(struct event_state_compositor *esc, struct sip_request *req, const int expires)
{
struct sip_esc_entry *esc_entry;
int res = -1;
+ int expires_ms;
if (!(esc_entry = ao2_alloc(sizeof(*esc_entry), esc_entry_destructor))) {
return NULL;
}
+
+ expires_ms = expires * 1000;
switch (esc->event) {
case CALL_COMPLETION:
@@ -1847,6 +1858,9 @@
default:
break;
}
+
+ /* XXX Need to bump refcount here. Scheduler will have a reference */
+ esc_entry->sched_id = ast_sched_add(sched, expires_ms, publish_expire, esc_entry);
ao2_link(*esc->compositor, esc_entry);
return esc_entry;
@@ -22428,9 +22442,8 @@
return 1;
}
-static enum sip_publish_type determine_sip_publish_type(struct sip_request *req, const char * const event, const char * const eid)
-{
- const char *expires = get_header(req, "Expires");
+static enum sip_publish_type determine_sip_publish_type(struct sip_request *req, const char * const event, const char * const eid, const char * const expires)
+{
int expires_int;
int eid_present = !ast_strlen_zero(eid);
int body_present = req->lines > 0;
@@ -22458,9 +22471,9 @@
return SIP_PUBLISH_UNKNOWN;
}
-static int handle_sip_publish_initial(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc)
-{
- struct sip_esc_entry *esc_entry = create_esc_entry(esc, req);
+static int handle_sip_publish_initial(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const int expires)
+{
+ struct sip_esc_entry *esc_entry = create_esc_entry(esc, req, expires);
if (!esc_entry) {
return -1;
@@ -22470,13 +22483,25 @@
return 0;
}
-static int handle_sip_publish_refresh(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid)
-{
- /* XXX STUB */
+static int handle_sip_publish_refresh(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid, const int expires)
+{
+ struct sip_esc_entry *esc_entry = get_esc_entry(eid, esc);
+ int expires_ms = expires * 1000;
+ /* A refresh is pretty simple. We need to verify that the eid corresponds to an esc entry of ours.
+ * If it does, great. We just reschedule destruction of the entry for later.
+ */
+
+ if (!esc_entry) {
+ return -1;
+ }
+
+ AST_SCHED_REPLACE(esc_entry->sched_id, sched, expires_ms, publish_expire, esc_entry);
+
+ ao2_ref(esc_entry, -1);
return 0;
}
-static int handle_sip_publish_modify(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid)
+static int handle_sip_publish_modify(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid, const int expires)
{
/* XXX STUB */
return 0;
@@ -22494,6 +22519,8 @@
const char *event = get_header(req, "Event");
struct event_state_compositor *esc;
enum sip_publish_type publish_type;
+ const char *expires_str = get_header(req, "Expires");
+ int expires_int;
int res;
if (ast_strlen_zero(event)) {
@@ -22527,20 +22554,20 @@
return 0;
}
- publish_type = determine_sip_publish_type(req, event, eid);
+ publish_type = determine_sip_publish_type(req, event, eid, expires_str);
switch (publish_type) {
case SIP_PUBLISH_UNKNOWN:
transmit_response(p, "400 Bad Request", req);
break;
case SIP_PUBLISH_INITIAL:
- handle_sip_publish_initial(p, req, esc);
+ handle_sip_publish_initial(p, req, esc, expires_int);
break;
case SIP_PUBLISH_REFRESH:
- handle_sip_publish_refresh(p, req, esc, eid);
+ handle_sip_publish_refresh(p, req, esc, eid, expires_int);
break;
case SIP_PUBLISH_MODIFY:
- handle_sip_publish_modify(p, req, esc, eid);
+ handle_sip_publish_modify(p, req, esc, eid, expires_int);
break;
case SIP_PUBLISH_REMOVE:
handle_sip_publish_remove(p, req, esc, eid);
More information about the asterisk-commits
mailing list