Skip to content

Commit

Permalink
Revert "Proper error handling in handle_subscribe"
Browse files Browse the repository at this point in the history
This reverts commit ec18896.
  • Loading branch information
bogdan-iancu committed Jun 21, 2019
1 parent 81db9c5 commit 110b185
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 48 deletions.
6 changes: 0 additions & 6 deletions modules/presence/hash.c
Expand Up @@ -340,12 +340,6 @@ int update_shtable(shtable_t htable,unsigned int hash_code,
return -1;
}

if(type & JUST_CHECK)
{
lock_release(&htable[hash_code].lock);
return 0;
}

if(type & REMOTE_TYPE)
{
s->expires= subs->expires+ (int)time(NULL);
Expand Down
1 change: 0 additions & 1 deletion modules/presence/hash.h
Expand Up @@ -35,7 +35,6 @@
struct presentity;
#define REMOTE_TYPE 1<<1
#define LOCAL_TYPE 1<<2
#define JUST_CHECK 1<<3

#define PKG_MEM_STR "pkg"
#define SHARE_MEM "share"
Expand Down
58 changes: 17 additions & 41 deletions modules/presence/subscribe.c
Expand Up @@ -332,15 +332,11 @@ int subs_process_insert_status(subs_t* subs)
return -1;
}

/* Internally updates the subscription data and generates the
* necessary NOTIFY's. It also takes care of sending back a reply
* to the SUBSCRIBE request
*/

int update_subscription(struct sip_msg* msg, subs_t* subs, int init_req)
{
unsigned int hash_code;
int reply_code = 200;
str reply_str;
int reply_code= 200;

if(subs->event->type & PUBL_TYPE)
reply_code=(subs->status==PENDING_STATUS)?202:200;
Expand All @@ -359,7 +355,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int init_req)
if(delete_db_subs(subs->pres_uri,subs->event->name,subs->to_tag)<0)
{
LM_ERR("deleting subscription record from database\n");
goto error_500_reply;
goto error;
}
/* delete record from hash table also */
subs->local_cseq= delete_shtable(subs_htable,hash_code,
Expand All @@ -369,7 +365,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int init_req)
&subs->local_contact) <0)
{
LM_ERR("sending %d OK\n", reply_code);
goto error_500_reply;
goto error;
}
goto send_notify;
}
Expand All @@ -378,66 +374,55 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int init_req)
{
LM_DBG("updating subscription record in hash table failed\n");
if(!fallback2db)
goto error_500_reply;
goto error;
}
if(fallback2db)
{
if(update_subs_db(subs, REMOTE_TYPE)< 0)
{
LM_ERR("updating subscription in database table\n");
goto error_500_reply;
goto error;
}
}

if(msg && send_2XX_reply(msg, reply_code, subs->expires, 0,
&subs->local_contact)<0)
{
LM_ERR("sending 2XX reply\n");
goto error_500_reply;
goto error;
}
}
else
{
if(subs->expires!= 0)
if(msg && send_2XX_reply(msg, reply_code, subs->expires, &subs->to_tag,
&subs->local_contact)<0)
{
/* be sure the SIP subscription does not exist in hash */
if(update_shtable(subs_htable, hash_code, subs, JUST_CHECK)==0) {
/* another subscription with same SIP coordinates already
* exists => decline */
LM_ERR("subscription overlapping detected, rejecting\n");
goto error_500_reply;
}
LM_ERR("sending 2XX reply\n");
goto error;
}

if(subs->expires!= 0)
{
subs->expires += expires_offset;
if(insert_shtable(subs_htable,hash_code,subs)< 0)
{
LM_ERR("inserting new record in subs_htable\n");
goto error_500_reply;
goto error;
}

if(fallback2db)
{
if(insert_subs_db(subs) < 0)
{
LM_ERR("failed to insert subscription in database\n");
goto error_500_reply;
goto error;
}
}
}
/*otherwise there is a subscription outside a dialog with expires= 0
* no update in database, but should try to send Notify */

if(msg && send_2XX_reply(msg, reply_code, subs->expires, &subs->to_tag,
&subs->local_contact)<0)
{
LM_ERR("sending 2XX reply\n");
goto error_500_reply;
}

}

/* the SUBSCRIBE request is replied at this point */

/* send Notifies */
send_notify:
if((subs->event->type & PUBL_TYPE) && subs->event->wipeer)
Expand All @@ -449,8 +434,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int init_req)
goto error;
}
}

LM_DBG("send NOTIFY's out\n");
LM_INFO("notify\n");
if(notify(subs, NULL, NULL, 0 , NULL, 0)< 0)
{
LM_ERR("Failed to send notify request\n");
Expand All @@ -459,14 +443,6 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int init_req)

return 0;

error_500_reply:
reply_code = 500;
reply_str.s = "Server Internal Error";
reply_str.len = sizeof("Server Internal Error")-1;

if (send_error_reply(msg, reply_code, reply_str)<0)
LM_ERR("failed to send reply on error case\n");

error:
return -1;
}
Expand Down

0 comments on commit 110b185

Please sign in to comment.