Exemple #1
0
Fichier : file.c Projet : ejrh/ejrh
int fetch_labelled_key(FS *fs, unsigned long int label, const char *name, KEY_TYPE *type, unsigned long int *data)
{
    char temp[MAX_INTERNAL_NAME+1];
    
    sprintf(temp, "%ld/%s", label, name);
    
    return fetch_key(fs, temp, type, data);
}
Exemple #2
0
/* If there is a raw key pending, return it; otherwise return -1.  */
static int
grub_keyboard_getkey (void)
{
  int key;
  int is_break = 0;

  key = fetch_key (&is_break);
  if (key == -1)
    return -1;

  if (grub_keyboard_isr (key, is_break))
    return -1;
  if (is_break)
    return -1;
  return key;
}
Exemple #3
0
/*
Begins scanning for nearby bluetooth devices. If any, it checks the keystore whether
they're valid or not. Locks/unlocks the screen appropriately.

@param time_per_scan Time to wait for bluetooth devices to respond.
@param store The keystore containing valid bluetooth key devices.
*/
void start_daemon(int time_per_scan, key_store* store) {
    discovered_dev_t* nearby = (discovered_dev_t*)malloc(sizeof(discovered_dev_t)*NR_MAX_DISCOVERED_DEVICES);
    state_history history;
    init_history(&history);

    bool unlock_status = TRUE;
    bool previous_status = TRUE;
    while(TRUE) {
        int found = scan_nearby(NR_MAX_DISCOVERED_DEVICES, TIME_PER_SCAN, nearby);
        int i;
        bool status = FALSE;
        key_device_t* found_device = NULL;

        for(i = 0; i < found; i++) {
            key_device_t* current = (key_device_t*)malloc(sizeof(key_device_t));
            discovered_dev_t dev = nearby[i];
            current -> device_id = (char*)malloc(sizeof(char)*ID_LEN);
            str2ba(dev.addr, &(current->addr));
            int pos = -1;
            if((pos = check_existence(store,current)) >= 0) {
                status = TRUE;
                update_key(store, pos);
                found_device = fetch_key(store,pos);
                break;
            }
            free(current);
        }
        update_history(&history,status);
        update_lock_status(history,&unlock_status);
        previous_status = execute_status(unlock_status,previous_status, found_device);

        if(unlock_status == TRUE) {
            usleep(SLEEP_TIME*1000);
            continue;
        }
        usleep(250);
    }
}
int main(int argc, char**argv)
{
  if (argc != 3)
  {
    std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n";
    exit(-1);
  }
  char *mysqld_sock  = argv[1];
  const char *connectstring = argv[2];
  ndb_init();
  MYSQL mysql;

  /* Connect to mysql server and create table. */
  {
    if ( !mysql_init(&mysql) ) {
      std::cout << "mysql_init failed.\n";
      exit(-1);
    }
    if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
                             0, mysqld_sock, 0) )
      MYSQLERROR(mysql);

    mysql_query(&mysql, "CREATE DATABASE ndb_examples");
    if (mysql_query(&mysql, "USE ndb_examples") != 0)
      MYSQLERROR(mysql);

    create_table(mysql);
  }

  /* Connect to ndb cluster. */

  Ndb_cluster_connection cluster_connection(connectstring);
  if (cluster_connection.connect(4, 5, 1))
  {
    std::cout << "Unable to connect to cluster within 30 secs." << std::endl;
    exit(-1);
  }
  /* Optionally connect and wait for the storage nodes (ndbd's). */
  if (cluster_connection.wait_until_ready(30,0) < 0)
  {
    std::cout << "Cluster was not ready within 30 secs.\n";
    exit(-1);
  }

  Ndb myNdb(&cluster_connection,"ndb_examples");
  if (myNdb.init(1024) == -1) {      // Set max 1024 parallel transactions
    APIERROR(myNdb.getNdbError());
    exit(-1);
  }

  setup_records(&myNdb);

  if(populate(&myNdb) > 0)
    std::cout << "populate: Success!" << std::endl;

  if(update_key(&myNdb) > 0)
    std::cout << "update_key: Success!" << std::endl;

  if(update_scan(&myNdb) > 0)
    std::cout << "update_scan: Success!" << std::endl;

  if(fetch_key(&myNdb) > 0)
    std::cout << "fetch_key: Success!" << std::endl;

  if(update2_key(&myNdb) > 0)
    std::cout << "update2_key: Success!" << std::endl;

  if(delete_key(&myNdb) > 0)
    std::cout << "delete_key: Success!" << std::endl;

  return 0;
}
int check_node(ServerConfig *config, upload_progress_node_t *node, const char *key) {
  char *node_key = fetch_key(config, node->key);
  return strcasecmp(node_key, key) == 0 ? 1 : 0;
}