Esempio n. 1
0
int main( int argc, char** argv ) {
	sqlite3* handle;

	if( !argv[0] || !argv[1] ) {
		fprintf( stderr, "Useage ./boltupdatedb <directory>\n" );
		return 1;
	}

	if( sqlite3_open( MEDIA_DB, &handle ) ) {
		perror("Error opening database "MEDIA_DB);
		return 1;
	}

	setup_database( handle );
	/* At this point it looks good */
	struct load_context context;
	context.directory = argv[1];;
	context.db = handle;
	
	printf("Loading music . . .\n");
	load_directory_root( &context );

	sqlite3_close( handle );

	return 0;
}
Esempio n. 2
0
Boolean PostListFormEventHandler(EventPtr event)
{
    static FormPtr gpForm;
    UInt16 postCount;

    switch (event->eType) {
    case frmOpenEvent: {
        postCount = 10; // If you exceed 10 you pop a warning and it gets trimmed.
        setup_database();
        FrmDrawForm(gpForm = FrmGetActiveForm());
        UpdatePostsTable(gpForm, postCount);

        return true;
    }
    case frmCloseEvent: {
        FrmEraseForm(gpForm);
        FrmDeleteForm(gpForm);
        return true;
    }
    case ctlSelectEvent: {
        switch (event->data.ctlSelect.controlID) {
        case HelpButton: {
            FrmCustomAlert(TheError,
                "Oops, looks like our connection goofed here, try again?",
                NULL, NULL);
            return true;
        }
        case PalmrMainMenuAbout: {
            FrmAlert(AboutAlert);
            return true;
        }
        }
    }
    case tblSelectEvent: {
        int row = event->data.tblSelect.row;
        int column = event->data.tblSelect.column;
        // char strRow[15];
        // char strColumn[15];
        //
        // sprintf(strRow, "%i", row);
        // sprintf(strColumn, "%i", column);

        // AlertPrintf3(
        //     "You selected:",
        //     strRow, strColumn);

        FrmGotoForm(PostViewForm);

        return true;
    }
    default: {
        return false;
    }
    }
}
Esempio n. 3
0
void
cut_setup(void)
{
  logger = setup_grn_logger();
  grn_ctx_init(&context, 0);
  GRN_VOID_INIT(&src);
  GRN_VOID_INIT(&dest);

  setup_database();
  setup_tables();
}
Esempio n. 4
0
static void
bench_startup(BenchmarkData *data)
{
  if (data->use_mruby) {
    g_setenv("GRN_MRUBY_ENABLED", "yes", TRUE);
  } else {
    g_setenv("GRN_MRUBY_ENABLED", "no", TRUE);
  }
  grn_ctx_init(&(data->context), 0);
  setup_database(data);
}
Esempio n. 5
0
/**
 * @brief check to make sure the copyright has been created
 *
 * will attempt to access the copyright table, if the response from the database
 * indicates that the copyright table does not exist, this will also attempt to
 * create the table for future use.
 *
 * @param pgConn the connection to the database
 * @return 1 if the table exists at the end of the function, 0 otherwise
 */
