Esempio n. 1
0
int main(int argc, char **argv)
{
    try
    {
        CL_SetupCore setup_core;

        CL_ConsoleWindow console("Console");

        CL_String database = CL_PathHelp::normalize("Database/clanlib.db");

        CL_SqliteConnection connection(database);

        show_all_users(connection);
        show_specific_user(connection, 1);
        show_specific_user_characters(connection, 1);

        int id = create_new_user(connection, "testuser", "test", "Test User");
        show_specific_user(connection, id);

        update_user_realname(connection, id, "Real Name");
        show_specific_user(connection, id);

        show_all_users(connection);
        delete_specific_user(connection, id);
        show_all_users(connection);

        console.display_close_message();

    }
    catch (CL_Exception &e)
    {
        CL_ConsoleWindow console("Console");
        CL_Console::write_line("Exception caught: " + e.get_message_and_stack_trace());
        console.display_close_message();
        return 0;
    }
    return 1;
}
void
user_edit_dialog::done(int r)
{
  bool success = false;
  if(QDialog::Accepted==r) {
    // ok was pressed
    if (check_valid()) {
      user u;
      get_user_fields(u);
      db_ctxt dbc;
      dbc.propagate_exceptions = true;
      try {
	dbc.m_db->begin_transaction();
	if (m_mode==new_user) {
	  success = create_new_user(u, &dbc);
	}
	else
	  success = update_user(u, &dbc);
	if (success)
	  success = update_granted_roles(u, &dbc);
	dbc.m_db->commit_transaction();
      }
      catch(db_excpt& p) {
	DBG_PRINTF(3, "exception caugth");
	dbc.m_db->rollback_transaction();
	success = false;
	DBEXCPT (p);
      }
      if (success)
	QDialog::done(r);
    }
  }
  else {
    QDialog::done(r);
  }
}
Esempio n. 3
0
int main(){

	int i, j;
	FILE* fp = fopen("sample2.bin", "wb+");
	if (fp){
		//create memory
		track* root = (track*)malloc(sizeof(track));
		root->users = (user**)malloc(sizeof(user*)* 20);
		for (int k = 0; k < 20; k++){
			root->users[k] = (user*)malloc(sizeof(user));
		}
		root->count = 0;
		for (i = 0; i < 20; i++){
			root->users[i]->cat = (category**)malloc(sizeof(category*)* 5);
			long k;
			for (k = 0; k < 5; k++){
				root->users[i]->cat[k] = (category*)malloc(sizeof(category));
			}
			root->users[i]->number_of_categories = 0;

			for (j = 0; j < 5; j++){
				root->users[i]->cat[j]->mes = (message**)malloc(sizeof(message*)* 10);
				for (k = 0; k < 10; k++){
					root->users[i]->cat[j]->mes[k] = (message*)malloc(sizeof(message));
					root->users[i]->cat[j]->mes[k]->rep = (reply**)malloc(sizeof(reply*)* 10);
					long l= 0;
					for (l = 0; l < 10; l++){
						root->users[i]->cat[j]->mes[k]->rep[l] = (reply*)malloc(sizeof(reply));
					}
					root->users[i]->cat[j]->mes[k]->number_of_reply = 0;
				}
			}
		}

	
		char ch = '\0';
		char check = '1';
		int u, loginflag=0;
		while (check == '1'){
			if(loginflag == 0){
				printf("1.Create user\n 2.login");
				fflush(stdin);
				scanf("%c", &ch);
				if (ch == '1'){
						create_new_user(root, fp);
				}
				for (i = 0; i < root->count; i++){
					char buff[20];
					int offset = root->users[i]->user_offset;	
					fseek(fp, offset, SEEK_SET);
					fread(buff, 20, 1, fp);
					printf("%d . %s\n", i, buff);
				}
				if (ch == '2'){
					loginflag=1;
					printf("\n login as :");
					fflush(stdin);
					scanf("%d",&u);
				}
			}
			if(loginflag == 1){
				printf("\n2.Create category for existent user\n3.Create message\n4.Send reply\n5.Delete message\n");
				fflush(stdin);
				scanf("%c", &ch);				
				
				if (ch != '\0' && ch != '\n'){
					if (ch == '2'){
						create_category_for_user(root, u, fp);
					}
					if (ch == '3'){
						create_message(root, u, fp);
					}
					if (ch == '4'){
						send_reply(root, u, fp);
					}
					if (ch == '5'){
						delete_message(root, u, fp);
					}
					
				}
			}
			printf("1.continue \n2.exit");
			fflush(stdin);
			scanf("%c", &check);
		}
		

	}

	getch();
	return 0;

}
Esempio n. 4
0
int main(int argc, char **argv) {
	char *username = NULL;
	char *password = NULL;
	char *xmpp_server = NULL;
	char *huelink = NULL;
	char *userid = NULL;
	char pubsub_server[80];
	int xmpp_server_port = 5223;
	int verbose = 0;
	int current_arg_num = 1;
	char *current_arg_name = NULL;
	char *current_arg_val = NULL;
	struct sigaction sig_int_handler;
        char *time=NULL;
	FILE *fd;
	int time_val=0;
	// Add SIGINT handler
	sig_int_handler.sa_handler = int_handler;
	sigemptyset(&sig_int_handler.sa_mask);
	sig_int_handler.sa_flags = 0;
	sigaction(SIGINT, &sig_int_handler, NULL );

	if (argc == 1 || !strcmp(argv[1], "-help")) {
		print_usage(argv[0]);
		return -1;
	}

	while (current_arg_num < argc) {
		current_arg_name = argv[current_arg_num++];

		if (strcmp(current_arg_name, "-help") == 0) {
			print_usage(argv[0]);
			return -1;
		}

		if (strcmp(current_arg_name, "-verbose") == 0) {
			verbose = 1;
			continue;
		}

		if (current_arg_num == argc) {
			print_usage(argv[0]);
			return -1;
		}

		current_arg_val = argv[current_arg_num++];

		if (strcmp(current_arg_name, "-u") == 0) {
			username = current_arg_val;
			xmpp_server = _sox_get_server(username);
			if (xmpp_server == NULL ) {
				fprintf(stderr, "Invalid JID, use format user@domain\n");
				//return SOX_ERROR_INVALID_JID;
				return -1;
			}
			strcpy(pubsub_server, "pubsub.");
			strcat(pubsub_server, xmpp_server);
		} else if (strcmp(current_arg_name, "-p") == 0) {
			password = current_arg_val;
		} else if (strcmp(current_arg_name, "-link") == 0) {
			huelink = current_arg_val;
			fd = fopen("huelink.dat", "w");
			if (fd == NULL ) {
				fprintf(stdout,
						"Cannot create a huelink.dat file to store a address to access hue bridge\n");
				return 0;
			}
			if (huelink != NULL ) {
				fprintf(fd, "%s", huelink);
				fprintf(stdout, "Stored Address (%s) in huelink.dat\n",
						huelink);
				fclose(fd);
				exit(1);
			} else {
				fprintf(fd, "Hue Link/Address missing..Aborting\n");
				print_usage(argv[0]);
				fclose(fd);
				exit(1);
			}

		}

		else if(strcmp(current_arg_name,"-time")==0) 
			time = current_arg_val;

		else if (strcmp(current_arg_name, "-set_userid") == 0) {
			if ((hue_login_information() < 0))
				printf(
						"Missing Address of Hue-Bridge\nCannot Create Username\nAborting\n");

			userid = current_arg_val;
			if (create_new_user(userid)) {
				fprintf(stdout,
						"\nUser Id stored in Hue Bridge and username.dat file\n ");
				exit(0);
			} else {
				fprintf(stdout,
						"Error, Press the Center Button on Hue Bridge before setting up the userid\n");
				exit(1);
			}

		}

		else {
			fprintf(stderr, "Unknown argument: %s\n", current_arg_name);
			print_usage(argv[0]);
			return -1;
		}
	}

	if (username == NULL ) {
		fprintf(stderr, "Username missing\n");
		print_usage(argv[0]);
		return -1;
	} else if (password == NULL ) {
		fprintf(stderr, "Password missing\n");
		print_usage(argv[0]);
		return -1;
	}

	if (verbose) {
		fprintf(stdout, "XMPP Server: %s\n", xmpp_server);
		fprintf(stdout, "XMPP Server Port: %d\n", xmpp_server_port);
		fprintf(stdout, "XMPP PubSub Server: %s\n", pubsub_server);
		fprintf(stdout, "Username: %s\n", username);
		fprintf(stdout, "Verbose: YES\n");
		fprintf(stdout, "\n");
	}

	conn = sox_conn_new();

	if (verbose == 0)
		sox_connect(username, password, SOX_LEVEL_ERROR,
				(sox_handler_conn) sox_conn_handler_presence_send, NULL, conn);
	else
		sox_connect(username, password, SOX_LEVEL_DEBUG,
				(sox_handler_conn) sox_conn_handler_presence_send, NULL, conn);

	if ((hue_login_information()) != 1) {
		printf("Address Information Missing for Hue Bridge\n.");
		printf(
				"Add them using -set_userid and -link option at command line\nAborting..\n");
		exit(0);
	}


	/*Checking Time-Delay Value*/
	if(time!=NULL)
		time_val = atoi(time);
	else
		time_val=0;

	if(time_val<1 && time_val>61) { 
	 	printf("Delay Value Entered is invalid. Using the default 2 second delay\n");
	        time_val=2;
	}
printf("not here\n");

/*Thread Argument is a Structure with following members*/
	thread1_args.conn = conn;
	thread1_args.verbose = verbose;
	thread1_args.delay=time_val;
	thread2_args.conn = conn;
	thread2_args.verbose = verbose;
	read_stub_data();

	hueid_read();
	/* Creating Thread to Publish Data */
	pthread_t thread1, thread2;
	pthread_create(&thread1, NULL, publish_hue_data, (void*) &thread1_args);
	pthread_create(&thread2, NULL, actuate_hue, (void*) &thread2_args);
	pthread_join(thread1, NULL );
	pthread_join(thread2, NULL );
	printf("Thread Joined \n");
	sleep(5);
	exit(0);
}
Esempio n. 5
0
int sox_response_check(sox_response_t *response, int verbose) {

	printf("Entered Response Check Function \n");

	sox_packet_t *packet;
	sox_data_t *data;
	sox_transducer_value_t *t;

	char t_value[10];
	int hue_option = 0, hue_value = 0;
	int hue_id = 0;
	char *event_node;
	event_node = (char*) malloc(256 * sizeof(char));

	if (response->response_type == SOX_RESPONSE_PACKET) {
		packet = (sox_packet_t *) response->response;
		if (packet->type == SOX_PACKET_DATA) {
			data = (sox_data_t*) packet->payload;
			strcpy(event_node, data->event);

			if ((hue_id = hueid_match(data->event)) != -1) {

				fprintf(stdout, "Found Event-Node[%s] with HUE-ID[%d]\n",
						event_node, hue_id);
			}

			/*Event Node Not present in the config file */
			else {
				printf(
						"No such event node exists in event_config.dat file. \n");
				exit(1);
			}

			
			t = data->transducers;
			while (t != NULL ) {

				if (strcmp(t->name, "State") == 0)
					hue_option = 1;

				else if (strcmp(t->name, "Brightness") == 0)

					hue_option = 2;

				else if (strcmp(t->name, "Hue") == 0)

					hue_option = 3;

				else if (strcmp(t->name, "Saturation") == 0)

					hue_option = 4;

				else if (strcmp(t->name, "transition") == 0)
					hue_option = 9;
				else if (strcmp(t->name, "scan") == 0) {
					get_all_light();
					break;
				} else if (strcmp(t->name, "set_username") == 0) {
					create_new_user(t->typed_value);
					break;
				} else {
					printf("Received Unknown tname \n");
					break;
				}

				/*Converting String to Integer to send the value*/
				strcpy(t_value, t->typed_value);
				hue_value = atoi(t_value);

				actuate_light(hue_id, hue_option, hue_value, verbose);

				t = t->next;
			}

		}
	}
	free(event_node);
	return SOX_OK;
}