On Tue, Aug 28, 2012 at 01:34:11PM +0200, Thibaut VARENE wrote:
> On Tue, Aug 28, 2012 at 2:24 AM, Ian Goldberg <[email protected]> wrote:
>
> > Indeed, otrl_init(ver_major, ver_minor, ver_sub) calls exit(1) if the
> > passed version numbers are incompatible with the library's actual
> > version.
> >
> > Seeing as how it's intended to be called from this macro:
> >
> > #define OTRL_INIT do { \
> > otrl_init(OTRL_VERSION_MAJOR, OTRL_VERSION_MINOR,
> > OTRL_VERSION_SUB); \
> > } while(0)
> >
> > I suppose we could change otrl_init to return an error code, and change
> > the *macro* to call exit() upon otrl_init returning an error. Although
> > technically the ABI would change, the API wouldn't.
>
> As long as the macro itself isn't used in the library, this should indeed
> work.
>
> > I will consider this for inclusion before release.
> >
> > Thanks for the note!
>
> You're welcome!
Thibaut,
Can you apply this patch and see if it cleans things up? If it looks
good, I'll include it for 4.0.0.
Thanks,
- Ian
diff --git a/ChangeLog b/ChangeLog
index 82984bf..42de6ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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:
diff --git a/UPGRADING b/UPGRADING
index 58cfc78..f7445c3 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -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.
diff --git a/src/proto.c b/src/proto.c
index 3522249..b6c773a 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -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
diff --git a/src/proto.h b/src/proto.h
index 3419e9b..28be83f 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -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
_______________________________________________
OTR-dev mailing list
[email protected]
http://lists.cypherpunks.ca/mailman/listinfo/otr-dev