int check_copyright_table(PGconn* pgConn)
{
  /* local variables */
  PGresult* pgResult; // the result of the database access
  int ret;            // the value returned by this function
  char* str;          // the string error message if the database access fails
  char buffer[256];   // a buffer used for string manipulation

  /* initialize memory and do the sql access */
  ret = 1;
  str = NULL;
  memset(buffer, '\0', sizeof(buffer));
  pgResult = PQexec(pgConn, check_database_table);

  /* check if the database already exists */
  if(PQresultStatus(pgResult) != PGRES_TUPLES_OK)
  {
    str = PQresultErrorMessage(pgResult);
    if(longest_common(buffer, str, "does not exist") == 14)
    {
      fprintf(cerr, "WARNING %s.%d: Could not find copyright table.", __FILE__, __LINE__);
      ret = setup_database(pgConn);
    }
    else
    {
      fprintf(cerr, "ERROR %s.%d: problem with copyright table\n", __FILE__, __LINE__);
      fprintf(cerr, "ERROR PQ error message: %s\n", PQresultErrorMessage(pgResult));
      fprintf(cerr, "ERROR sql was: %s\n", check_database_table);
      ret = 0;
    }
    //free(str);
  }
  else
  {
    /* check if the copyright foreign key exsits */
    pgResult = PQexec(pgConn, check_copyright_foreign_key);
    if(PQntuples(pgResult) != 1)
    {
      ret = cleanup_copyright(pgConn);
    }
  }

  /* check if the copyright exsits */
  pgResult = PQexec(pgConn, check_copyright_ars);
  if(PQresultStatus(pgResult) != PGRES_TUPLES_OK && PQntuples(pgResult) != 1)
  {
    fo_CreateARSTable(pgConn, AGENT_ARS);
  }
  /* clean up memory and return */
  PQclear(pgResult);
  return ret;
}
Esempio n. 6
0
void
cut_setup(void)
{
  reset_variables();

  logger = setup_grn_logger();

  context = g_new(grn_ctx, 1);
  grn_ctx_init(context, 0);

  setup_database();

  result = grn_table_create(context, NULL, 0, NULL,
                            GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
                            comments, NULL);
  grn_test_assert_context(context);
}
Esempio n. 7
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //for our settings
    QCoreApplication::setOrganizationName("BengalBionics");
    QCoreApplication::setOrganizationDomain("bengalbionics.com");
    QCoreApplication::setApplicationName("Chhobi");
    setWindowIcon(QIcon(":Images/Icons/chhobi-icon.png"));

    setup_ui();
    restore_appearance();
    setup_connections();
    setup_database();
    setup_photo_root();
    load_photo_list();
    crawl();
}
Esempio n. 8
0
static void
out_of_sync(TABLE_INFO *table_data)
{
	/*
	 * We have five directories:
	 * - The main database directory that we just corrupted/salvaged.
	 * - A .SAVE copy of the main directory that is coherent prior to
	 *   corrupting. Essentially a copy of the second checkpoint dir.
	 * - A copy of the main directory before the first checkpoint. DB0
	 * - A copy of the main directory after the first checkpoint. DB1
	 * - A copy of the main directory after the second checkpoint. DB2
	 *
	 * We want to make a copy of a source directory and then copy a
	 * turtle or metadata file from another directory. Then detect the
	 * error, run with salvage and confirm.
	 */
	/*
	 * Run in DB0, bring in future metadata from DB1.
	 */
	test_out_of_sync = true;
	printf(
	    "#\n# OUT OF SYNC: %s with future metadata from %s\n#\n", DB0, DB1);
	setup_database(DB0, NULL, DB1);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB0, bring in future turtle file from DB1.
	 */
	printf(
	    "#\n# OUT OF SYNC: %s with future turtle from %s\n#\n", DB0, DB1);
	setup_database(DB0, DB1, NULL);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB1, bring in old metadata file from DB0.
	 */
	printf("#\n# OUT OF SYNC: %s with old metadata from %s\n#\n", DB1, DB0);
	setup_database(DB1, NULL, DB0);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB1, bring in old turtle file from DB0.
	 */
	printf("#\n# OUT OF SYNC: %s with old turtle from %s\n#\n", DB1, DB0);
	setup_database(DB1, DB0, NULL);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB1, bring in future metadata file from DB2.
	 */
	printf(
	    "#\n# OUT OF SYNC: %s with future metadata from %s\n#\n", DB1, DB2);
	setup_database(DB1, NULL, DB2);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB1, bring in future turtle file from DB2.
	 */
	printf(
	    "#\n# OUT OF SYNC: %s with future turtle from %s\n#\n", DB1, DB2);
	setup_database(DB1, DB2, NULL);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB2, bring in old metadata file from DB1.
	 */
	printf("#\n# OUT OF SYNC: %s with old metadata from %s\n#\n", DB2, DB1);
	setup_database(DB2, NULL, DB1);
	run_all_verification(TEST, table_data);

	/*
	 * Run in DB2, bring in old turtle file from DB1.
	 */
	printf("#\n# OUT OF SYNC: %s with old turtle from %s\n#\n", DB2, DB1);
	setup_database(DB2, DB1, NULL);
	run_all_verification(TEST, table_data);
}
Esempio n. 9
0
int main()
{
    pcap_if_t *alldevsp , *device;
    pcap_t *handle; //Handle of the device that shall be sniffed
    char* databaseName = "database.sqlite3";
 
    char errbuf[100] , *devname , devs[100][100];
    int count = 1 , n;
     
    //First get the list of available devices
    printf("Finding available devices ... ");
    if( pcap_findalldevs( &alldevsp , errbuf) )
    {
        printf("Error finding devices : %s" , errbuf);
        exit(1);
    }
    printf("Done");
     
    //Print the available devices
    printf("\nAvailable Devices are :\n");
    for(device = alldevsp ; device != NULL ; device = device->next)
    {
        printf("%d. %s - %s\n" , count , device->name , device->description);
        if(device->name != NULL)
        {
            strncpy(devs[count] , device->name, 16);
        }
        count++;
    }
     
    //Ask user which device to sniff
    printf("Enter the number of the device you want to sniff : ");
    scanf("%d" , &n);
    devname = devs[n];
     
    //Open the device for sniffing
    printf("Opening device %s for sniffing ... " , devname);
    handle = pcap_open_live(devname , 65536 , 1 , 0 , errbuf);
     
    if (handle == NULL)
    {
        fprintf(stderr, "Couldn't open device %s : %s\n" , devname , errbuf);
        exit(1);
    }
    printf("Done\n");
     
    setup_log();

    if(setup_database(databaseName)){
        printf("Database is setup.\n");
    }
    else {
        printf("No database file exists.\n");
    }
     

    //Put the device in sniff loop
    pcap_loop(handle , -1 , process_packet , NULL);
     
    return 0;  
}
Esempio n. 10
0
/**
 * Runs the program.
 */
