⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subscribe.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
			return -5;		}	}	add_presentity(_d, *_p);	_d->reg(&watch_uri, _puri, (void*)callback, *_p);	return 0;}/* * Update existing presentity and watcher list */static int update_presentity(struct sip_msg* _m, struct pdomain* _d, 			     struct presentity* _p, struct watcher** _w){	time_t e;	dlg_t* dialog;	str watch_uri;	str watch_dn;	event_t *event = NULL;	int et = 0;	if (_m->event) {		event = (event_t*)(_m->event->parsed);		et = event->parsed;	} else {		LOG(L_ERR, "update_presentity defaulting to EVENT_PRESENCE\n");		et = EVENT_PRESENCE;	}	if (_m->expires) {		e = ((exp_body_t*)_m->expires->parsed)->val;	} else {		e = default_expires;	}	if (get_watch_uri(_m, &watch_uri, &watch_dn) < 0) {		LOG(L_ERR, "update_presentity(): Error while extracting watcher URI\n");		return -1;	}	if (find_watcher(_p, &watch_uri, et, _w) == 0) {		LOG(L_ERR, "update_presentity() found watcher\n");		if (e == 0) {			if (et != EVENT_PRESENCE_WINFO) {				if (remove_watcher(_p, *_w) < 0) {					LOG(L_ERR, "update_presentity(): Error while deleting winfo watcher\n");					return -2;				} 			} else {				if (remove_winfo_watcher(_p, *_w) < 0) {					LOG(L_ERR, "update_presentity(): Error while deleting winfo watcher\n");					return -2;				} 			}						(*_w)->expires = 0;   /* The watcher will be freed after NOTIFY is sent */			if (!_p->watchers && !_p->winfo_watchers) {				remove_presentity(_d, _p);			}		} else {			e += act_time;			if (update_watcher(*_w, e) < 0) {				LOG(L_ERR, "update_presentity(): Error while updating watcher\n");				return -3;			}		}	} else {		if (e) {			e += act_time;			if (tmb.new_dlg_uas(_m, 200, &dialog) < 0) {				paerrno = PA_DIALOG_ERR;				LOG(L_ERR, "update_presentity(): Error while creating dialog state\n");				return -4;			}			if (et != EVENT_PRESENCE_WINFO) {				if (add_watcher(_p, &watch_uri, e, et, acc, dialog, &watch_dn, _w) < 0) {					LOG(L_ERR, "update_presentity(): Error while creating presentity\n");					tmb.free_dlg(dialog);					return -5;				}			} else {				if (add_winfo_watcher(_p, &watch_uri, e, et, acc, dialog, &watch_dn, _w) < 0) {					LOG(L_ERR, "update_presentity(): Error while creating winfo watcher\n");					tmb.free_dlg(dialog);					return -5;				}						}		} else {			DBG("update_presentity(): expires = 0 but no watcher found\n");			*_w = 0;		}	}	return 0;}/* * Handle a registration request -- make sure aor exists in presentity table *//* * Extract Address of Record */#define MAX_AOR_LEN 256int pa_extract_aor(str* _uri, str* _a){	static char aor_buf[MAX_AOR_LEN];	struct sip_uri puri;	int user_len;	if (parse_uri(_uri->s, _uri->len, &puri) < 0) {		LOG(L_ERR, "pa_extract_aor(): Error while parsing Address of Record\n");		return -1;	}		if ((puri.user.len + puri.host.len + 1) > MAX_AOR_LEN) {		LOG(L_ERR, "pa_extract_aor(): Address Of Record too long\n");		return -2;	}	_a->s = aor_buf;	_a->len = puri.user.len;	user_len = _a->len;	memcpy(aor_buf, puri.user.s, puri.user.len);	aor_buf[_a->len] = '@';	memcpy(aor_buf + _a->len + 1, puri.host.s, puri.host.len);	_a->len += 1 + puri.host.len;#if 0	if (case_sensitive) {		tmp.s = _a->s + user_len + 1;		tmp.len = puri.host.len;		strlower(&tmp);	} else {		strlower(_a);	}#endif	return 0;}int pa_handle_registration(struct sip_msg* _m, char* _domain, char* _s2){     struct pdomain* d = (struct pdomain*)_domain;     struct presentity *presentity;     str p_uri;     struct to_body *from = NULL;     int e = 0;     // LOG(L_ERR, "pa_handle_registration() entered\n");     paerrno = PA_OK;     d = (struct pdomain*)_domain;     if (parse_hfs(_m, 0) < 0) {	  paerrno = PA_PARSE_ERR;	  LOG(L_ERR, "pa_handle_registration(): Error while parsing headers\n");	  return -1;     }     from = get_from(_m);     if (!from || (pa_extract_aor(&from->uri, &p_uri) < 0)) {	  LOG(L_ERR, "pa_handle_registration(): Error while extracting Address Of Record\n");	  goto error;     }     if (_m->expires) {	  e = ((exp_body_t*)_m->expires->parsed)->val;     }     if (from)       LOG(L_ERR, "pa_handle_registration: from=%.*s p_uri=%.*s expires=%d\n", 	   from->uri.len, from->uri.s, p_uri.len, p_uri.s, e);     lock_pdomain(d);	     if (find_presentity(d, &p_uri, &presentity) > 0) {	  LOG(L_ERR, "pa_handle_registration: find_presentity did not find presentity\n");	  if (e > 0) {	       if (create_presentity_only(_m, d, &p_uri, &presentity) < 0) {		    LOG(L_ERR, "pa_handle_registration(): Error while creating new presentity\n");		    goto error2;	       }	  } #if 0	  else {	       presence_tuple_t *tuple = NULL;	       if (_m->contact) {		    struct hdr_field* ptr = _m->contact;		    while (ptr) {			 if (ptr->type == HDR_CONTACT) {			      if (!ptr->parsed && (parse_contact(ptr) < 0)) {				   goto next;			      }			 }			 if (find_presence_tuple(contact, presentity, &tuple) == 0) {			      tuple->state = PS_OFFLINE;			 }		    next:			 ptr = ptr->next;		    }	       }	       db_update_presentity(presentity);	  }#endif     }     if (presentity && e > 0) {	  LOG(L_ERR, "pa_handle_registration about to call d->reg p=%p expires=%d", presentity, e);	  d->reg(&presentity->uri, &presentity->uri, (void*)callback, presentity);     }     LOG(L_ERR, "pa_handle_registration about to return 1");     unlock_pdomain(d);     return 1;	 error2:     LOG(L_ERR, "pa_handle_registration about to return -1\n");     unlock_pdomain(d);     return -1; error:     LOG(L_ERR, "pa_handle_registration about to return -2\n");     return -1;}/* * Handle a subscribe Request */int handle_subscription(struct sip_msg* _m, char* _domain, char* _s2){	struct pdomain* d;	struct presentity *p;	struct watcher* w;	str p_uri;	LOG(L_ERR, "handle_subscription() entered\n");	get_act_time();	paerrno = PA_OK;	if (parse_hfs(_m, 1) < 0) {		LOG(L_ERR, "handle_subscription(): Error while parsing message header\n");		goto error;	}	if (check_message(_m) < 0) {		LOG(L_ERR, "handle_subscription(): Error while checking message\n");		goto error;	}	d = (struct pdomain*)_domain;	if (get_pres_uri(_m, &p_uri) < 0) {		LOG(L_ERR, "handle_subscription(): Error while extracting presentity URI\n");		goto error;	}	lock_pdomain(d);		if (find_presentity(d, &p_uri, &p) > 0) {		if (create_presentity(_m, d, &p_uri, &p, &w) < 0) {			LOG(L_ERR, "handle_subscription(): Error while creating new presentity\n");			goto error2;		}	} else {		if (update_presentity(_m, d, p, &w) < 0) {			LOG(L_ERR, "handle_subscription(): Error while updating presentity\n");			goto error2;		}	}	if (send_reply(_m) < 0) {	  LOG(L_ERR, "handle_subscription(): Error while sending reply\n");	  goto error2;	}	if (p) {		p->flags |= PFLAG_WATCHERINFO_CHANGED;	}	if (w) {		w->flags |= WFLAG_SUBSCRIPTION_CHANGED;	}	LOG(L_ERR, "handle_subscription about to return 1: w->event_package=%d w->accept=%d p->flags=%x w->flags=%x w=%p\n",	    (w ? w->event_package : -1), (w ? w->accept : -1), (p ? p->flags : -1), (w ? w->flags : -1), w);	unlock_pdomain(d);	return 1;	 error2:	LOG(L_ERR, "handle_subscription about to return -1\n");	unlock_pdomain(d);	return -1; error:	LOG(L_ERR, "handle_subscription about to send_reply and return -2\n");	send_reply(_m);	return -1;}/* * Returns 1 if subscription exists and -1 if not */int existing_subscription(struct sip_msg* _m, char* _domain, char* _s2){	struct pdomain* d;	struct presentity* p;	struct watcher* w;	str p_uri, w_uri;	str w_dn;	int et = 0;	if (_m->event) {		event_t *event = (event_t*)(_m->event->parsed);		et = event->parsed;	} else {		LOG(L_ERR, "existing_subscription defaulting to EVENT_PRESENCE\n");		et = EVENT_PRESENCE;	}	paerrno = PA_OK;	if (parse_from_header(_m) < 0) {		paerrno = PA_PARSE_ERR;		LOG(L_ERR, "existing_subscription(): Error while parsing From header field\n");		goto error;	}	d = (struct pdomain*)_domain;	if (get_pres_uri(_m, &p_uri) < 0) {		LOG(L_ERR, "existing_subscription(): Error while extracting presentity URI\n");		goto error;	}	if (get_watch_uri(_m, &w_uri, &w_dn) < 0) {		LOG(L_ERR, "existing_subscription(): Error while extracting watcher URI\n");		goto error;	}	lock_pdomain(d);		if (find_presentity(d, &p_uri, &p) == 0) {		if (find_watcher(p, &w_uri, et, &w) == 0) {			LOG(L_ERR, "existing_subscription() found watcher\n");			unlock_pdomain(d);			return 1;		}	}	unlock_pdomain(d);	return -1; error:	send_reply(_m);       	return 0;}/* * Returns 1 if possibly a user agent can handle SUBSCRIBE * itself, 0 if it cannot for sure */int pua_exists(struct sip_msg* _m, char* _domain, char* _s2){	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -