예제 #1
0
int deleteMsg(char *username, int mesgid) {
	char *query;
	int retval;
	sqlite3 *handle;
	char sMesgId[10];

	sprintf(sMesgId,"%d",mesgid);

	generateDeleteQuery(username,sMesgId,&query);

	getConnection(DBNAME, &handle);

	retval = sqlite3_exec(handle, ddl_create_table_users, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot setup the database");
		freeConnection(handle);
		return(-1);
	}

	retval = sqlite3_exec(handle, ddl_create_table_users, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot setup the database");
		freeConnection(handle);
		return(-1);
	}

	free(query);
	freeConnection(handle);
	return(retval);
}
예제 #2
0
int getNextMailId() {
	sqlite3_stmt *stmt;
	int retval;
	sqlite3 *handle;

	getConnection(DBNAME, &handle);

	retval = sqlite3_prepare_v2(handle, sel_max_mailid, -1, &stmt, 0);
	if (retval) {
		printf("Selecting data from DB Failed\n");
		freeConnection(handle);
		return -1;
	}

	// Read the number of rows fetched
	// int cols = sqlite3_column_count(stmt);
	retval = sqlite3_step(stmt);

	if(retval == SQLITE_ROW)
		retval = sqlite3_column_int(stmt,0) + 1;
	else
		retval = 1;

	sqlite3_finalize(stmt);
	freeConnection(handle);
	return(retval);
}
예제 #3
0
int setupDB() {
	int retval;
	sqlite3 *handle;

	printf("SETTING UP DATABASE\n");
	getConnection(DBNAME, &handle);

	retval = sqlite3_exec(handle, ddl_create_table_users, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot setup the database");
		freeConnection(handle);
		return(-1);
	}

	retval = sqlite3_exec(handle, ddl_create_table_mails, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot setup the database");
		freeConnection(handle);
		return(-1);
	}

	retval = sqlite3_exec(handle, ddl_create_table_mailboxes, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot setup the database");
		freeConnection(handle);
		return(-1);
	}

	printf("SETTING UP DATABASE...DONE\n");

	add_user(handle);

	freeConnection(handle);
	return (0);
}
예제 #4
0
파일: proxy.c 프로젝트: erictelmer/project3
int receive(int fd, fd_set * master, int *fdmax, int listener, char (* buf)[BUF_SIZE], connection_list_s *connection, stream_s *stream){
  int readret;
  int i;
  if ((readret = recv(fd, *buf, BUF_SIZE, 0)) > 0)//Check if connection closed
    {
      //Http handling//
      
      log_msg(log, "Read data from fd:%d", fd);
      return readret;
    } 
 
  if (readret <= 0){//If connection closed
    log_msg(log, "Connection closed on fd:%d",fd);
    close_socket(connection->server_sock);
    close_socket(connection->browser_sock);
    FD_CLR(connection->server_sock, master);
    FD_CLR(connection->browser_sock, master);

    log_msg(log, "Closing connection associated with sockets %d,%d because of %d\n", connection->server_sock, connection->browser_sock, fd);

    removeConnectionFromStream(connection, stream);
    freeConnection(connection);

    for(i=0; i<=*fdmax; i++){
      if(FD_ISSET(i, master)){
        log_msg(log, "FD_SET: %d", i);
      }
    }
    //change fdmax
  }
  return -1;
}
예제 #5
0
void TCPClient::handleConnectionBindErrorResponse(const stun::Message& response)
{
	TraceL << "ConnectionBind error response" << endl;
	
	auto transaction = reinterpret_cast<stun::Transaction*>(response.opaque);
	auto req = reinterpret_cast<RelayConnectionBinding*>(transaction->socket->opaque);

	// TODO: Handle properly

	freeConnection(req->peerAddress);
}
예제 #6
0
void SFtpConnectionCache::closeConnection(const QUrl &url)
{
    QString key(getKey(url));

    if (_connectionMap.contains(key))
    {
        freeConnection(findConnection(url));

        _connectionMap.remove(key);
    }
}
예제 #7
0
void TCPClient::onRelayConnectionClosed(void* sender)
{	
	auto ptr = reinterpret_cast<net::Socket*>(sender);
	auto req = reinterpret_cast<RelayConnectionBinding*>(ptr->opaque);
	auto socket = _connections.get(req->peerAddress);
	
	TraceL << "Relay connection closed: " << req->peerAddress << endl;	
	assert(connections().has(req->peerAddress));
	
	_observer.onRelayConnectionClosed(*this, socket, req->peerAddress);
	freeConnection(req->peerAddress);
}
예제 #8
0
void SFtpConnectionCache::closeAll()
{
    QMapIterator<QString, const SFtpConnection *> it(_connectionMap);

    while (it.hasNext())
    {
        it.next();

        freeConnection(it.value());
    }

    _connectionMap.clear();
}
int driverMySQL_disconnect(struct xsb_connectionHandle* handle)
{
	int i, j;

	for (i = 0 ; i < numHandles ; i++)
	{
		if (!strcmp(handle->handle, mysqlHandles[i]->handle))
		{
			mysql_close(mysqlHandles[i]->mysql);
			freeConnection(mysqlHandles[i]);
			for (j = i + 1 ; j < numHandles ; j++)
				mysqlHandles[j-1] = mysqlHandles[j];
			numHandles--;
			break;
		}
	}

	return SUCCESS;
}
jint
shmemBase_accept(SharedMemoryTransport *transport,
                 long timeout,
                 SharedMemoryConnection **connectionPtr)
{
    jint error;
    SharedMemoryConnection *connection;

    clearLastError();

    CHECK_ERROR(sysEventWait(NULL, transport->attachEvent, timeout));

    error = createConnection(transport, transport->shared->attachingPID,
                             &connection);
    if (error != SYS_OK) {
        /*
         * Reject the attacher
         */
        transport->shared->isAccepted = JNI_FALSE;
        sysEventSignal(transport->acceptEvent);

        freeConnection(connection);
        return error;
    }

    transport->shared->isAccepted = JNI_TRUE;
    error = sysEventSignal(transport->acceptEvent);
    if (error != SYS_OK) {
        /*
         * No real point trying to reject it.
         */
        closeConnection(connection);
        return error;
    }

    *connectionPtr = connection;
    return SYS_OK;
}
예제 #11
0
int fetch_user_data(char *username, char *password, struct userdata **user) {
	char *query;
	struct userdata *result;
	int col_username = 0;
	int col_password = 1;
	sqlite3_stmt *stmt;
	int retval;
	sqlite3 *handle;
	int rowCount = 0;

	getConnection(DBNAME, &handle);

	generateUserQuery(username, password, &query);
	rowCount = getQueryCount(handle, query);
	if (rowCount > 0) {
		int rCounter = 0;
		retval = sqlite3_prepare_v2(handle, query, -1, &stmt, 0);
		if (retval) {
			printf("Selecting data from DB Failed\n");
			freeConnection(handle);
			return -1;
		}

		result = (struct userdata *) malloc (sizeof (struct userdata *) * rowCount);
		if (result == NULL) {
			perror("ERROR: Cannot allocate memory");
			freeConnection(handle);
			return(-1);
		}

		// Read the number of rows fetched
		// int cols = sqlite3_column_count(stmt);
		while(1)
		{
			// fetch a row's status
			retval = sqlite3_step(stmt);

			if(retval == SQLITE_ROW)
			{
				// SQLITE_ROW means fetched a row
				strcpy(result[rCounter].username,(const char*)sqlite3_column_text(stmt,col_username));
				strcpy(result[rCounter].password,(const char*)sqlite3_column_text(stmt,col_password));
				rCounter++;
			}
			else if(retval == SQLITE_DONE)
			{
				break;
			}
			else
			{
				// Some error encountered
				printf("Some error encountered\n");
				freeConnection(handle);
				return -1;
			}
		}
		sqlite3_finalize(stmt);
		*user = result;
	}

	free(query);
	freeConnection(handle);

	return(rowCount);
}
예제 #12
0
int fetch_mesg_data(char *username, int mesgId, struct emaildata **mail) {
	char *query;
	struct emaildata *result;
	int col_mesgId = 0;
	int col_mesgSize = 1;
	int col_mesgSubject = 2;
	int col_mesgBody = 3;
	int col_mesgFrom = 4;
	int col_mesgTo = 5;
	char sMesgId[10];
	sqlite3_stmt *stmt;
	int retval;
	sqlite3 *handle;
	int rowCount = 0;

	getConnection(DBNAME, &handle);

	sprintf(sMesgId, "%d", mesgId);

	generateMesgQuery(username, sMesgId, &query);
	rowCount = getQueryCount(handle, query);
	if (rowCount > 0) {
		int rCounter = 0;
		retval = sqlite3_prepare_v2(handle, query, -1, &stmt, 0);
		if (retval) {
			printf("Selecting data from DB Failed\n");
			freeConnection(handle);
			return -1;
		}

		result = (struct emaildata *) malloc (sizeof (struct emaildata *) * rowCount);
		if (result == NULL) {
			perror("ERROR: Cannot allocate memory");
			freeConnection(handle);
			return(-1);
		}

		// Read the number of rows fetched
		// int cols = sqlite3_column_count(stmt);
		while(1)
		{
			// fetch a row's status
			retval = sqlite3_step(stmt);

			if(retval == SQLITE_ROW)
			{
				// SQLITE_ROW means fetched a row
				result[rCounter].mesgid = sqlite3_column_int(stmt,col_mesgId);
				result[rCounter].mesgsize = sqlite3_column_int(stmt,col_mesgSize);
				strcpy(result[rCounter].subject,(const char*)sqlite3_column_text(stmt,col_mesgSubject));
				result[rCounter].body = (char *)malloc(sizeof(char *)*result[rCounter].mesgsize);
				if (result[rCounter].body == NULL) {
					perror("ERROR: Cannot allocate memory");
					sqlite3_finalize(stmt);
					free(query);
					freeConnection(handle);
					return(-1);
				}
				strcpy(result[rCounter].body,(const char*)sqlite3_column_text(stmt,col_mesgBody));
				//From
				result[rCounter].from = (char *)malloc(sizeof(char *)*50);
				if (result[rCounter].from == NULL) {
					perror("ERROR: Cannot allocate memory");
					sqlite3_finalize(stmt);
					free(query);
					freeConnection(handle);
					return(-1);
				}
				strcpy(result[rCounter].from,(const char*)sqlite3_column_text(stmt,col_mesgFrom));
				//TO
				result[rCounter].to = (char *)malloc(sizeof(char *)*50);
				if (result[rCounter].to == NULL) {
					perror("ERROR: Cannot allocate memory");
					sqlite3_finalize(stmt);
					free(query);
					freeConnection(handle);
					return(-1);
				}
				strcpy(result[rCounter].to,(const char*)sqlite3_column_text(stmt,col_mesgTo));
				rCounter++;
			}
			else if(retval == SQLITE_DONE)
			{
				break;
			}
			else
			{
				// Some error encountered
				printf("Some error encountered\n");
				freeConnection(handle);
				return -1;
			}
		}
		sqlite3_finalize(stmt);
		*mail = result;
	}

	free(query);
	freeConnection(handle);

	return(rowCount);
}
예제 #13
0
int fetch_list_data(char *username, struct listdata **list) {
	char *query;
	struct listdata *result;
	int col_mesgid = 0;
	int col_size = 1;
	sqlite3_stmt *stmt;
	int retval;
	sqlite3 *handle;
	int rowCount = 0;
	int stat_details = 0;
	int stat_sizesum = 0;

	generateListQuery(username, &query);
	getConnection(DBNAME, &handle);
	rowCount = getQueryCount(handle, query);

	result = (struct listdata *) malloc (sizeof (struct listdata *) * (rowCount + 1));
	if (result == NULL) {
		perror("ERROR: Cannot allocate memory");
		freeConnection(handle);
		return(-1);
	}

	if (rowCount > 0) {
		int rCounter = 0;
		retval = sqlite3_prepare_v2(handle, query, -1, &stmt, 0);
		if (retval) {
			printf("Selecting data from DB Failed\n");
			freeConnection(handle);
			return -1;
		}

		rCounter++;

		// Read the number of rows fetched
		// int cols = sqlite3_column_count(stmt);
		while(1)
		{
			// fetch a row's status
			retval = sqlite3_step(stmt);

			if(retval == SQLITE_ROW)
			{
				// SQLITE_ROW means fetched a row
				result[rCounter].count = rCounter;
				result[rCounter].mesgid = sqlite3_column_int(stmt,col_mesgid);
				result[rCounter].mesgsize = sqlite3_column_int(stmt,col_size);
				stat_sizesum += result[rCounter].mesgsize;
				rCounter++;
			}
			else if(retval == SQLITE_DONE)
			{
				break;
			}
			else
			{
				// Some error encountered
				printf("Some error encountered\n");
				freeConnection(handle);
				return -1;
			}
		}
		sqlite3_finalize(stmt);
	}

	//SET STAT DETAILS
	result[stat_details].count = stat_details;
	result[stat_details].mesgid = rowCount;
	result[stat_details].mesgsize = stat_sizesum;


	*list = result;

	free(query);
	freeConnection(handle);

	return(rowCount);
}
예제 #14
0
int storeMail(char *from, char to[50][100], char *subject, char *msg, int noRcpt) {
	char query[4000];
	char msgId[1000];
	char msgSize[1000];
	sqlite3 *handle;
	int iCount;
	int retval;

	sprintf( msgId, "%d", getNextMailId());
	sprintf( msgSize, "%d", (int)strlen(msg));

	memset(query,'0',4000);
	//INSERT MAIL
	strcpy(query,dml_insert_mails);
	strcat(query,msgId);
	strcat(query,", ");
	strcat(query,msgSize);
	strcat(query,", '");
	strcat(query,subject);
	strcat(query,"', '");
	strcat(query,msg);
	strcat(query,"')");

	getConnection(DBNAME, &handle);
	retval = sqlite3_exec(handle, query, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot insert data in the table");
		freeConnection(handle);
		return(-1);
	}

	//INSERT MAILBOX

	memset(query,'0',4000);
	for (iCount = 0; iCount < noRcpt; iCount++) {
		strcpy(query,dml_insert_mailboxes);
		strcat(query,msgId);
		strcat(query,", '");
		strcat(query,from);
		strcat(query,"', '");
		strcat(query,to[iCount]);
		strcat(query,"', 0)");

		retval = sqlite3_exec(handle, query, 0, 0, 0);
		if (retval == -1) {
			perror("ERROR: Cannot insert data in the table");
			freeConnection(handle);
			return(-1);
		}
	}

	memset(query,'0',4000);
	strcpy(query,"commit");

	retval = sqlite3_exec(handle, query, 0, 0, 0);
	if (retval == -1) {
		perror("ERROR: Cannot insert data in the table");
		freeConnection(handle);
		return(-1);
	}

	freeConnection(handle);
	return(0);
}