Exemplo n.º 1
0
int
swill_checkuser() {
   String *auths;
   String *userpw;
   int ch;
   char *auth;
   if (!SwillUsers) return 1;
   auth = swill_getheader("authorization");
   if (!auth) {
      return 0;
   }
   auths = NewString(auth);
   Seek(auths, 0, SEEK_SET);
   do {
      ch = Getc(auths);
   } while ((ch != EOF) && (ch != ' '));
   userpw = NewString("");
   swill_base64_decode(auths,userpw);
   if (Getattr(SwillUsers,userpw)) {
      Delete(auths);
      Delete(userpw);
      return 1;
   }
   Delete(auths);
   Delete(userpw);
   return 0;
}
Exemplo n.º 2
0
// Terminates connection to the embedded web-server.
void terminate(FILE *f, sqlite3 *db) {
  char response_type[50];
  strcpy(response_type, swill_getheader("Http_Choose_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\";}"
		"</style>"
		"</head>"
		"<body>");
  }
  deinit_selectors();
  sqlite3_close(db);
  if (!strcmp(response_type, "text/html")) {
    swill_fprintf(f, "<b>TERMINATED CONNECTION...</b>"
		"</body>"
		"</html>");
  }
  swill_close();
}
Exemplo n.º 3
0
/* 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();
}