media/webrtc/signaling/src/sipcc/cpr/android/cpr_android_stdio.c

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "cpr_stdio.h"
michael@0 6 #include "cpr_string.h"
michael@0 7 #include "CSFLog.h"
michael@0 8
michael@0 9 /**
michael@0 10 * @def LOG_MAX
michael@0 11 *
michael@0 12 * Constant represents the maximum allowed length for a message
michael@0 13 */
michael@0 14 #define LOG_MAX 1024
michael@0 15
michael@0 16 /**
michael@0 17 * @addtogroup DebugAPIs The CPR Logging Abstractions
michael@0 18 * @ingroup CPR
michael@0 19 * @brief The CPR Debug/Logging APIs
michael@0 20 *
michael@0 21 * @{
michael@0 22 */
michael@0 23
michael@0 24 /**
michael@0 25 * Debug message
michael@0 26 *
michael@0 27 * @param _format format string
michael@0 28 * @param ... variable arg list
michael@0 29 *
michael@0 30 * @return Return code from vsnprintf
michael@0 31 *
michael@0 32 * @pre (_format not_eq NULL)
michael@0 33 */
michael@0 34 int
michael@0 35 buginf (const char *_format, ...)
michael@0 36 {
michael@0 37 char fmt_buf[LOG_MAX + 1];
michael@0 38 va_list ap;
michael@0 39 int rc;
michael@0 40
michael@0 41 va_start(ap, _format);
michael@0 42 rc = vsnprintf(fmt_buf, LOG_MAX, _format, ap);
michael@0 43 va_end(ap);
michael@0 44 if (rc <= 0) {
michael@0 45 return rc;
michael@0 46 }
michael@0 47
michael@0 48 CSFLogDebug("cpr", "%s", fmt_buf);
michael@0 49
michael@0 50 return rc;
michael@0 51 }
michael@0 52
michael@0 53 /**
michael@0 54 * Debug message that can be larger than #LOG_MAX
michael@0 55 *
michael@0 56 * @param str - a fixed constant string
michael@0 57 *
michael@0 58 * @return zero(0)
michael@0 59 *
michael@0 60 * @pre (str not_eq NULL)
michael@0 61 */
michael@0 62 int
michael@0 63 buginf_msg (const char *str)
michael@0 64 {
michael@0 65 char buf[LOG_MAX + 1];
michael@0 66 const char *p;
michael@0 67 int16_t len;
michael@0 68
michael@0 69 // terminate buffer
michael@0 70 buf[LOG_MAX] = NUL;
michael@0 71
michael@0 72 len = (int16_t) strlen(str);
michael@0 73
michael@0 74 if (len > LOG_MAX) {
michael@0 75 p = str;
michael@0 76 do {
michael@0 77 memcpy(buf, p, LOG_MAX);
michael@0 78 p += LOG_MAX;
michael@0 79 len -= LOG_MAX;
michael@0 80
michael@0 81 printf("%s",buf);
michael@0 82 } while (len > LOG_MAX);
michael@0 83
michael@0 84 if (len) {
michael@0 85 CSFLogDebug("cpr", "%s", (char *)p);
michael@0 86 }
michael@0 87 } else {
michael@0 88 CSFLogDebug("cpr", "%s", (char *) str);
michael@0 89 }
michael@0 90
michael@0 91 return 0;
michael@0 92 }
michael@0 93
michael@0 94 /**
michael@0 95 * Error message
michael@0 96 *
michael@0 97 * @param _format format string
michael@0 98 * @param ... variable arg list
michael@0 99 *
michael@0 100 * @return Return code from vsnprintf
michael@0 101 *
michael@0 102 * @pre (_format not_eq NULL)
michael@0 103 */
michael@0 104 void
michael@0 105 err_msg (const char *_format, ...)
michael@0 106 {
michael@0 107 char fmt_buf[LOG_MAX + 1];
michael@0 108 va_list ap;
michael@0 109 int rc;
michael@0 110
michael@0 111 va_start(ap, _format);
michael@0 112 rc = vsnprintf(fmt_buf, LOG_MAX, _format, ap);
michael@0 113 va_end(ap);
michael@0 114 if (rc <= 0) {
michael@0 115 return;
michael@0 116 }
michael@0 117
michael@0 118 CSFLogError("cpr", "%s", fmt_buf);
michael@0 119 }
michael@0 120
michael@0 121
michael@0 122 /**
michael@0 123 * Notice message
michael@0 124 *
michael@0 125 * @param _format format string
michael@0 126 * @param ... variable arg list
michael@0 127 *
michael@0 128 * @return Return code from vsnprintf
michael@0 129 *
michael@0 130 * @pre (_format not_eq NULL)
michael@0 131 */
michael@0 132 void
michael@0 133 notice_msg (const char *_format, ...)
michael@0 134 {
michael@0 135 char fmt_buf[LOG_MAX + 1];
michael@0 136 va_list ap;
michael@0 137 int rc;
michael@0 138
michael@0 139 va_start(ap, _format);
michael@0 140 rc = vsnprintf(fmt_buf, LOG_MAX, _format, ap);
michael@0 141 va_end(ap);
michael@0 142 if (rc <= 0) {
michael@0 143 return;
michael@0 144 }
michael@0 145
michael@0 146 CSFLogInfo("cpr", "%s", fmt_buf);
michael@0 147 }
michael@0 148

mercurial