Add Android logging support
authorJason Cooper <openconnect@lakedaemon.net>
Fri, 15 Jul 2011 17:51:12 +0000 (10:51 -0700)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 15 Jul 2011 17:51:12 +0000 (10:51 -0700)
[dwmw2: make it use the --syslog option instead of removing it]

Signed-off-by: Jason Cooper <cyanogen@lakedaemon.net>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
main.c
openconnect.html

diff --git a/main.c b/main.c
index 72e8bc1..18f2353 100644 (file)
--- a/main.c
+++ b/main.c
  */
 
 #include <stdio.h>
+#ifdef ANDROID
+#include <android/log.h>
+#else
 #include <syslog.h>
+#endif
 #include <stdarg.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -475,7 +479,9 @@ int main(int argc, char **argv)
                exit(1);
 
        if (use_syslog) {
+#ifndef ANDROID
                openlog("openconnect", LOG_PID, LOG_DAEMON);
+#endif
                vpninfo->progress = syslog_progress;
        }
 
@@ -613,6 +619,24 @@ void write_progress(void *_vpninfo, int level, const char *fmt, ...)
        }
 }
 
+#ifdef ANDROID
+void syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
+{
+        static int l[4] = {
+               ANDROID_LOG_ERROR,      /* PRG_ERR   */
+               ANDROID_LOG_INFO,       /* PRG_INFO  */
+               ANDROID_LOG_DEBUG,      /* PRG_DEBUG */
+               ANDROID_LOG_DEBUG       /* PRG_TRACE */
+        };
+       va_list args;
+
+       if (verbose >= level) {
+               va_start(args, fmt);
+               __android_log_vprint(l[level], "openconnect", fmt, args);
+               va_end(args);
+       }
+}
+#else /* !ANDROID */
 void syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
 {
        int priority = level ? LOG_INFO : LOG_NOTICE;
@@ -624,7 +648,7 @@ void syslog_progress(void *_vpninfo, int level, const char *fmt, ...)
                va_end(args);
        }
 }
-
+#endif
 
 struct accepted_cert {
        struct accepted_cert *next;
index 873d584..0b97156 100644 (file)
@@ -183,6 +183,7 @@ For full changelog entries including the latest development, see
 <UL>
   <LI><B>OpenConnect HEAD</B><BR>
      <UL>
+       <LI>Add logging support for Android, in place of standard <TT>syslog()</TT>.</LI>
        <LI>Switch back to using TLSv1, but without extensions.</LI>
        <LI>Make TPM support optional, dependent on OpenSSL ENGINE support.</LI>
      </UL><BR>
@@ -489,6 +490,6 @@ An <TT>openconnect</TT> <A HREF="http://www.freebsd.org/cgi/cvsweb.cgi/ports/sec
 <hr>
 <address>David Woodhouse &lt;<A HREF="mailto:dwmw2@infradead.org">dwmw2@infradead.org</A>&gt;</address>
 <!-- hhmts start -->
-Last modified: Fri Jul 15 10:20:37 PDT 2011
+Last modified: Fri Jul 15 10:47:38 PDT 2011
 <!-- hhmts end -->
 </body> </html>