static int find_exec_pathsearch(const char *filepath, char **argv, char *newpath, int newpath_size, char ***new_argv) { char *newname = NULL; int result; if (!filepath) { newpath[0] = '\0'; return 0; } if (filepath[0] == '/' || filepath[0] == '.') { find_exec(filepath, argv, newpath, newpath_size, new_argv); return 0; } check_for_fork(); if (ldcsid < 0 || !use_ldcs) { strncpy(newpath, filepath, newpath_size); newpath[newpath_size-1] = '\0'; return 0; } sync_cwd(); result = exec_pathsearch(ldcsid, filepath, &newname); if (result == -1) return -1; result = prep_exec(filepath, argv, newname, newpath, newpath_size, new_argv); return result; }
/* Builds the front page of the library's web interface, * retrieves the database schema and promotes inputted * queries to sqlite_engine. */ void app_index(FILE *f, sqlite3 *db) { swill_fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\"http://www.w3.org/TR/html4/loose.dtd\">" "<html>" "<head>" "<style type=\"text/css\">" "img{height:116px;width:109px;align:left}" ".div_style{width:500px; border:2px solid; background-color:#ccc;margin:0px auto;margin-top:-40px;}" ".top{border-bottom:1px solid;padding-top:10px;padding-left:10px;padding-bottom:2px;}" ".middle{padding-top:5px;padding-left:9px; padding-bottom:5px;}" ".bottom{border-top:1px solid;padding-top:5px; padding-bottom:10px; text-align:center;}" ".button{height:7em; width:10em; font-size:22px;}" ".style_text{font-family:Times New Roman;font-size:20px;}" ".style_input{font-family:Times New Roman;font-size:15px;}" "table,td{border:1px double;}" ".div_tbl{margin-top:20px;}" "p.aligned{text-align:left;}" "</style>" "</head>" "<body>"); swill_fprintf(f, "<p><left><img src=\"pico_ql_logo.png\"></left>\n" "<div class=\"div_style\">" "<form action=\"serveQuery.html\" method=GET>" "<div class=\"top\">" "<span class=\"style_text\"><b>Input your SQL query:</b></span>" "</div>" "<div class=\"middle\">" "<textarea name=\"query\" cols=\"72\" rows=\"10\" class=\"style_input\"></textarea><br>" "</div>" "<div class=\"bottom\">" "<input type=\"submit\" value=\"Submit\" class=\"button\"></input>" "</div>" "</form>" "</div>" "<div class=\"div_tbl\">" "<span class=\"style_text\"><b>Your database schema is:</b></span>"); prep_exec(f, db, "SELECT * FROM sqlite_master;", "text/html"); swill_fprintf(f, "</div>" "<br>" "<p class=\"aligned\">"); swill_fprintf(f,"<a href=\""); swill_printurl(f,"terminateConnection.html", "", 0); swill_fprintf(f,"\">[ Terminate Server Connection ]</a>" "</p>" "</body>" "</html>"); }
static int find_exec(const char *filepath, char **argv, char *newpath, int newpath_size, char ***new_argv) { char *newname = NULL; if (!filepath) { newpath[0] = '\0'; return 0; } check_for_fork(); if (ldcsid < 0 || !use_ldcs || exec_filter(filepath) != REDIRECT) { strncpy(newpath, filepath, newpath_size); newpath[newpath_size-1] = '\0'; return 0; } sync_cwd(); debug_printf2("Exec operation requesting file: %s\n", filepath); send_file_query(ldcsid, (char *) filepath, &newname); debug_printf("Exec file request returned %s -> %s\n", filepath, newname ? newname : "NULL"); return prep_exec(filepath, argv, newname, newpath, newpath_size, new_argv); }
/* Executes the SQL CREATE queries, opens the sqlite * database connection and calls swill or pico_ql_test * depending on the compile flag TEST. */ int register_table(int argc, int view_index, const char **q, const char **sqlite_names, int port_number) { /* This definition implicitly constraints a table name * to 140 characters. It should be more than enough. */ char sqlite_query[200]; int re, i=0; sqlite3 *db; /* Virtual table schema will be in-memory and will not persist. Views can be included in the DSL */ re = sqlite3_open(":memory:", &db); if (re) { printf("can't open database\n"); sqlite3_close(db); return re; } #ifdef PICO_QL_DEBUG for (i = 0; i < argc; i++) { printf("\nquery to be executed: %s.\n", q[i]); } #endif sqlite3_module *mod; mod = (sqlite3_module *)sqlite3_malloc(sizeof(sqlite3_module)); fill_module(mod); int output = sqlite3_create_module(db, "PicoQL", mod, NULL); if (output == 1) printf("Error while registering module\n"); #ifdef PICO_QL_DEBUG else if (output == 0) printf("Module registered successfully\n"); #endif // sqlite3_create_function() calls for (i = 0; i < argc; i++) { char sqlite_type[10]; if (i < view_index) strcpy(sqlite_type, "table"); else strcpy(sqlite_type, "view"); sprintf(sqlite_query, "SELECT * FROM sqlite_master WHERE type='%s' AND name='%s';", sqlite_type, sqlite_names[i]); if (prep_exec(NULL, db, (const char *)sqlite_query, NULL) != SQLITE_ROW) { re = prep_exec(NULL, db, (const char *)q[i], NULL); #ifdef PICO_QL_DEBUG printf("Query %s returned %i\n", q[i], re); #endif if (re != 101) { printf("Extended error code: %i.\n", sqlite3_extended_errcode(db)); printf("Extended error message:\n%s.\n", sqlite3_errmsg(db)); return re; } } } start_serving(); #ifndef PICO_QL_TEST printf("Please visit http://localhost:%i to be served\n", port_number); call_swill(db, port_number); #else re = call_test(db); #endif sqlite3_free(mod); return re; }
/* Builds the html page of the result set of a query * along with the time it took to execute and the query * itself. */ void serve_query(FILE *f, sqlite3 *db) { const char *query = "\0"; char response_type[50]; char *rt = swill_getheader("Http_Choose_Response_Type"); if (rt) strcpy(response_type, rt); else strcpy(response_type, "text/html"); /* default */ //swill_fprintf(f, "Response type should be: %s", response_type); if (!strcmp(response_type, "text/html")) swill_fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\"http://www.w3.org/TR/html4/loose.dtd\">" "<html>" "<head>" "<style type=\"text/css\">" "body{bgcolor=\"#ffffff\";}" "span.styled{color:blue;}" "table, td{border:1px double;}" "p.aligned{text-align:left;}" "</style>" "</head>" "<body>"); if (swill_getargs("s(query)", &query)) { int rc = 0; clock_t start_clock,finish_clock; double c_time; start_clock = clock(); int j = 0; if (!strcmp(response_type, "text/html")) { swill_fprintf(f, "<b>For SQL query: "); swill_fprintf(f, "<span class=\"styled\">%s</span><br><br>", query); swill_fprintf(f, "Result set is:</b><br><br>"); } // j for debugging, execute the query multiple times. while (j < 1 && (rc = prep_exec(f, db, query, response_type)) == SQLITE_DONE) { j++; } if (rc == SQLITE_DONE) { finish_clock = clock(); c_time = ((double)finish_clock - (double)start_clock)/CLOCKS_PER_SEC; if (!strcmp(response_type, "text/html")) { swill_fprintf(f, "<b>\nQUERY SUCCESSFUL! </b><br><br>"); swill_fprintf(f,"CPU time: <b>%f</b>s.<br><br>", c_time); } } else { if (!strcmp(response_type, "text/html")) { swill_fprintf(f, "<br><b>Extended error message:<br><b>%s</b><br><br>", sqlite3_errmsg(db)); swill_fprintf(f, "Extended error code <b>%i.<br>Please advise </b><a href=\"", sqlite3_extended_errcode(db)); swill_printurl(f, "pico_ql_error_page.html", "", 0); swill_fprintf(f,"\">SQLite error codes</a>.<br><br>"); } } if (!strcmp(response_type, "text/html")) { swill_fprintf(f, "<p class=\"aligned\">"); swill_fprintf(f, "<a href=\""); swill_printurl(f,"index.html", "", 0); swill_fprintf(f,"\">[ Input new Query ]</a>"); swill_fprintf(f, "<a href=\""); swill_printurl(f,"terminateConnection.html", "", 0); swill_fprintf(f,"\">[ Terminate Server Connection ]</a>" "</p>" "</body>" "</html>"); } } clear_temp_structs(); }