sslinit.c (1466B)
1 /* 2 * NSS utility functions 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #include "prtypes.h" 9 #include "prinit.h" 10 #include "nss.h" 11 #include "seccomon.h" 12 #include "secerr.h" 13 #include "ssl.h" 14 #include "sslimpl.h" 15 #include "sslproto.h" 16 17 static PRCallOnceType ssl_init = { 0 }; 18 PR_STATIC_ASSERT(sizeof(unsigned long) <= sizeof(PRUint64)); 19 20 static SECStatus 21 ssl_InitShutdown(void *appData, void *nssData) 22 { 23 memset(&ssl_init, 0, sizeof(ssl_init)); 24 return SECSuccess; 25 } 26 27 PRStatus 28 ssl_InitCallOnce(void *arg) 29 { 30 int *error = (int *)arg; 31 SECStatus rv; 32 33 rv = ssl_InitializePRErrorTable(); 34 if (rv != SECSuccess) { 35 *error = SEC_ERROR_NO_MEMORY; 36 return PR_FAILURE; 37 } 38 #ifdef DEBUG 39 ssl3_CheckCipherSuiteOrderConsistency(); 40 #endif 41 42 rv = ssl3_ApplyNSSPolicy(); 43 if (rv != SECSuccess) { 44 *error = PORT_GetError(); 45 return PR_FAILURE; 46 } 47 48 rv = NSS_RegisterShutdown(ssl_InitShutdown, NULL); 49 if (rv != SECSuccess) { 50 *error = PORT_GetError(); 51 return PR_FAILURE; 52 } 53 return PR_SUCCESS; 54 } 55 56 SECStatus 57 ssl_Init(void) 58 { 59 int error; 60 PRStatus nrv = PR_CallOnceWithArg(&ssl_init, ssl_InitCallOnce, &error); 61 if (nrv != PR_SUCCESS) { 62 PORT_SetError(error); 63 return SECFailure; 64 } 65 return SECSuccess; 66 }