Back to index

indicator-appmenu  12.10.0
hud-verify-app-info.c
Go to the documentation of this file.
00001 /*
00002 Verify the validity of the App Info file to make sure it parses
00003 
00004 Copyright 2011 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This program is free software: you can redistribute it and/or modify it 
00010 under the terms of the GNU General Public License version 3, as published 
00011 by the Free Software Foundation.
00012 
00013 This program is distributed in the hope that it will be useful, but 
00014 WITHOUT ANY WARRANTY; without even the implied warranties of 
00015 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
00016 PURPOSE.  See the GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License along 
00019 with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #include <unistd.h>
00023 #include <glib-object.h>
00024 #include <glib/gstdio.h>
00025 #include "load-app-info.h"
00026 #include "create-db.h"
00027 
00028 static void
00029 build_db (sqlite3 * db)
00030 {
00031        /* Create the table */
00032        int exec_status = SQLITE_OK;
00033        gchar * failstring = NULL;
00034        exec_status = sqlite3_exec(db,
00035                                   create_db,
00036                                   NULL, NULL, &failstring);
00037        if (exec_status != SQLITE_OK) {
00038               g_warning("Unable to create table: %s", failstring);
00039        }
00040 
00041        /* Import data from the system */
00042 
00043        return;
00044 }
00045 
00046 int
00047 main (int argv, char * argc[])
00048 {
00049        gboolean passed = TRUE;
00050 
00051        if (argv != 2) {
00052               g_printerr("Usage: %s <app-info file path>\n", argc[0]);
00053               return 1;
00054        }
00055 
00056        g_type_init();
00057 
00058        gchar * filename = NULL;
00059        gint tmpfile = g_file_open_tmp("hud-verify-app-info-temp-db-XXXXXX", &filename, NULL);
00060 
00061        if (tmpfile < 0) {
00062               passed = FALSE;
00063        } else {
00064 
00065               close(tmpfile);
00066               /* NOTE: there is a small security bug here in that we're closing the
00067                  file and reopening it, so the temp isn't really guaranteed to be
00068                  safe.  But, I don't think we're really worried about security in this
00069                  utility. */
00070 
00071               sqlite3 * db = NULL;
00072               int open_status = sqlite3_open(filename, &db); 
00073 
00074               if (open_status != SQLITE_OK) {
00075                      g_warning("Error opening usage DB: %s", filename);
00076                      passed = FALSE;
00077               } else {
00078 
00079                      /* Create the table in the DB */
00080                      build_db(db);
00081 
00082                      passed = load_app_info(argc[1], db);
00083 
00084                      sqlite3_close(db);
00085               }
00086        }
00087 
00088        if (filename != NULL) {
00089               if (g_getenv("HUD_VERIFY_NO_UNLINK") == NULL) {
00090                      g_unlink(filename);
00091               } else {
00092                      g_print("Temp db '%s' not deleted\n", filename);
00093               }
00094               g_free(filename);
00095        }
00096 
00097        if (passed) {
00098               return 0;
00099        } else {
00100               return 1;
00101        }
00102 }