Пример #1
0
/* Process a SETDB command. */
yerr_t command_setdb(tcp_thread_t *thread, ydynabin_t *buff) {
	unsigned char *pdbname_len, dbname_len;
	char *dbname = NULL;
	void *ptr;
	yerr_t result = YENOERR;

	YLOG_ADD(YLOG_DEBUG, "SETDB command");
	// read dbname length
	if (connection_read_data(thread, buff, sizeof(dbname_len)) != YENOERR)
		goto error;
	pdbname_len = ydynabin_forward(buff, sizeof(dbname_len));
	dbname_len = *pdbname_len;
	YFREE(thread->dbname);
	if (dbname_len > 0) {
		// read dbname
		if (connection_read_data(thread, buff, (size_t)dbname_len) != YENOERR)
			goto error;
		ptr = ydynabin_forward(buff, (size_t)dbname_len);
		if ((dbname = YMALLOC((size_t)dbname_len + 1)) == NULL)
			goto error;
		memcpy(dbname, ptr, (size_t)dbname_len);
		thread->dbname = dbname;
	}
	// send the response to the client
	YLOG_ADD(YLOG_DEBUG, "SETDB command OK");
	CONNECTION_SEND_OK(thread);
	return (result);
error:
	YLOG_ADD(YLOG_WARN, "SETDB error");
	CONNECTION_SEND_ERROR(thread, RESP_ERR_SERVER);
	return (YEIO);
}
Пример #2
0
/* Process a STOP command. */
yerr_t command_stop(tcp_thread_t *thread, ybool_t sync, ybool_t compress, ybool_t serialized, ydynabin_t *buff) {
	YLOG_ADD(YLOG_DEBUG, "STOP command");
	// check running transaction
	if (thread->transaction == NULL)
		goto error;
	// rollback transaction
	database_transaction_rollback(thread->transaction);
	thread->transaction = NULL;
	CONNECTION_SEND_OK(thread);
	return (YENOERR);
error:
	YLOG_ADD(YLOG_WARN, "STOP error");
	CONNECTION_SEND_ERROR(thread, RESP_ERR_TRANSACTION);
	return (YEACCESS);
}
Пример #3
0
/* Process a START command. */
yerr_t command_start(tcp_thread_t *thread, ybool_t sync, ybool_t compress, ybool_t serialized, ydynabin_t *buff) {
	YLOG_ADD(YLOG_DEBUG, "START command");
	// rollback previous transaction
	if (thread->transaction != NULL)
		database_transaction_rollback(thread->transaction);
	// open transaction
	thread->transaction = database_transaction_start(thread->finedb->database, YTRUE);
	if (thread->transaction == NULL)
		goto error;
	CONNECTION_SEND_OK(thread);
	return (YENOERR);
error:
	YLOG_ADD(YLOG_WARN, "START error");
	CONNECTION_SEND_ERROR(thread, RESP_ERR_TRANSACTION);
	return (YEACCESS);
}
Пример #4
0
/* Process a LIST command. */
yerr_t command_list(tcp_thread_t *thread, ybool_t sync, ybool_t compress, ybool_t serialized, ydynabin_t *buff) {
	char last_byte = 0;
	yerr_t result;

	YLOG_ADD(YLOG_DEBUG, "LIST command");
	// send the response to the client
	result = CONNECTION_SEND_OK(thread);
	if (result != YENOERR)
		goto error;
	// send data
	if (database_list(thread->finedb->database, thread->transaction, thread->dbname, _command_list_loop, thread) != YENOERR)
		goto error;
	// send last byte
	if (write(thread->fd, &last_byte, 1) != 1)
		goto error;
	YLOG_ADD(YLOG_DEBUG, "LIST command OK");
	return (result);
error:
	YLOG_ADD(YLOG_WARN, "LIST error");
	CONNECTION_SEND_ERROR(thread, RESP_ERR_SERVER);
	return (YEIO);
}