Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Include the required headers from httpd */
- #include "httpd.h"
- #include "http_core.h"
- #include "http_protocol.h"
- #include "http_request.h"
- #include "uuid/uuid.h"
- #include "sqlite3.h"
- /* Define prototypes of our functions in this module */
- static void register_hooks(apr_pool_t *pool);
- static int example_handler(request_rec *r);
- static int callback(void *NotUsed, int argc, char **argv, char **azColName);
- /* Define our module as an entity and assign a function for registering hooks */
- request_rec *rg = NULL;
- module AP_MODULE_DECLARE_DATA example_module =
- {
- STANDARD20_MODULE_STUFF,
- NULL, // Per-directory configuration handler
- NULL, // Merge handler for per-directory configurations
- NULL, // Per-server configuration handler
- NULL, // Merge handler for per-server configurations
- NULL, // Any directives we may have for httpd
- register_hooks // Our hook registering function
- };
- /* register_hooks: Adds a hook to the httpd process */
- static void register_hooks(apr_pool_t *pool)
- {
- /* Hook the request handler */
- ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
- }
- static int callback(void *NotUsed, int argc, char **argv, char **azColName) {
- int i;
- printf("\n callback");
- for (i = 0; i < argc; i++) {
- //printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
- ap_rputs(azColName[i],rg);
- ap_rputs(argv[i],rg);
- }
- printf("\n");
- return 0;
- }
- /* The handler function for our module.
- * This is where all the fun happens!
- */
- static int example_handler(request_rec *r)
- {
- /* First off, we need to check if this is a call for the "example" handler.
- * If it is, we accept it and do our things, it not, we simply return DECLINED,
- * and Apache will try somewhere else.
- */
- if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);
- // The first thing we will do is write a simple "Hello, world!" back to the client.
- ap_rputs("Hello, world!<br/>", r);
- rg =r;
- uuid_t uuid;
- // generate
- uuid_generate_time_safe(uuid);
- // unparse (to string)
- char uuid_str[37]; // ex. "1b4e28ba-2fa1-11d2-883f-0016d3cca427" + "\0"
- uuid_unparse_lower(uuid, uuid_str);
- // printf("generate uuid=%s\n", uuid_str);
- ap_rputs(uuid_str,r);
- int rc;
- char *pStrSql;
- sqlite3* db;
- char *zErrMsg;
- rc = sqlite3_open("a.db", &db);
- if (rc) {
- // printf("\nCant open db ");
- ap_rputs("\nCant open db",r);
- exit(0);
- } else {
- //fprintf(stdout, "Opened database successfully\n");
- ap_rputs("\nDatabase opened succesfully",r);
- }
- pStrSql = "CREATE TABLE employee (name text,age int);";
- rc = sqlite3_exec(db, pStrSql, callback, 0, &zErrMsg);
- if (rc != SQLITE_OK) {
- ap_rputs(zErrMsg,r);
- sqlite3_free(zErrMsg);
- } else {
- ap_rputs("\nTable created successfully",r);
- }
- pStrSql = "INSERT INTO employee VALUES ('prakash',23);"\
- "INSERT INTO employee VALUES ('dravid',41);" \
- "INSERT INTO employee VALUES ('sourav',41);" \
- "INSERT INTO employee VALUES ('sachin',40);"\
- "INSERT INTO employee VALUES ('Some one',23);";
- rc = sqlite3_exec(db, pStrSql, callback, 0, &zErrMsg);
- if (rc != SQLITE_OK) {
- ap_rputs(zErrMsg,r);
- sqlite3_free(zErrMsg);
- } else {
- ap_rputs("Records created succefulyy",r);
- }
- return OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment