Exemple #1
0
static int main_keygen(char *home)
{
	create_curvedir(home);
	write_username(home);
	create_keypair(home);
	check_config_keypair_or_die(home);

	return 0;
}
/**
 * Determines the transaction code based on the enumeration value received
 *
 * @return buffer after transaction text line is composed and concatenated for file write
 **/
char* Transaction::write(char* dest){
	//prepare the code

	switch (this->code){
		case Transaction::Test:{
			//write code
			if( debug_transaction) printf("writing code\n");
			char* curr = write_code( dest, this->code);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write username
			if( debug_transaction) printf("writing username\n");
			curr = write_username( curr, this->username);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write buyer username
			if( debug_transaction) printf("writing buyer username\n");
			curr = write_username( curr, this->buyer);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write seller username
			if( debug_transaction) printf("writing seller username\n");
			curr = write_username( curr, this->seller);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write event name
			if( debug_transaction) printf("writing event name\n");
			curr = write_eventName( curr, this->eventName);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write type
			if( debug_transaction) printf("writing type\n");
			curr = write_type( curr, this->type);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write ticket amount
			if( debug_transaction) printf("writing ticket amount\n");
			curr = write_ticketAmount( curr, this->ticketAmount);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			curr = write_token( curr);
			//write ticket price
			if( debug_transaction) printf("writing ticket price\n");
			curr = write_ticketPrice( curr, this->ticketPrice);
			if( error) break;
			curr = write_token( curr);
			//write credit
			if( debug_transaction) printf("writing credit\n");
			curr = write_credit( curr, this->totalCredits);
			if( error) break;
			if( debug_transaction) printf("writing token\n");
			//good
			if( debug_transaction) printf("done\n");
			return dest;}

		//01-create, 02-delete, 06-addcredit, 00-end of session
		//(X field 2, U field 15, T field 2, C field 9, total 28 + 3 = 31)
		//XX_UUUUUUUUUUUUUUU_TT_CCCCCCCCC
		case Transaction::Create:
		case Transaction::Delete:
		case Transaction::AddCredit:{
			//write code
			char* curr = write_code( dest, this->code);
			if( error) break;
			curr = write_token( curr);

			//write username
			curr = write_username( curr, this->username);
			if( error) break;
			curr = write_token( curr);

			//write type
			curr = write_type( curr, this->type);
			if( error) break;
			curr = write_token( curr);

			//write credit
			curr = write_credit( curr, this->totalCredits);
			if( error) break;

			//done
			return dest;}

		//05-refund
		//(X field 2, U field 15, S field 15, C field 9, total 44)
		//XX_UUUUUUUUUUUUUUU_SSSSSSSSSSSSSSS_CCCCCCCCC
		case Transaction::Refund:{
			//write code
			char* curr = write_code( dest, this->code);
			if( error) break;
			curr = write_token( curr);

			//write buyer username
			curr = write_username( curr, this->buyer);
			if( error) break;
			curr = write_token( curr);

			//write seller username
			curr = write_username( curr, this->seller);
			if( error) break;
			curr = write_token( curr);

			//write credit
			curr = write_credit( curr, this->totalCredits);
			if( error) break;

			//done
			return dest;}

		//03-sell, 04-buy
		//(X field 2, E field 19, S field 15, T field 3, P field 6, total 45+4 = 49)
		//XX_EEEEEEEEEEEEEEEEEEE_SSSSSSSSSSSSSSS_TTT_PPPPPP
		case Transaction::Buy:
		case Transaction::Sell:{
			//write code
			char* curr = write_code( dest, this->code);
			if( error) break;
			curr = write_token( curr);

			//write seller username
			curr = write_username( curr, this->seller);
			if( error) break;
			curr = write_token( curr);

			//write ticket amount
			curr = write_ticketAmount( curr, this->ticketAmount);
			if( error) break;
			curr = write_token( curr);

			//write ticket price
			curr = write_ticketPrice( curr, this->ticketPrice);
			if( error) break;

			//done
			return dest;}

		//manage the error case
		default:{
			printf("%s\n", Error::TransactionInvalidCode);
			break;}}
	//handle the error case
	printf("%s\n", error_string);
	dest[0] = '\0';
	printf("transaction: {%s}\n", dest);
	return buffer;
}