Commit ec38ddb5 authored by Ian Goldberg's avatar Ian Goldberg

Don't have otrl_init call exit(1)

Don't have otrl_init call exit(1) if the application's requested version
number differs from libotr's.  Rather, return a non-zero error code, and
have the application clean up gracefully.  The OTRL_INIT macro now
checks the error code and does an exit(1) as the default behaviour, but
the application can do what it likes.
parent d0eef09c
2012-08-28
* UPGRADING:
* src/proto.h:
* src/proto.c: Don't have otrl_init call exit(1) if the
application's requested version number differs from libotr's.
Rather, return a non-zero error code, and have the application
clean up gracefully. The OTRL_INIT macro now checks the error
code and does an exit(1) as the default behaviour, but the
application can do what it likes.
2012-08-27
* src/auth.h:
......
......@@ -15,6 +15,7 @@ Table of Contents
3.2. Instance Tags
3.3. Fragmentation Changes
3.4. Asynchronous Private Key Generation
3.5. Library Initialization
1. Introduction
......@@ -499,5 +500,16 @@ If the privkey generation was cancelled, the application should call:
void otrl_privkey_generate_cancelled(OtrlUserState us, void *newkey)
3.5. Library Initialization
If you currently initialize libotr with the recommended OTRL_INIT;
macro, you do not need to change anything.
If you call otrl_init(ver_major, ver_minor, ver_sub) directly, then know
that this function no longer returns void. Previously, if the
application requested version numbers incompatible with those of the
library, the library would exit(1). Now, the otrl_init call will return
a non-zero error code. You must check the return value of otrl_init (a
gcry_error_t), and if it is non-zero, your application's expected
API/ABI does not match the installed libotr, and libotr cannot be used.
......@@ -48,7 +48,7 @@ unsigned int otrl_api_version = 0;
/* Initialize the OTR library. Pass the version of the API you are
* using. */
void otrl_init(unsigned int ver_major, unsigned int ver_minor,
gcry_error_t otrl_init(unsigned int ver_major, unsigned int ver_minor,
unsigned int ver_sub)
{
unsigned int api_version;
......@@ -60,7 +60,7 @@ void otrl_init(unsigned int ver_major, unsigned int ver_minor,
"with actual version %u.%u.%u. Aborting.\n",
ver_major, ver_minor, ver_sub,
OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR, OTRL_VERSION_SUB);
exit(1);
return gcry_error(GPG_ERR_INV_VALUE);
}
/* Set the API version. If we get called multiple times for some
......@@ -84,6 +84,8 @@ void otrl_init(unsigned int ver_major, unsigned int ver_minor,
fprintf(stderr, "\nlibotr debugging is available. Type %s in a message\n"
" to see debug info.\n\n", OTRL_DEBUGGING_DEBUGSTR);
#endif
return gcry_error(GPG_ERR_NO_ERROR);
}
/* Return a pointer to a static string containing the version number of
......
......@@ -102,12 +102,15 @@ typedef enum {
/* Initialize the OTR library. Pass the version of the API you are
* using. */
void otrl_init(unsigned int ver_major, unsigned int ver_minor,
gcry_error_t otrl_init(unsigned int ver_major, unsigned int ver_minor,
unsigned int ver_sub);
/* Shortcut */
#define OTRL_INIT do { \
otrl_init(OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR, OTRL_VERSION_SUB); \
if (otrl_init(OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR, \
OTRL_VERSION_SUB)) { \
exit(1); \
} \
} while(0)
/* Return a pointer to a static string containing the version number of
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment