rem: ptr->uri.s = (char*)ptr + sizeof(presentity_t); memcpy(ptr->uri.s, _uri->s, _uri->len); ptr->uri.len = _uri->len; *_p = ptr;
add: presentity->uri.s = (char*)presentity + sizeof(presentity_t); memcpy(presentity->uri.s, _uri->s, _uri->len); presentity->uri.len = _uri->len; *_p = presentity;  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 = 1; int n_result_cols = 0; int basic_col, status_col, location_col;  LOG(L_INFO, "new_presentity: use_db starting\n");  query_cols[0] = "uri"; query_ops[0] = OP_EQ; query_vals[0].type = DB_STR; query_vals[0].nul = 0; query_vals[0].val.str_val = *_uri;  result_cols[basic_col = n_result_cols++] = "basic"; result_cols[status_col = n_result_cols++] = "status"; result_cols[location_col = n_result_cols++] = "location";  db_use_table(pa_db, presentity_table); if (db_query (pa_db, query_cols, query_ops, query_vals, result_cols, n_query_cols, n_result_cols, 0, &res) < 0) { LOG(L_ERR, "db_new_presentity(): Error while querying presentity\n"); return -1; } LOG(L_INFO, "new_presentity: getting values: res=%p res->n=%d\n", res, (res ? res->n : 0)); if (res && res->n > 0) {  db_row_t *row = &res->rows[0]; db_val_t *row_vals = ROW_VALUES(row); str basic = row_vals[basic_col].val.str_val;  str location = row_vals[location_col].val.str_val;  LOG(L_INFO, "  basic=%s location=%s\n", basic.s, location.s);  presentity->state = basic2status(basic); presentity->location = str_strdup(location);  } else {  LOG(L_INFO, "new_presentity: inserting into table\n"); if (db_insert(pa_db, query_cols, query_vals, n_query_cols) < 0) { LOG(L_ERR, "db_new_presentity(): Error while inserting presentity\n"); return -1; } } LOG(L_INFO, "new_presentity: use_db done\n"); }
context: int new_presentity(str* _uri, presentity_t** _p){	presentity_t* ptr;	if (!_uri || !_p) {		paerrno = PA_INTERNAL_ERROR;		LOG(L_ERR, "new_presentity(): Invalid parameter value\n");		return -1;	}	ptr = (presentity_t*)shm_malloc(sizeof(presentity_t) + _uri->len);	if (!ptr) {		paerrno = PA_NO_MEMORY;		LOG(L_ERR, "new_presentity(): No memory left\n");		return -1;	}	memset(ptr, 0, sizeof(presentity_t));	ptr->uri.s = (char*)ptr + sizeof(presentity_t);	memcpy(ptr->uri.s, _uri->s, _uri->len);	ptr->uri.len = _uri->len;	*_p = ptr;	return 0;}