rem: str *_dn, watcher_t** _w)
add: str *_dn, str *server_contact, watcher_t** _w)
context: int new_watcher(presentity_t *_p, str* _uri, time_t _e, int event_package, doctype_t _a, dlg_t* _dlg, 		str *_dn, watcher_t** _w){     int rc;     watcher_t* watcher;     /* Check parameters */     if (!_uri && !_dlg && !_w) {	  LOG(L_ERR, "new_watcher(): Invalid parameter value\n");	  return -1;     }     rc = new_watcher_no_wb(_p, _uri, _e, event_package, _a, _dlg, _dn, _w);     if (rc < 0) {	  return rc;     } else {	  watcher = *_w;     }     if (use_db) {	  db_key_t query_cols[11];	  db_op_t query_ops[11];	  db_val_t query_vals[11];	  db_key_t result_cols[5];	  db_res_t *res;	  int n_query_cols = 0;	  int n_result_cols = 0;	  int s_id_col, status_col, display_name_col, event_col;	  char *package = event_package_name[watcher->event_package];	  LOG(L_ERR, "new_watcher starting\n");	  query_cols[n_query_cols] = "r_uri";	  query_ops[n_query_cols] = OP_EQ;	  query_vals[n_query_cols].type = DB_STR;	  query_vals[n_query_cols].nul = n_query_cols;	  query_vals[n_query_cols].val.str_val.s = _p->uri.s;	  query_vals[n_query_cols].val.str_val.len = _p->uri.len;	  n_query_cols++;	  LOG(L_ERR, "new_watcher:  _p->uri=%.*s\n", _p->uri.len, _p->uri.s);	  query_cols[n_query_cols] = "w_uri";	  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.s = watcher->uri.s;	  query_vals[n_query_cols].val.str_val.len = watcher->uri.len;	  n_query_cols++;	  LOG(L_ERR, "db_new_watcher:  watcher->uri=%.*s\n", watcher->uri.len, watcher->uri.s);	  query_cols[n_query_cols] = "package";	  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.s = package;	  query_vals[n_query_cols].val.str_val.len = strlen(package);	  n_query_cols++;	  LOG(L_ERR, "new_watcher:  watcher->package=%s\n", package);	  result_cols[s_id_col = n_result_cols++] = "s_id";	  result_cols[status_col = n_result_cols++] = "status";	  result_cols[event_col = n_result_cols++] = "event";	  result_cols[display_name_col = n_result_cols++] = "display_name";			  if (pa_dbf.use_table(pa_db, watcherinfo_table) < 0) {		  LOG(L_ERR, "new_watcher: 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, "new_watcher: Error while querying tuple\n");		  return -1;	  }	  LOG(L_INFO, "new_watcher: getting values: res=%p res->n=%d\n",	      res, (res ? res->n : 0));	  if (res && res->n > 0) {	       /* fill in tuple structure from database query result */	       db_row_t *row = &res->rows[0];	       db_val_t *row_vals = ROW_VALUES(row);	       str s_id = { 0, 0 };	       str status = { 0, 0 };	       str event_str = { 0, 0 };	       watcher_event_t watcher_event = WE_SUBSCRIBE;	       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[status_col].nul) {		    status.s = row_vals[status_col].val.string_val;		    status.len = strlen(status.s);	       }	       if (!row_vals[event_col].nul) {		    event_str.s = row_vals[event_col].val.string_val;		    event_str.len = strlen(event_str.s);		    watcher_event = watcher_event_from_string(&event_str);	       }	       watcher->event = watcher_event;	       	       LOG(L_ERR, "new_watcher: status=%.*s\n", status.len, status.s);	       if (status.len) {		    watcher->status = watcher_status_from_string(&status);	       } else {		    watcher->status = WS_ACTIVE;	       }	       if (s_id.s) {		    strncpy(watcher->s_id.s, s_id.s, S_ID_LEN);		    watcher->s_id.len = strlen(s_id.s);	       }	  } else {	       watcher_assign_statement_id(_p, watcher);	       query_cols[n_query_cols] = "s_id";	       query_vals[n_query_cols].type = DB_STR;	       query_vals[n_query_cols].nul = 0;	       query_vals[n_query_cols].val.str_val.s = watcher->s_id.s;	       query_vals[n_query_cols].val.str_val.len = watcher->s_id.len;	       n_query_cols++;	       query_cols[n_query_cols] = "status";	       query_vals[n_query_cols].type = DB_STR;	       query_vals[n_query_cols].nul = 0;	       if (new_watcher_pending) {		    query_vals[n_query_cols].val.str_val.s = "pending";		    query_vals[n_query_cols].val.str_val.len = strlen("pending");	       } else {		    query_vals[n_query_cols].val.str_val.s = "active";		    query_vals[n_query_cols].val.str_val.len = strlen("active");	       }	       n_query_cols++;	       query_cols[n_query_cols] = "event";	       query_vals[n_query_cols].type = DB_STR;	       query_vals[n_query_cols].nul = 0;	       query_vals[n_query_cols].val.str_val = watcher_event_names[watcher->event];	       n_query_cols++;	       query_cols[n_query_cols] = "display_name";	       query_vals[n_query_cols].type = DB_STR;	       query_vals[n_query_cols].nul = 0;	       query_vals[n_query_cols].val.str_val.s = watcher->display_name.s;	       query_vals[n_query_cols].val.str_val.len = watcher->display_name.len;	       n_query_cols++;	       query_cols[n_query_cols] = "accepts";	       query_vals[n_query_cols].type = DB_INT;	       query_vals[n_query_cols].nul = 0;	       query_vals[n_query_cols].val.int_val = watcher->preferred_mimetype;	       n_query_cols++;	       query_cols[n_query_cols] = "expires";	       query_vals[n_query_cols].type = DB_INT;	       query_vals[n_query_cols].nul = 0;	       query_vals[n_query_cols].val.int_val = watcher->expires;	       n_query_cols++;	       /* insert new record into database */	       LOG(L_INFO, "new_watcher: inserting %d cols into table\n", n_query_cols);	       if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols)				   < 0) {		    LOG(L_ERR, "new_watcher: Error while inserting tuple\n");		    return -1;	       }	  }	  if (res)	       pa_dbf.free_result(pa_db, res);     }     return 0;}