/** * Create a new connection identifier * \param url database URL * \return connection identifier, or zero on error */ struct db_id* new_db_id(const str* url) { struct db_id* ptr; if (!url || !url->s) { LM_ERR("invalid parameter\n"); return 0; } ptr = (struct db_id*)pkg_malloc(sizeof(struct db_id)); if (!ptr) { LM_ERR("no private memory left\n"); goto err; } memset(ptr, 0, sizeof(struct db_id)); if (parse_db_url(ptr, url) < 0) { LM_ERR("error while parsing database URL: '%.*s' \n", url->len, url->s); goto err; } return ptr; err: if (ptr) pkg_free(ptr); return 0; }
/** * Create a new connection identifier * \param url database URL * \param pooling whether or not a pooled connection may be used * \return connection identifier, or zero on error */ struct db_id* new_db_id(const str* url, db_pooling_t pooling) { static int poolid=0; struct db_id* ptr; if (!url || !url->s) { LM_ERR("invalid parameter\n"); return 0; } ptr = (struct db_id*)pkg_malloc(sizeof(struct db_id)); if (!ptr) { LM_ERR("no private memory left\n"); goto err; } memset(ptr, 0, sizeof(struct db_id)); if (parse_db_url(ptr, url) < 0) { LM_ERR("error while parsing database URL: '%.*s' \n", url->len, url->s); goto err; } if (pooling == DB_POOLING_NONE) ptr->poolid = ++poolid; else ptr->poolid = 0; ptr->pid = my_pid(); return ptr; err: if (ptr) pkg_free(ptr); return 0; }