daemon.c
static int method_add(sd_bus_message *m, void *userdata,
                      sd_bus_error *ret_error) {
  (void)ret_error;
  (void)userdata;
  int r;
  char *path;
  char *extension;

  r = sd_bus_message_read(m, "ss", &path, &extension);
  if (r < 0) {
    fprintf(stderr, "Failed to parse parameters: %s\n", strerror(-r));
    return r;
  }

  sqlite3 *db;
  char *err_msg = 0;

  int rc = sqlite3_open("extensions.db", &db);

  if (rc != SQLITE_OK) {
    fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);

    return 1;
  }

  /* Glue sqllite command */
  char *create =
      "CREATE TABLE IF NOT EXISTS Programs(program_path TEXT,program_extension "
      "TEXT,"
      "UNIQUE(program_path, program_extension) ON CONFLICT IGNORE);"
      "INSERT INTO Programs VALUES('";
  char *add_path = concat(create, path);
  char *add_sep1 = concat(add_path, "', '");
  char *add_extension = concat(add_sep1, extension);
  char *sql = concat(add_extension, "');");

  rc = sqlite3_exec(db, sql, 0, 0, &err_msg);

  if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", err_msg);

    sqlite3_free(err_msg);
    sqlite3_close(db);

    return 1;
  }

  sqlite3_close(db);

  return sd_bus_reply_method_return(m, "x", 0);
}
/* Returns 0 if success, other value if failure" */
Returns 0 if success, other value if failure"
Returns 0 if success other value if failure "
static int method_add(sd_bus_message *m, void *userdata,
                      sd_bus_error *ret_error) {
  (void)ret_error;
  (void)userdata;
  int r;
  char *path;
  char *extension;
  r = sd_bus_message_read(m, "ss", &path, &extension);
  if (r < 0) {
    fprintf(stderr, "Failed to parse parameters: %s\n", strerror(-r));
    return r;
  }
  sqlite3 *db;
  char *err_msg = 0;
  int rc = sqlite3_open("extensions.db", &db);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return 1;
  }
  char *create =
      "CREATE TABLE IF NOT EXISTS Programs(program_path TEXT,program_extension "
      "TEXT,"
      "UNIQUE(program_path, program_extension) ON CONFLICT IGNORE);"
      "INSERT INTO Programs VALUES('";
  char *add_path = concat(create, path);
  char *add_sep1 = concat(add_path, "', '");
  char *add_extension = concat(add_sep1, extension);
  char *sql = concat(add_extension, "');");
  rc = sqlite3_exec(db, sql, 0, 0, &err_msg);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", err_msg);
    sqlite3_free(err_msg);
    sqlite3_close(db);
    return 1;
  }
  sqlite3_close(db);
  return sd_bus_reply_method_return(m, "x", 0);
}
static int method_add ( sd_bus_message * m , void * userdata , sd_bus_error * ret_error ) { ( void ) ret_error ; ( void ) userdata ; int r ; char * path ; char * extension ; r = sd_bus_message_read ( m , " " , & path , & extension ) ; if ( r < 0 ) { fprintf ( stderr , " \n " , strerror ( - r ) ) ; return r ; } sqlite3 * db ; char * err_msg = 0 ; int rc = sqlite3_open ( " " , & db ) ; if ( rc != SQLITE_OK ) { fprintf ( stderr , " \n " , sqlite3_errmsg ( db ) ) ; sqlite3_close ( db ) ; return 1 ; } char * create = " " " " " " " " ; char * add_path = concat ( create , path ) ; char * add_sep1 = concat ( add_path , " " ) ; char * add_extension = concat ( add_sep1 , extension ) ; char * sql = concat ( add_extension , " " ) ; rc = sqlite3_exec ( db , sql , 0 , 0 , & err_msg ) ; if ( rc != SQLITE_OK ) { fprintf ( stderr , " \n " , err_msg ) ; sqlite3_free ( err_msg ) ; sqlite3_close ( db ) ; return 1 ; } sqlite3_close ( db ) ; return sd_bus_reply_method_return ( m , " " , 0 ) ; }
Returns 0 if success, other value if failure"
Returns 0 if success other value if failure "
/* Glue sqllite command */