int main(int argc, char **argv) {
    char *category, **all_categories;
    customer_t *customer;
    float revenue;
    int i, num_categories;
    receipt_t *receipt;
    void *ignore;

    // Check for the proper amount of arguments
    if (argc != 4) {
        fprintf(stderr, "Error: wrong number of arguments\n");
        print_usage();
        exit(EXIT_FAILURE);
    }

    // Figure out how many categories there are
    input_categories = malloc(strlen(argv[3]) + 1);
    strcpy(input_categories, argv[3]);
    all_categories = (char **) calloc(1024, sizeof(char *));
    num_categories = 0;
    category = strtok(argv[3], " ");
    if (category == NULL) {
        fprintf(stderr, "Error: Must specify at least one category.\n");
        exit(EXIT_FAILURE);
    }
    all_categories[0] = malloc(strlen(category) + 1);
    strcpy(all_categories[0], category);
    num_categories++;

    while ((category = strtok(NULL, " ")) != NULL) {
        all_categories[num_categories] = malloc(strlen(category) + 1);
        strcpy(all_categories[num_categories], category);
        num_categories++;
    }

    // Holds all the thread ids spawned later
    pthread_t tid[num_categories + 1];

    // Set up customer database from file and our queue
    customerDatabase = setup_database(argv[1]);
    queue = queue_create();

    // Spawn producer thread
    pthread_create(&tid[0], NULL, producer_thread, (void *) argv[2]);

    // Spawn all the consumer threads
    for (i = 0; i < num_categories; i++) {
        pthread_create(&tid[i + 1], NULL, consumer_thread, all_categories[i]);
    }

    // Wait for all the other threads to finish before continuing
    for (i = 0; i < num_categories + 1; i++) {
        pthread_join(tid[i], &ignore);
    }

    // Now we can print our final report
    printf("\n\n");
    revenue = 0.0f;
    for (i = 0; i < MAXCUSTOMERS; i++) {
        customer = customerDatabase->customer[i];
        if (customer == NULL) {
            continue;
        }

        // Print out this customer's data
        printf("=== Customer Info ===\n");
        printf("--- Balance ---\n");
        printf("Customer name: %s\n", customer->name);
        printf("Customer ID number: %d\n", customer->customer_id);
        printf("Remaining credit: %.2f\n", customer->credit_limit);

        // Successful book orders
        printf("\n--- Successful orders ---\n");
        if (queue_isempty(customer->successful_orders)) {
                printf("\tNone.\n");
        }
        else {
            while ((receipt = (receipt_t *)
                        queue_dequeue(customer->successful_orders)) != NULL) {
                printf("%s|%.2f|%.2f\n", receipt->title, receipt->price,
                                           receipt->remaining_credit);
                revenue += receipt->price;
                receipt_destroy(receipt);
            }
        }

        // Failed book orders
        printf("\n--- Failed orders ---\n");
        if (queue_isempty(customer->failed_orders)) {
            printf("None.\n");
        }
        else {
            while ((receipt = (receipt_t *)
                        queue_dequeue(customer->failed_orders)) != NULL) {
                printf("%s|%.2f\n", receipt->title, receipt->price);
                receipt_destroy(receipt);
            }
        }
        printf("=== End Customer Info ===\n\n");
    }

    printf("Total Revenue: $%.2f\n", revenue);

    // Free all the memory we allocated
    database_destroy(customerDatabase);
    queue_destroy(queue, NULL);
    return EXIT_SUCCESS;
}