int main(int argc, char **argv) { uuid_t buf; time_t time_reg; struct timeval tv; int type, variant; if (argc != 2) { fprintf(stderr, "Usage: %s uuid\n", argv[0]); exit(1); } if (gf_uuid_parse(argv[1], buf)) { fprintf(stderr, "Invalid UUID: %s\n", argv[1]); exit(1); } variant = gf_uuid_variant(buf); type = gf_uuid_type(buf); time_reg = gf_uuid_time(buf, &tv); printf("UUID variant is %d (%s)\n", variant, variant_string(variant)); if (variant != UUID_VARIANT_DCE) { printf("Warning: This program only knows how to interpret " "DCE UUIDs.\n\tThe rest of the output is likely " "to be incorrect!!\n"); } printf("UUID type is %d", type); switch (type) { case 1: printf(" (time based)\n"); break; case 2: printf(" (DCE)\n"); break; case 3: printf(" (name-based)\n"); break; case 4: printf(" (random)\n"); break; default: printf("\n"); } if (type != 1) { printf("Warning: not a time-based UUID, so UUID time " "decoding will likely not work!\n"); } printf("UUID time is: (%" GF_PRI_SECOND ", %" GF_PRI_USEC "): %s\n", tv.tv_sec, tv.tv_usec, ctime(&time_reg)); return 0; }
/****************************************************************************** * * Find/Query helper functions * * ****************************************************************************/ int gf_sql_query_function (sqlite3_stmt *prep_stmt, gf_query_callback_t query_callback, void *_query_cbk_args) { int ret = -1; gfdb_query_record_t *gfdb_query_record = NULL; char *text_column = NULL; sqlite3 *db_conn = NULL; GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, prep_stmt, out); GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, query_callback, out); db_conn = sqlite3_db_handle(prep_stmt); gfdb_query_record = gfdb_query_record_init (); if (!gfdb_query_record) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, "Failed to create " "gfdb_query_record"); goto out; } /*Loop to access queried rows*/ while ((ret = sqlite3_step (prep_stmt)) == SQLITE_ROW) { /*Clear the query record*/ memset (gfdb_query_record, 0, sizeof(*gfdb_query_record)); if (sqlite3_column_count(prep_stmt) > 0) { /*Retriving GFID - column index is 0*/ text_column = (char *)sqlite3_column_text (prep_stmt, 0); if (!text_column) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_ID_FAILED, "Failed " "retriving GF_ID"); goto out; } ret = gf_uuid_parse (text_column, gfdb_query_record->gfid); if (ret) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PARSE_FAILED, "Failed parsing " "GF_ID"); goto out; } /*Retrive Link Buffer - column index 1*/ text_column = (char *)sqlite3_column_text (prep_stmt, 1); /* Get link string. Do shallow copy here * query_callback function should do a * deep copy and then do operations on this field*/ gfdb_query_record->_link_info_str = text_column; gfdb_query_record->link_info_size = strlen (text_column); /* Call the call back function provided*/ ret = query_callback (gfdb_query_record, _query_cbk_args); if (ret) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_CALL_BACK_FAILED, "Query Call back failed!"); goto out; } } } if (ret != SQLITE_DONE) { gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_RECORD_FAILED, "Failed retriving records " "from db : %s", sqlite3_errmsg (db_conn)); ret = -1; goto out; } ret = 0; out: gfdb_query_record_fini (&gfdb_query_record); return ret; }