correctly handle CANL_ERROR_CODE when updating error messages in context
authorMarcel Poul <marcel.poul@cern.ch>
Tue, 29 May 2012 22:22:11 +0000 (22:22 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Tue, 29 May 2012 22:22:11 +0000 (22:22 +0000)
emi.canl.canl-c/Makefile
emi.canl.canl-c/src/canl_err.c
emi.canl.canl-c/src/canl_locl.h
emi.canl.canl-c/src/gen_err_desc.pl

index bb9e95a..bf5d60c 100644 (file)
@@ -79,9 +79,10 @@ all: ${LIBCANL} server client proxy delegation doc
 doc: canl.pdf
 
 ${LIBCANL}:\
-       canl.lo canl_err.lo canl_dns.lo canl_ssl.lo canl_cert.lo canl_cred.lo                   \
-       canl_err_desc.lo doio.lo evaluate.lo list.lo normalize.lo proxycertinfo.lo              \
-       scutils.lo sslutils.lo data.lo namespaces_parse.lo namespaces_lex.lo                    \
+       canl_err_desc.lo canl.lo canl_err.lo canl_dns.lo canl_ssl.lo \
+       canl_cert.lo canl_cred.lo\
+       doio.lo evaluate.lo list.lo normalize.lo proxycertinfo.lo\
+       scutils.lo sslutils.lo data.lo namespaces_parse.lo namespaces_lex.lo\
        signing_policy_parse.lo signing_policy_lex.lo
        ${LINK} -rpath ${stagedir}${prefix}/${libdir} ${version_info} $+ ${LFLAGS_LIB} -o $@
 
index c316c85..29ebded 100644 (file)
@@ -6,6 +6,8 @@ static canl_err_code resolve_error_code(glb_ctx *cc, unsigned long err_code,
         canl_err_origin err_orig);
 static void get_error_string(glb_ctx *cc, char *code_str);
 static canl_err_code update_error_msg(canl_ctx cc, const char *new_msg);
+static char *
+canl_strerror(const canl_err_code c_code);
 
 /* Save error message into err_msg
  * use NULL for empty err_format */
@@ -177,6 +179,14 @@ static void get_error_string(glb_ctx *cc, char *code_str)
                 code_str[ERR_CODE_LEN - 1] = '\0';
             }
             break;
+        case CANL_ERROR:
+            new_str = canl_strerror(cc->err_code);
+            if (new_str) {
+                strncpy(code_str, new_str,
+                        ERR_CODE_LEN);
+                code_str[ERR_CODE_LEN - 1] = '\0';
+            }
+            break;
         default:
            snprintf(code_str, ERR_CODE_LEN,
                     "Unknown error origin (%u) of error %lu!",
@@ -185,6 +195,19 @@ static void get_error_string(glb_ctx *cc, char *code_str)
     }
 }
 
+static char *
+canl_strerror(const canl_err_code c_code)
+{
+    char *new_str = NULL;
+    int k = 0;
+    for (k = 0; k < canl_err_descs_num; k++) {
+        if (canl_err_descs[k].code == c_code) {
+            new_str = canl_err_descs[k].desc;
+        }
+    }
+    return new_str;
+}
+
 canl_err_code
 canl_get_error_code(canl_ctx cc)
 {
index 64ccc9f..1a0a22e 100644 (file)
@@ -118,6 +118,9 @@ typedef struct canl_mech {
 /* Mechanism specific */
 extern canl_mech canl_mech_ssl;
 
+extern canl_err_desc canl_err_descs[];
+extern int canl_err_descs_num;
+
 struct canl_mech *
 find_mech(gss_OID oid);
 
index c17c3a2..b7425a6 100755 (executable)
@@ -33,7 +33,7 @@ print qq (/*
 #include "canl_locl.h"
 #include "canl_mech_ssl.h"
 
-struct canl_err_desc canl_err_descs[] = {);
+canl_err_desc canl_err_descs[] = {);
 
 open (DESC, $desc_file) or die ("Failed to open $desc_file: $!");
 while (<DESC>) {
@@ -67,4 +67,6 @@ make_c_line ($err_name, $err_dsc, $openssl_err_lib, $openssl_err_reason)
 
 print STDOUT qq (
 };
+
+int canl_err_descs_num = sizeof(canl_err_descs)/sizeof(*canl_err_descs);
 );