rem: DBG("----<%.*s>:%d -> p=%p\n", sock_str.len,sock_str.s,port,sock );
context: int preload_udomain(db_con_t* _c, udomain_t* _d){	char b[256];	db_key_t columns[11];	db_res_t* res;	db_row_t* row;	int i, cseq;	unsigned int flags;	struct socket_info  *sock;	unsigned int port;	char *p;	str user, contact, callid, ua, received, sock_str;	str* rec;	char* domain;	time_t expires;	qvalue_t q;	urecord_t* r;	ucontact_t* c;	columns[0] = user_col.s;	columns[1] = contact_col.s;	columns[2] = expires_col.s;	columns[3] = q_col.s;	columns[4] = callid_col.s;	columns[5] = cseq_col.s;	columns[6] = flags_col.s;	columns[7] = user_agent_col.s;	columns[8] = received_col.s;	columns[9] = sock_col.s;	columns[10] = domain_col.s;		memcpy(b, _d->name->s, _d->name->len);	b[_d->name->len] = '\0';	if (ul_dbf.use_table(_c, b) < 0) {		LOG(L_ERR, "preload_udomain(): Error in use_table\n");		return -1;	}	if (ul_dbf.query(_c, 0, 0, 0, columns, 0, (use_domain) ? (11) : (10), 0,				&res) < 0) {		LOG(L_ERR, "preload_udomain(): Error while doing db_query\n");		return -1;	}	if (RES_ROW_N(res) == 0) {		DBG("preload_udomain(): Table is empty\n");		ul_dbf.free_result(_c, res);		return 0;	}	lock_udomain(_d);	for(i = 0; i < RES_ROW_N(res); i++) {		row = RES_ROWS(res) + i;				user.s      = (char*)VAL_STRING(ROW_VALUES(row));		if (user.s == 0) {			LOG(L_CRIT, "preload_udomain: ERROR: bad username "							"record in table %s\n", b);			LOG(L_CRIT, "preload_udomain: ERROR: skipping...\n");			continue;		} else {			user.len = strlen(user.s);		}		contact.s = (char*)VAL_STRING(ROW_VALUES(row) + 1);		if (contact.s == 0) {			LOG(L_CRIT, "preload_udomain: ERROR: bad contact "							"record in table %s\n", b);			LOG(L_CRIT, "preload_udomain: ERROR: for username %.*s\n",							user.len, user.s);			LOG(L_CRIT, "preload_udomain: ERROR: skipping...\n");			continue;		} else {			contact.len = strlen(contact.s);		}		expires     = VAL_TIME  (ROW_VALUES(row) + 2);		q           = double2q(VAL_DOUBLE(ROW_VALUES(row) + 3));		cseq        = VAL_INT   (ROW_VALUES(row) + 5);		callid.s    = (char*)VAL_STRING(ROW_VALUES(row) + 4);		if (callid.s == 0) {			LOG(L_CRIT, "preload_udomain: ERROR: bad callid record in"							" table %s\n", b);			LOG(L_CRIT, "preload_udomain: ERROR: for username %.*s,"							" contact %.*s\n",							user.len, user.s, contact.len, contact.s);			LOG(L_CRIT, "preload_udomain: ERROR: skipping...\n");			continue;		} else {			callid.len  = strlen(callid.s);		}		flags  = VAL_BITMAP(ROW_VALUES(row) + 6);		ua.s  = (char*)VAL_STRING(ROW_VALUES(row) + 7);		if (ua.s) {			ua.len = strlen(ua.s);		} else {			ua.len = 0;		}		if (!VAL_NULL(ROW_VALUES(row) + 8)) {			received.s  = (char*)VAL_STRING(ROW_VALUES(row) + 8);			if (received.s) {				received.len = strlen(received.s);				rec = &received;			} else {				received.len = 0;				rec = 0;			}		} else {			rec = 0;		}		if (!VAL_NULL(ROW_VALUES(row) + 9)) {			sock_str.s  = (char*)VAL_STRING(ROW_VALUES(row) + 9);			if ( (p=strchr(sock_str.s,'_'))!=0 && *(p+1)) {				sock_str.s = p+1;				sock_str.len = strlen(sock_str.s);				if (str2int( &sock_str, &port)!=0) {					LOG(L_ERR,"preload_udomain(): bad port <%.*s> in "						"socket\n",sock_str.len,sock_str.s);					port = SIP_PORT;				}				sock_str.s = (char*)VAL_STRING(ROW_VALUES(row) + 9);				sock_str.len = p - sock_str.s;			} else {				sock_str.len = strlen(sock_str.s);				port = SIP_PORT;			}			sock = grep_sock_info( &sock_str, (unsigned short)port,					PROTO_NONE /*FIXME - correct proto?*/);		} else {			sock = 0;		}		DBG("----<%.*s>:%d -> p=%p\n", sock_str.len,sock_str.s,port,sock );		if (use_domain) {			domain    = (char*)VAL_STRING(ROW_VALUES(row) + 10);			snprintf(b, 256, "%.*s@%s", user.len, ZSW(user.s), domain);			user.s = b;			user.len = strlen(b);		}		if (get_urecord(_d, &user, &r) > 0) {			if (mem_insert_urecord(_d, &user, &r) < 0) {				LOG(L_ERR, "preload_udomain(): Can't create a record\n");				ul_dbf.free_result(_c, res);				unlock_udomain(_d);				return -2;			}		}				if (mem_insert_ucontact(r, &contact, expires, q, &callid, cseq, flags, &c, &ua, rec, sock) < 0) {			LOG(L_ERR, "preload_udomain(): Error while inserting contact\n");			ul_dbf.free_result(_c, res);			unlock_udomain(_d);			return -3;		}		     /* We have to do this, because insert_ucontact sets state to CS_NEW		      * and we have the contact in the database already			  * we also store zombies in database so we have to restore			  * the correct state		      */		c->state = CS_SYNC;	}	ul_dbf.free_result(_c, res);	unlock_udomain(_d);	return 0;}