Exemplo n.º 1
0
static int
xmlSecOpenSSLErrorsInit(void) {
    static ERR_STRING_DATA xmlSecOpenSSLStrReasons[XMLSEC_ERRORS_MAX_NUMBER + 1];
    static ERR_STRING_DATA xmlSecOpenSSLStrLib[]= {
        { ERR_PACK(XMLSEC_OPENSSL_ERRORS_LIB,0,0),      "xmlsec routines"},
        { 0,                                            NULL}
    };
    static ERR_STRING_DATA xmlSecOpenSSLStrDefReason[]= {
        { XMLSEC_OPENSSL_ERRORS_LIB,                    "xmlsec lib"},
        { 0,                                            NULL}
    };
    xmlSecSize pos;

    /* initialize reasons array */
    memset(xmlSecOpenSSLStrReasons, 0, sizeof(xmlSecOpenSSLStrReasons));
    for(pos = 0; (pos < XMLSEC_ERRORS_MAX_NUMBER) && (xmlSecErrorsGetMsg(pos) != NULL); ++pos) {
        xmlSecOpenSSLStrReasons[pos].error  = xmlSecErrorsGetCode(pos);
        xmlSecOpenSSLStrReasons[pos].string = xmlSecErrorsGetMsg(pos);
    }

    /* finally load xmlsec strings in OpenSSL */
    ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrLib); /* define xmlsec lib name */
    ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrDefReason); /* define default reason */
    ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrReasons);

    /* and set default errors callback for xmlsec to us */
    xmlSecErrorsSetCallback(xmlSecOpenSSLErrorsDefaultCallback);

    return(0);
}
Exemplo n.º 2
0
void secErrorCallback (const char *file,
                       int line,
                       const char *func,
                       const char *errorObject,
                       const char *errorSubject,
                       int reason,
                       const char *msg)
{
    const char* error_msg = NULL;

    for (xmlSecSize i = 0;
            (i < XMLSEC_ERRORS_MAX_NUMBER) && (xmlSecErrorsGetMsg(i) != NULL);
            ++i)
    {
        if (xmlSecErrorsGetCode(i) == reason)
        {
            error_msg = xmlSecErrorsGetMsg(i);
            break;
        }
    }
    char* str = sec_error_str;
    for (; (*str && ((str - sec_error_str) < SEC_ERRORSTR_SIZE)); str++);
    snprintf(str, SEC_ERRORSTR_SIZE - (str - sec_error_str),
             "func=%s:file=%s:line=%d:obj=%s:subj=%s:error=%d:%s:%s\n",
             (func != NULL) ? func : "unknown",
             (file != NULL) ? file : "unknown",
             line,
             (errorObject != NULL) ? errorObject : "unknown",
             (errorSubject != NULL) ? errorSubject : "unknown",
             reason,
             (error_msg != NULL) ? error_msg : "",
             (msg != NULL) ? msg : "");
#ifdef DEBUG_EXCEPTIONS
    fprintf(stderr,
            "func=%s:file=%s:line=%d:obj=%s:subj=%s:error=%d:%s:%s\n",
            (func != NULL) ? func : "unknown",
            (file != NULL) ? file : "unknown",
            line,
            (errorObject != NULL) ? errorObject : "unknown",
            (errorSubject != NULL) ? errorSubject : "unknown",
            reason,
            (error_msg != NULL) ? error_msg : "",
            (msg != NULL) ? msg : "");
#endif // DEBUG_EXCEPTIONS
}