Esempio n. 1
0
char bt_already_registered_device(bdaddr_t add) {
	if (!bt_devices_table) {
		bt_devices_table = cfuhash_new_with_initial_size(200);
	}
	char string_add[18]; 
	memset(string_add, 0, 18);
	ba2str((const bdaddr_t *)&(add), string_add);

	return (char)(cfuhash_exists(bt_devices_table, string_add));
}
Esempio n. 2
0
/*
        Input arguments have a pattern of -option argument -option argument
        For example -u username -p password where username is the name of
        the user who wishes to log in and password is the password for that user
*/
int parseArguments(int argc, char *argv[]) {
             	
        // flag indicating the result
        bool passwordRequested = false;

	argumentInit();

	// if the user did not pass any credentials, then take them from the config file
	/*
	if(argc == 1)		
		getCredentialsFromConfigFile();
	*/

	int i;
        for(i = 1; i < argc;)
        {	
		if(argv[i][0] != '-') {
			fputs("Invalid Option\n", stderr);
			return -1;
		}	

		char *option = argv[i];	
		if(strcmp(option, "-p") == 0){
			passwordRequested = true;
			++i;
			continue;
		}

		if(cfuhash_exists(arguments, option)) {
	
			char * argument = cfuhash_get(arguments, option);
			if(argument[0] != 0){
				fputs("Criteria already set\n", stderr);
                        	return -1;	
			} else if (i == argc - 1) {
				fputs("Invalid Argument Input\n", stderr);
				return -1;
			} else {
				if(isOption(argv[i + 1]) == 0)
					return -1;
				// calloc(30, (sizeof (char)));	
				strlcpy(argument, argv[i + 1]);
				cfuhash_put(arguments, option, argument);
				i += 2;
			}
		} else {
  			fputs("Option not recognised\n", stderr);
                        return -1;
		}
	}

	if(passwordRequested) {
		fputs("Password: ", stdout);
		promptPasswordEntry();	
	}

	// TESTING
	// cfuhash_pretty_print(arguments, stdout);

        return 0;
}
Esempio n. 3
0
int isOption(char *argument) {	
	if(cfuhash_exists(arguments, argument))
		return 0;
	else		
		return -1;
}