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

📄 presentity.c

📁 性能优秀的SIP Proxy
💻 C
📖 第 1 页 / 共 2 页
字号:
	while (tuple) {		if (str_strcasecmp(&tuple->contact, _contact) == 0) {			*_t = tuple;			return 0;		}		tuple = tuple->next;	}	return 1;}void add_presence_tuple(presentity_t *_p, presence_tuple_t *_t){	presence_tuple_t *tuples = _p->tuples;	_p->tuples = _t;	_t->next = tuples;	if (tuples) {		tuples->prev = _t;	}}void remove_presence_tuple(presentity_t *_p, presence_tuple_t *_t){	presence_tuple_t *tuples = _p->tuples;	if (tuples == _t) {		_p->tuples = _t->next;	}	if (_t->prev) {		_t->prev->next = _t->next;	}	if (_t->next) {		_t->next->prev = _t->prev;	}}/* * Free all memory associated with a presence_tuple */void free_presence_tuple(presence_tuple_t * _t){	shm_free(_t);}/* * Print a presentity */void print_presentity(FILE* _f, presentity_t* _p){	watcher_t* ptr;	fprintf(_f, "--presentity_t---\n");	fprintf(_f, "uri: '%.*s'\n", _p->uri.len, ZSW(_p->uri.s));		if (_p->watchers) {		ptr = _p->watchers;		while(ptr) {			print_watcher(_f, ptr);			ptr = ptr->next;		}	}	if (_p->winfo_watchers) {		ptr = _p->winfo_watchers;		while(ptr) {			print_watcher(_f, ptr);			ptr = ptr->next;		}	}	fprintf(_f, "---/presentity_t---\n");}int timer_presentity(presentity_t* _p){	watcher_t* watcher, *t;	presence_tuple_t *tuple;	if (_p && _p->flags)	     LOG(L_ERR, "timer_presentity: _p=%p %.*s flags=%x watchers=%p\n", 		 _p, _p->uri.len, _p->uri.s, _p->flags, _p->watchers);	if (_p->flags & PFLAG_WATCHERINFO_CHANGED) {		watcher_t *w = _p->watchers;		while (w) {		     if (w && w->flags)			  LOG(L_ERR, "\t w=%p %.*s flags=%x\n", w, w->uri.len, w->uri.s, w->flags);		     if (w->flags & WFLAG_SUBSCRIPTION_CHANGED) {				if (send_notify(_p, w) < 0) {					LOG(L_ERR, "handle_subscription(): Error while sending notify\n");					/* FIXME: watcher and presentity should be test for removal here					 * (and possibly in other error cases too					 */				}				w->flags &= ~WFLAG_SUBSCRIPTION_CHANGED;			}			w = w->next;		}		notify_winfo_watchers(_p);		     /* We remove it here because a notify needs to be send first */		// if (w->expires == 0) free_watcher(w);		// if (p->slot == 0) free_presentity(p);	}	if (_p->flags & (PFLAG_PRESENCE_CHANGED			|PFLAG_PRESENCE_LISTS_CHANGED			|PFLAG_XCAP_CHANGED			|PFLAG_LOCATION_CHANGED)) {		notify_watchers(_p);	}	tuple = _p->tuples;	while (tuple) {	  presence_tuple_t *next_tuple = tuple->next;	  if (tuple->expires < act_time) {	    LOG(L_ERR, "Expiring tuple %.*s\n", tuple->contact.len, tuple->contact.s);	    remove_presence_tuple(_p, tuple);	  }	  tuple = next_tuple;	}	watcher = _p->watchers;	if (0) print_presentity(stdout, _p);	while(watcher) {	        if (watcher->expires <= act_time) {		  LOG(L_ERR, "Removing watcher %.*s\n", watcher->uri.len, watcher->uri.s);			watcher->expires = 0;			_p->flags |= PFLAG_WATCHERINFO_CHANGED;			send_notify(_p, watcher);			t = watcher;			watcher = watcher->next;			remove_watcher(_p, t);			free_watcher(t);			continue;		}				watcher = watcher->next;	}	watcher = _p->winfo_watchers;	while(watcher) {	        if (watcher->expires <= act_time) {		  LOG(L_ERR, "Removing watcher %.*s\n", watcher->uri.len, watcher->uri.s);			watcher->expires = 0;			_p->flags |= PFLAG_WATCHERINFO_CHANGED;			send_notify(_p, watcher);			t = watcher;			watcher = watcher->next;			remove_winfo_watcher(_p, t);			free_watcher(t);			continue;		}				watcher = watcher->next;	}	return 0;}/* * Add a new watcher to the list */int add_watcher(presentity_t* _p, str* _uri, time_t _e, int event_package, doctype_t _a, dlg_t* _dlg, 		str *_dn, struct watcher** _w){	if (new_watcher(_p, _uri, _e, event_package, _a, _dlg, _dn, _w) < 0) {		LOG(L_ERR, "add_watcher(): Error while creating new watcher structure\n");		return -1;	}	(*_w)->next = _p->watchers;	_p->watchers = *_w;	return 0;}/* * Remove a watcher from the list */int remove_watcher(presentity_t* _p, watcher_t* _w){	watcher_t* watcher, *prev;	watcher = _p->watchers;	prev = 0;		while(watcher) {		if (watcher == _w) {			if (prev) {				prev->next = watcher->next;			} else {				_p->watchers = watcher->next;			}			return 0;		}		prev = watcher;		watcher = watcher->next;	}		     /* Not found */	DBG("remove_watcher(): Watcher not found in the list\n");	return 1;}/* * Notify all watchers in the list */int notify_watchers(presentity_t* _p){	struct watcher* watcher = _p->watchers;	while(watcher) {		send_notify(_p, watcher);		watcher = watcher->next;	}	/* clear the flags */	_p->flags &= ~(PFLAG_PRESENCE_CHANGED		       |PFLAG_PRESENCE_LISTS_CHANGED		       |PFLAG_XCAP_CHANGED		       |PFLAG_LOCATION_CHANGED);	_p->flags &= ~(PFLAG_PRESENCE_LISTS_CHANGED | PFLAG_WATCHERINFO_CHANGED);	return 0;}/* * Notify all winfo watchers in the list */int notify_winfo_watchers(presentity_t* _p){	struct watcher* watcher;	watcher = _p->winfo_watchers;	if (watcher)	  LOG(L_ERR, "notify_winfo_watchers: presentity=%.*s winfo_watchers=%p\n", _p->uri.len, _p->uri.s, watcher);	while(watcher) {		LOG(L_ERR, "notify_winfo_watchers: watcher=%.*s\n", watcher->uri.len, watcher->uri.s);		send_notify(_p, watcher);		watcher = watcher->next;	}	/* clear the watcherinfo changed flag */	_p->flags &= ~PFLAG_WATCHERINFO_CHANGED;	return 0;}/* * Add a new watcher to the winfo_watcher list */int add_winfo_watcher(presentity_t* _p, str* _uri, time_t _e, int event_package, doctype_t _a, dlg_t* _dlg, 		      str *_dn, struct watcher** _w){	if (new_watcher(_p, _uri, _e, event_package, _a, _dlg, _dn, _w) < 0) {		LOG(L_ERR, "add_winfo_watcher(): Error while creating new watcher structure\n");		return -1;	}	(*_w)->preferred_mimetype = DOC_WINFO;	(*_w)->next = _p->winfo_watchers;	_p->winfo_watchers = *_w;	return 0;}/* * Remove a watcher from the list */int remove_winfo_watcher(presentity_t* _p, watcher_t* _w){	watcher_t* watcher, *prev;	watcher = _p->winfo_watchers;	prev = 0;		while(watcher) {		if (watcher == _w) {			if (prev) {				prev->next = watcher->next;			} else {				_p->winfo_watchers = watcher->next;			}			return 0;		}		prev = watcher;		watcher = watcher->next;	}		     /* Not found */	DBG("remove_winfo_watcher(): Watcher not found in the list\n");	return 1;}/* * Find a given watcher in the list */int find_watcher(struct presentity* _p, str* _uri, int _et, watcher_t** _w){	watcher_t* watcher;	/* first look for watchers */	watcher = _p->watchers;	if (_et != EVENT_PRESENCE_WINFO) {		while(watcher) {			if ((_uri->len == watcher->uri.len) &&			    (!memcmp(_uri->s, watcher->uri.s, _uri->len)) &&			    (watcher->event_package == _et)) {				*_w = watcher;				return 0;			}						watcher = watcher->next;		}	} else {		/* now look for winfo watchers */		watcher = _p->winfo_watchers;		while(watcher) {			if ((_uri->len == watcher->uri.len) &&			    (!memcmp(_uri->s, watcher->uri.s, _uri->len)) &&			    (watcher->event_package == _et)) {				*_w = watcher;				return 0;			}						watcher = watcher->next;		}	}		return 1;}resource_list_t *resource_list_append_unique(resource_list_t *list, str *uri){	resource_list_t *head = list;	resource_list_t *last = NULL;	fprintf(stderr, "resource_lists_append_unique: list=%p uri=%.*s\n", list, uri->len, uri->s);	while (list) {		if (str_strcasecmp(&list->uri, uri) == 0)		     return head;		last = list;		list = list->next;	}	list = (resource_list_t *)shm_malloc(sizeof(resource_list_t) + uri->len + 1);	list->uri.len = uri->len;	list->uri.s = ((char*)list) + sizeof(resource_list_t);	strncpy(list->uri.s, uri->s, uri->len);	list->uri.s[uri->len] = 0;	if (last) {		list->prev = last;		last->next = list;	}	if (head) {		return head;	} else {		return list;	}}resource_list_t *resource_list_remove(resource_list_t *list, str *uri){	resource_list_t *head = list;	resource_list_t *last = NULL;	resource_list_t *next = NULL;	while (list) {		if (str_strcasecmp(&list->uri, uri) == 0)			goto remove;		last = list;		list = list->next;	}	return head; remove:	next = list->next;	if (last)		last->next = next;	if (next)		next->prev = last;	shm_free(list);	if (head == list)		return next;	else		return head;}/* * Create a new presentity but no watcher list */int create_presentity_only(struct sip_msg* _m, struct pdomain* _d, str* _puri, 			   struct presentity** _p){	event_t *parsed_event;	int et = EVENT_PRESENCE;	if (_m && _m->event) {		parsed_event = (event_t *)_m->event->parsed;		et = parsed_event->parsed;	}	if (new_presentity(_d, _puri, _p) < 0) {		LOG(L_ERR, "create_presentity_only(): Error while creating presentity\n");		return -2;	}	add_presentity(_d, *_p);	return 0;}int pdomain_load_presentities(pdomain_t *pdomain){     if (use_db) {	  db_key_t query_cols[1];	  db_op_t  query_ops[1];	  db_val_t query_vals[1];	  db_key_t result_cols[4];	  db_res_t *res;	  int n_query_cols = 0;	  int n_result_cols = 0;	  int uri_col;	  int presid_col;	  int i;	  query_cols[n_query_cols] = "pdomain";	  query_ops[n_query_cols] = OP_EQ;	  query_vals[n_query_cols].type = DB_STR;	  query_vals[n_query_cols].nul = 0;	  query_vals[n_query_cols].val.str_val = *pdomain->name;	  n_query_cols++;	  result_cols[uri_col = n_result_cols++] = "uri";	  result_cols[presid_col = n_result_cols++] = "presid";	  if (pa_dbf.use_table(pa_db, presentity_table) < 0) {		  LOG(L_ERR, "pdomain_load_presentities: Error in use_table\n");		  return -1;	  }	  if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,			result_cols, n_query_cols, n_result_cols, 0, &res) < 0) {	       LOG(L_ERR, "pdomain_load_presentities: Error while querying presentity\n");	       return -1;	  }	  if (res) {	       for (i = 0; i < res->n; i++) {		    presentity_t *presentity = NULL;		    /* fill in tuple structure from database query result */		    db_row_t *row = &res->rows[i];		    db_val_t *row_vals = ROW_VALUES(row);		    int presid = row_vals[presid_col].val.int_val;		    str uri;		    if (!row_vals[uri_col].nul) {			 uri.s = (char*)row_vals[uri_col].val.string_val;			 uri.len = strlen(uri.s);		    }		    LOG(L_INFO, "pdomain_load_presentities: pdomain=%.*s presentity uri=%.*s presid=%d\n",			pdomain->name->len, pdomain->name->s, uri.len, uri.s, presid);		    new_presentity_no_wb(pdomain, &uri, &presentity);		    if (presentity) {			 add_presentity(pdomain, presentity);			 presentity->presid = presid;		    }	       }	       pa_dbf.free_result(pa_db, res);	  }	  	  { 	       presentity_t *presentity;	       for (presentity = pdomain->first; presentity; presentity = presentity->next) {		    db_read_watcherinfo(presentity);	       }	  }     }     return 0;}

⌨️ 快捷键说明

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