rem: if (find_watcher(_p, &w_uri, event_package, &watcher) != 0) { new_watcher_no_wb(_p, &w_uri, expires, event_package, accepts, NULL, &display_name, &server_contact, &watcher); } if (watcher) { watcher_status_t ws = watcher_status_from_string(&status); if (watcher->status != ws) watcher->flags |= WFLAG_SUBSCRIPTION_CHANGED; watcher->status = ws; watcher->event = watcher_event;  if (s_id.s) { strncpy(watcher->s_id.s, s_id.s, S_ID_LEN); watcher->s_id.len = strlen(s_id.s); } } } } pa_dbf.free_result(pa_db, res); LOG(L_ERR, "db_read_watcherinfo:  _p->uri='%s' done\n", _p->uri.s); } return 0;
add: if (new_watcher_no_wb(_p, &w_uri, expires, event_package, accepts, dlg, &display_name, &server_contact, &watcher) == 0) {  watcher_status_t ws = watcher_status_from_string(&status);  watcher->status = ws; watcher->event = watcher_event; watcher->document_index = doc_index;  if (s_id.s) { strncpy(watcher->s_id.s, s_id.s, S_ID_LEN); watcher->s_id.len = strlen(s_id.s); } if (event_package == EVENT_PRESENCE_WINFO) r = add_winfo_watcher(_p, watcher); else r = add_watcher(_p, watcher); if (r < 0) { LOG(L_ERR, "db_read_watcher(): Error while adding watcher\n"); free_watcher(watcher); } } else r = -1; } } pa_dbf.free_result(db, res); LOG(L_ERR, "db_read_watcherinfo:  _p->uri='%s' done\n", _p->uri.s);  return r;
context: int db_read_watcherinfo(presentity_t *_p){     if (use_db) {	  db_key_t query_cols[5];	  db_op_t query_ops[5];	  db_val_t query_vals[5];	  db_key_t result_cols[9];	  db_res_t *res;	  int n_query_cols = 1;	  int n_result_cols = 0;	  int w_uri_col, s_id_col, event_package_col, status_col, watcher_event_col, display_name_col, accepts_col, expires_col;	  // LOG(L_ERR, "db_read_watcherinfo starting\n");	  query_cols[0] = "r_uri";	  query_ops[0] = OP_EQ;	  query_vals[0].type = DB_STRING;	  query_vals[0].nul = 0;	  query_vals[0].val.string_val = _p->uri.s;	  LOG(L_ERR, "db_read_watcherinfo:  _p->uri='%s'\n", _p->uri.s);	  result_cols[w_uri_col = n_result_cols++] = "w_uri";	  result_cols[s_id_col = n_result_cols++] = "s_id";	  result_cols[event_package_col = n_result_cols++] = "package";	  result_cols[status_col = n_result_cols++] = "status";	  result_cols[display_name_col = n_result_cols++] = "display_name";	  result_cols[accepts_col = n_result_cols++] = "accepts";	  result_cols[expires_col = n_result_cols++] = "expires";	  result_cols[watcher_event_col = n_result_cols++] = "event";			  if (pa_dbf.use_table(pa_db, watcherinfo_table) < 0) {		  LOG(L_ERR, "db_read_watcherinfo: 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, "db_read_watcherinfo(): Error while querying watcherinfo\n");	       return -1;	  }	  if (res && res->n > 0) {	       /* fill in tuple structure from database query result */	       int i;	       for (i = 0; i < res->n; i++) {		    db_row_t *row = &res->rows[i];		    db_val_t *row_vals = ROW_VALUES(row);		    str w_uri = { 0, 0 };		    str s_id = { 0, 0 };		    str event_package_str = { 0, 0 };		    int event_package = EVENT_PRESENCE;		    str watcher_event_str = { 0, 0 };		    watcher_event_t watcher_event = WE_SUBSCRIBE;		    int accepts = row_vals[accepts_col].val.int_val;		    int expires = row_vals[expires_col].val.int_val;		    str status = { 0, 0 };		    str display_name = { 0, 0 };			str server_contact = { 0, 0};		    watcher_t *watcher = NULL;		    if (!row_vals[w_uri_col].nul) {			 w_uri.s = row_vals[w_uri_col].val.string_val;			 w_uri.len = strlen(w_uri.s);		    }		    if (!row_vals[s_id_col].nul) {			 s_id.s = row_vals[s_id_col].val.string_val;			 s_id.len = strlen(s_id.s);		    }		    if (!row_vals[event_package_col].nul) {			 event_package_str.s = row_vals[event_package_col].val.string_val;			 event_package_str.len = strlen(event_package_str.s);			 event_package = event_package_from_string(&event_package_str);		    }		    if (!row_vals[status_col].nul) {			 status.s = row_vals[status_col].val.string_val;			 status.len = strlen(status.s);		    }		    if (!row_vals[watcher_event_col].nul) {			 watcher_event_str.s = row_vals[watcher_event_col].val.string_val;			 watcher_event_str.len = strlen(watcher_event_str.s);			 watcher_event = watcher_event_from_string(&watcher_event_str);		    }		    if (!row_vals[display_name_col].nul) {			 display_name.s = row_vals[display_name_col].val.string_val;			 display_name.len = strlen(display_name.s);		    }			/* FIXME: read server_contact from DB */		    if (find_watcher(_p, &w_uri, event_package, &watcher) != 0) {			 new_watcher_no_wb(_p, &w_uri, expires, event_package, accepts, NULL, &display_name, &server_contact, &watcher);		    }		    if (watcher) {			 watcher_status_t ws = watcher_status_from_string(&status);			 if (watcher->status != ws)			      watcher->flags |= WFLAG_SUBSCRIPTION_CHANGED;			 watcher->status = ws;			 watcher->event = watcher_event;			     			 if (s_id.s) {			      strncpy(watcher->s_id.s, s_id.s, S_ID_LEN);			      watcher->s_id.len = strlen(s_id.s);			 }		    }	       }	  }	  pa_dbf.free_result(pa_db, res);	  LOG(L_ERR, "db_read_watcherinfo:  _p->uri='%s' done\n", _p->uri.s);     }     return 0;}