Author: dumindu
Date: Mon Dec 10 21:04:52 2007
New Revision: 10876
Log:
adding mechanisms to make use of ap_log_error. Jira IDENTITY-21
Modified:
trunk/solutions/identity/modules/mod-cspace/mod_cspace.c
trunk/solutions/identity/modules/mod-cspace/process_request.c
trunk/solutions/identity/modules/mod-cspace/process_request.h
trunk/solutions/identity/modules/mod-cspace/process_request_defines.h
trunk/solutions/identity/modules/mod-cspace/res/test.c
Modified: trunk/solutions/identity/modules/mod-cspace/mod_cspace.c
==============================================================================
--- trunk/solutions/identity/modules/mod-cspace/mod_cspace.c (original)
+++ trunk/solutions/identity/modules/mod-cspace/mod_cspace.c Mon Dec 10
21:04:52 2007
@@ -39,6 +39,11 @@
#define CARDSPACE_HEADER_PFX "cardspace_"
+static void cspace_log_error(const char *msg, pc_log_level_t level, void
*cb_ctx)
+{
+ ap_log_error(APLOG_MARK, level, 0, (server_rec *)cb_ctx, msg);
+}
+
/* TODO:This function should ideally redirect the browser to the url specified
* by url. This is only used to redirect the browser to the login page when an
* HTTP_UNAUTHORIZED occurs.
@@ -162,6 +167,7 @@
/*this array is free'd before the function exits*/
}
} else {
+ cspace_log_error("Cannot read request body", APLOG_WARNING, r->server);
#ifdef CSPACE_DEBUG
printf("ERR: should_client_block false!\n");
#endif
@@ -180,7 +186,7 @@
static void set_header(char *uri, char *key, char *val, void* table, void
*pool)
{
apr_table_t *t = (apr_table_t *)table;
-
+
#ifdef CSPACE_DEBUG
printf("Header %s/%s:%s\n", uri, key, val);
#endif
@@ -375,6 +381,7 @@
int state = FAIL;
process_context_t *ctx = NULL;
+ cspace_log_error(buf, APLOG_DEBUG, r->server);
#ifdef CSPACE_DEBUG
printf("TOKEN: %s\n", buf);
#endif
@@ -383,9 +390,18 @@
/*TODO: create with pool allocator*/
ctx = cspace_process_context_create_default();
if (!ctx)
+ {
+ cspace_log_error("process context could not be created", APLOG_ERR,
+ r->server);
return HTTP_INTERNAL_SERVER_ERROR;
+ }
cspace_process_context_set_key_file(ctx, svr_cfg->key_file);
+
+ /*if (ctx->ca_file)
+ cspace_process_context_set_ca_file(ctx, svr_cfg->ca_file);*/
+
+ cspace_process_context_set_logger(ctx, cspace_log_error, r->server);
cspace_process_context_set_header_callback(ctx, &set_header,
(void*)(r->subprocess_env));
@@ -422,7 +438,11 @@
status = get_cookie(r, &cookies);
if (status == HTTP_INTERNAL_SERVER_ERROR)
+ {
+ cspace_log_error("Could not retrieve the session cookie", APLOG_NOTICE,
+ r->server);
return status;
+ }
session_ctx = session_ctx_create(r->pool, dir_cfg->session_file,
svr_cfg->session_expire);
@@ -465,6 +485,7 @@
if (session_id)
set_cookie(r, session_id);
+ /*log success/failure of this*/
return OK;
} else {
@@ -475,6 +496,8 @@
#ifdef CSPACE_DEBUG
printf("ERR: request null! can't read?");
#endif
+ cspace_log_error("could not extract the token from the request",
+ APLOG_NOTICE, r->server);
if (ret != OK)
return ret;
}
@@ -518,6 +541,8 @@
printf("ERR: request null! can't read?");
#endif
+ cspace_log_error("could not extract the token from the request",
+ APLOG_NOTICE, r->server);
/*Should it be UNAUTHORIZED_REDIRECT(r, NULL) that should go here*/
if (ret != OK)
return ret;
@@ -548,13 +573,19 @@
if (!(dir_cfg->use_cspace_auth))
return DECLINED;
- if (strcmp(ap_http_scheme(r), "https") != 0)
+ if (strcmp(ap_http_scheme(r), "https") != 0) {
+ cspace_log_error("https scheme expected for cardspace requests",
+ APLOG_NOTICE, r->server);
return UNAUTHORIZED_REDIRECT(r, NULL);
+ }
/*Don't send us CARDSPACE headers*/
- if (!check_valid_headers(r))
+ if (!check_valid_headers(r)) {
+ cspace_log_error("client sent cardspace headers. denied access",
+ APLOG_NOTICE, r->server);
return UNAUTHORIZED_REDIRECT(r, NULL);
-
+ }
+
if (dir_cfg->session) {
if (dir_cfg->sso) {
return handle_session_sso(r, dir_cfg, svr_cfg);
Modified: trunk/solutions/identity/modules/mod-cspace/process_request.c
==============================================================================
--- trunk/solutions/identity/modules/mod-cspace/process_request.c
(original)
+++ trunk/solutions/identity/modules/mod-cspace/process_request.c Mon Dec
10 21:04:52 2007
@@ -65,8 +65,9 @@
(obj) ? (((obj)->nodesetval) ? \
((obj)->nodesetval->nodeTab[(i)]) : NULL) : NULL)
-static void* malloc_def(size_t size, void *cb_ctx);
+static void *malloc_def(size_t size, void *cb_ctx);
static void free_def(void *ptr, void *cb_ctx);
+static void logger_def(const char *msg, pc_log_level_t level, void *cb_ctx);
static int decrypt_token(xmlDoc *doc, process_context_t *ctx);
static int register_namespaces(xmlXPathContext *xpath_ctx);
static xmlSecKeysMngr *keys_mnrg_create_and_load_priv_key(process_context_t
*ctx);
@@ -79,7 +80,7 @@
{
int res = FAIL;
xmlDoc *doc = NULL;
-
+
/* Load XML document */
doc = xmlReadMemory(req, (int)strlen(req), NULL, NULL, 0);
@@ -129,9 +130,17 @@
return res;
}
+void cspace_process_context_set_logger(process_context_t *ctx,
+ logger_cb_t logger, void *cb_ctx)
+{
+ ctx->logger_fn = logger;
+ ctx->logger_cb_ctx = cb_ctx;
+}
+
void cspace_process_context_set_header_callback_context(process_context_t *ctx,
void *cb_ctx)
{
+ pc_log_error(ctx, "TEST_ERROR TEST_ERROR", PCLOG_ERR);
ctx->set_header_cb_ctx = cb_ctx;
}
@@ -479,8 +488,12 @@
return SUCC;
}
+static void logger_def(const char *msg, pc_log_level_t level, void *cb_ctx)
+{
+ printf("%s\n", msg);
+}
-static void* malloc_def(size_t size, void *cb_ctx)
+static void *malloc_def(size_t size, void *cb_ctx)
{
return malloc(size);
}
@@ -544,7 +557,12 @@
ctx->allocator->mctx = mctx;
ctx->allocator->free_fn = free_fn;
ctx->allocator->fctx = fctx;
-
+
+ /* Set the default logger (stdio)
+ * "User" can always change this afterwards */
+ ctx->logger_fn = logger_def;
+ ctx->logger_cb_ctx = NULL;
+
ctx->key_file = NULL;
ctx->ca_file = NULL;
Modified: trunk/solutions/identity/modules/mod-cspace/process_request.h
==============================================================================
--- trunk/solutions/identity/modules/mod-cspace/process_request.h
(original)
+++ trunk/solutions/identity/modules/mod-cspace/process_request.h Mon Dec
10 21:04:52 2007
@@ -17,14 +17,27 @@
#define cspace_process_context_create \
cspace_process_context_create_with_allocator
+typedef enum {
+ PCLOG_EMERG = 0,
+ PCLOG_ALERT,
+ PCLOG_CRIT,
+ PCLOG_ERR,
+ PCLOG_WARNING,
+ PCLOG_NOTICE,
+ PCLOG_INFO,
+ PCLOG_DEBUG,
+} pc_log_level_t;
+
typedef struct allocator allocator_t;
typedef struct process_context process_context_t;
typedef void *(*malloc_cb_t)(size_t size, void *cb_ctx);
typedef void (*free_cb_t)(void *ptr, void *cb_ctx);
-typedef void (*set_header_cb_t)(char *ns_uri, char *key, char *val, void
*container,
- void *cb_ctx);
+typedef void (*logger_cb_t)(const char *msg, pc_log_level_t level, void
*cb_ctx);
+
+typedef void (*set_header_cb_t)(char *ns_uri, char *key, char *val,
+ void *container, void *cb_ctx);
int cspace_process_context_init(void);
@@ -36,11 +49,14 @@
void cspace_process_context_free(process_context_t *ctx);
void cspace_process_context_halt(void);
+void cspace_process_context_set_logger(process_context_t *ctx,
+ logger_cb_t logger, void *cb_ctx);
+
int cspace_process_context_set_key_file(process_context_t *ctx,
const char* key_file);
int cspace_process_context_set_ca_file(process_context_t *ctx,
- const char* ca_file);
+ const char* ca_file);
void cspace_process_context_set_header_callback(process_context_t *ctx,
set_header_cb_t set_header_fn,
Modified: trunk/solutions/identity/modules/mod-cspace/process_request_defines.h
==============================================================================
--- trunk/solutions/identity/modules/mod-cspace/process_request_defines.h
(original)
+++ trunk/solutions/identity/modules/mod-cspace/process_request_defines.h
Mon Dec 10 21:04:52 2007
@@ -13,6 +13,9 @@
#define pc_free(ptr, pctx)\
(pctx)->allocator->free_fn((ptr), (pctx)->allocator->fctx)
+
+#define pc_log_error(pctx, error_msg, level) \
+ (pctx)->logger_fn((error_msg), (level), (pctx)->logger_cb_ctx)
struct allocator {
/*void *(*malloc_fn)(size_t size, void *cb_ctx);*/
@@ -27,7 +30,10 @@
void *header_container;
set_header_cb_t set_header_fn;
void *set_header_cb_ctx;
+ logger_cb_t logger_fn;
+ void *logger_cb_ctx;
+
char *key_file;
char *ca_file;
Modified: trunk/solutions/identity/modules/mod-cspace/res/test.c
==============================================================================
--- trunk/solutions/identity/modules/mod-cspace/res/test.c (original)
+++ trunk/solutions/identity/modules/mod-cspace/res/test.c Mon Dec 10
21:04:52 2007
@@ -14,10 +14,11 @@
process_context_t *ctx = cspace_process_context_create_default();
cspace_process_context_set_key_file(ctx, "identity.lk.wso2.com.key");
+ cspace_process_context_set_ca_file(ctx, "cacert.pem");
cspace_process_context_set_header_callback(ctx,
sample_set_header_callback ,
NULL);
- if (cspace_process_request(ctx, TEST_TOKEN_MANAGED, NULL, NULL)) {
+ if (cspace_process_request(ctx, TEST_TOKEN_MANAGED)) {
printf("Verificatio SUCCESS!\n\n");
} else {
printf("Verificatio FAILED!\n\n");
@@ -30,7 +31,7 @@
cspace_process_context_set_header_callback(ctx,
sample_set_header_callback ,
NULL);
- if (cspace_process_request(ctx, TEST_TOKEN_SELF, NULL, NULL)) {
+ if (cspace_process_request(ctx, TEST_TOKEN_SELF)) {
printf("Verificatio SUCCESS!\n");
} else {
printf("Verificatio FAILED!\n");
@@ -46,7 +47,6 @@
void *container, void *cb_ctx)
{
printf("header: %s, val: %s, uri: %s\n", key, val, ns_uri);
- free(ns_uri);
- free(key);
+ free(ns_uri); free(key);
free(val);
}
_______________________________________________
Identity-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/identity-dev