#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
-void _notmuch_crypto_cleanup (unused(_notmuch_crypto_t *crypto))
+void
+_notmuch_crypto_cleanup (unused(_notmuch_crypto_t *crypto))
{
}
GError **err)
{
GMimeObject *ret = NULL;
+
if (decrypt == NOTMUCH_DECRYPT_FALSE)
return NULL;
GMimeDecryptFlags flags = GMIME_DECRYPT_NONE;
if (decrypt == NOTMUCH_DECRYPT_TRUE && decrypt_result)
flags |= GMIME_DECRYPT_EXPORT_SESSION_KEY;
- ret = g_mime_multipart_encrypted_decrypt(part, flags, NULL,
- decrypt_result, err);
+ ret = g_mime_multipart_encrypted_decrypt (part, flags, NULL,
+ decrypt_result, err);
return ret;
}
static int
_notmuch_message_crypto_destructor (_notmuch_message_crypto_t *msg_crypto)
{
- if (!msg_crypto)
+ if (! msg_crypto)
return 0;
if (msg_crypto->sig_list)
g_object_unref (msg_crypto->sig_list);
_notmuch_message_crypto_new (void *ctx)
{
_notmuch_message_crypto_t *ret = talloc_zero (ctx, _notmuch_message_crypto_t);
+
talloc_set_destructor (ret, _notmuch_message_crypto_destructor);
return ret;
}
notmuch_status_t
_notmuch_message_crypto_potential_sig_list (_notmuch_message_crypto_t *msg_crypto, GMimeSignatureList *sigs)
{
- if (!msg_crypto)
+ if (! msg_crypto)
return NOTMUCH_STATUS_NULL_POINTER;
/* Signatures that arrive after a payload part during DFS are not
const char *forwarded = NULL;
const char *subject = NULL;
- if (!msg_crypto || !payload)
+ if (! msg_crypto || ! payload)
return NOTMUCH_STATUS_NULL_POINTER;
/* only fire on the first payload part encountered */
} else {
/* Consider "memoryhole"-style protected headers as practiced by Enigmail and K-9 */
protected_headers = g_mime_object_get_content_type_parameter (payload, "protected-headers");
- if (protected_headers && strcasecmp("v1", protected_headers) == 0)
+ if (protected_headers && strcasecmp ("v1", protected_headers) == 0)
subject = g_mime_object_get_header (payload, "Subject");
/* FIXME: handle more than just Subject: at some point */
}
notmuch_status_t
_notmuch_message_crypto_successful_decryption (_notmuch_message_crypto_t *msg_crypto)
{
- if (!msg_crypto)
+ if (! msg_crypto)
return NOTMUCH_STATUS_NULL_POINTER;
/* see the rationale for different values of
* _notmuch_message_decryption_status_t in util/crypto.h */
- if (!msg_crypto->payload_encountered)
+ if (! msg_crypto->payload_encountered)
msg_crypto->decryption_status = NOTMUCH_MESSAGE_DECRYPTED_FULL;
else if (msg_crypto->decryption_status == NOTMUCH_MESSAGE_DECRYPTED_NONE)
msg_crypto->decryption_status = NOTMUCH_MESSAGE_DECRYPTED_PARTIAL;
/* signature status of the whole message (either the whole message
* is signed, or it is not) -- this means that partially-signed
* messages will get no signature status. */
- GMimeSignatureList * sig_list;
+ GMimeSignatureList *sig_list;
/* if part of the message was signed, and the MUA is clever, it
* can determine on its own exactly which part and try to make
* more sense of it. */
/* the value of any "Subject:" header in the cryptographic payload
* (the top level part within the crypto envelope), converted to
* UTF-8 */
- char * payload_subject;
+ char *payload_subject;
/* if both signed and encrypted, was the signature encrypted? */
bool signature_encrypted;
*
* Note that __location__ comes from talloc.h.
*/
-#define INTERNAL_ERROR(format, ...) \
- _internal_error (format " (%s).\n", \
+#define INTERNAL_ERROR(format, ...) \
+ _internal_error (format " (%s).\n", \
##__VA_ARGS__, __location__)
#ifdef __cplusplus
static
GMimeStream *
-_gzfile_maybe_filter (GMimeStream *file_stream) {
+_gzfile_maybe_filter (GMimeStream *file_stream)
+{
char buf[4];
int bytes_read;
return NULL;
/* check for gzipped input */
- if (bytes_read >= 2 && buf[0] == 0x1f && (unsigned char)buf[1] == 0x8b) {
+ if (bytes_read >= 2 && buf[0] == 0x1f && (unsigned char) buf[1] == 0x8b) {
GMimeStream *gzstream;
GMimeFilter *gzfilter;
return NULL;
/* ignore filter id */
- (void)g_mime_stream_filter_add ((GMimeStreamFilter *)gzstream, gzfilter);
+ (void) g_mime_stream_filter_add ((GMimeStreamFilter *) gzstream, gzfilter);
return gzstream;
} else {
return file_stream;
}
GMimeStream *
-g_mime_stream_stdout_new()
+g_mime_stream_stdout_new ()
{
GMimeStream *stream_stdout = NULL;
GMimeStream *stream_buffered = NULL;
stream_stdout = g_mime_stream_pipe_new (STDOUT_FILENO);
- if (!stream_stdout)
+ if (! stream_stdout)
return NULL;
g_mime_stream_pipe_set_owner (GMIME_STREAM_PIPE (stream_stdout), FALSE);
/**
* copy a glib string into a talloc context, and free it.
*/
-static char*
+static char *
g_string_talloc_strdup (void *ctx, char *g_string)
{
char *new_str = talloc_strdup (ctx, g_string);
+
g_free (g_string);
return new_str;
}
{
/* output user id only if validity is FULL or ULTIMATE. */
const char *uid = g_mime_certificate_get_user_id (cert);
+
if (uid == NULL)
return uid;
GMimeValidity validity = g_mime_certificate_get_id_validity (cert);
return NULL;
}
-const char*
-g_mime_certificate_get_fpr16 (GMimeCertificate *cert) {
+const char *
+g_mime_certificate_get_fpr16 (GMimeCertificate *cert)
+{
const char *fpr = g_mime_certificate_get_fingerprint (cert);
- if (!fpr || strlen (fpr) < 16)
+
+ if (! fpr || strlen (fpr) < 16)
return fpr;
return fpr + (strlen (fpr) - 16);
g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
{
InternetAddressList *list = g_mime_message_get_addresses (message, type);
+
return internet_address_list_to_string (list, NULL, 0);
}
char *
g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
{
- GDateTime* parsed_date = g_mime_message_get_date (message);
+ GDateTime *parsed_date = g_mime_message_get_date (message);
+
if (parsed_date) {
char *date = g_mime_utils_header_format_date (parsed_date);
return g_string_talloc_strdup (ctx, date);
} else {
- return talloc_strdup(ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
+ return talloc_strdup (ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
}
}
InternetAddressList *
-g_mime_message_get_reply_to_list(GMimeMessage *message)
+g_mime_message_get_reply_to_list (GMimeMessage *message)
{
return g_mime_message_get_reply_to (message);
}
g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
{
InternetAddressList *list = g_mime_message_get_reply_to (message);
+
return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
}
*/
gboolean
-g_mime_signature_status_good (GMimeSignatureStatus status) {
- return ((status & (GMIME_SIGNATURE_STATUS_RED | GMIME_SIGNATURE_STATUS_ERROR_MASK)) == 0);
+g_mime_signature_status_good (GMimeSignatureStatus status)
+{
+ return ((status & (GMIME_SIGNATURE_STATUS_RED | GMIME_SIGNATURE_STATUS_ERROR_MASK)) == 0);
}
gboolean
-g_mime_signature_status_bad (GMimeSignatureStatus status) {
+g_mime_signature_status_bad (GMimeSignatureStatus status)
+{
return (status & GMIME_SIGNATURE_STATUS_RED);
}
gboolean
-g_mime_signature_status_error (GMimeSignatureStatus status) {
+g_mime_signature_status_error (GMimeSignatureStatus status)
+{
return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK);
}
gint64
-g_mime_utils_header_decode_date_unix (const char *date) {
- GDateTime* parsed_date = g_mime_utils_header_decode_date (date);
+g_mime_utils_header_decode_date_unix (const char *date)
+{
+ GDateTime *parsed_date = g_mime_utils_header_decode_date (date);
time_t ret;
if (parsed_date) {
extern "C" {
#endif
-GMimeStream *g_mime_stream_stdout_new(void);
+GMimeStream *g_mime_stream_stdout_new (void);
/* Return a GMime stream for this open file descriptor, un-gzipping if
* necessary */
*/
char *g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type);
-InternetAddressList * g_mime_message_get_addresses (GMimeMessage *message, GMimeAddressType type);
+InternetAddressList *g_mime_message_get_addresses (GMimeMessage *message, GMimeAddressType type);
/**
* return talloc allocated date string
* glib allocated list of From: addresses
*/
-InternetAddressList * g_mime_message_get_from (GMimeMessage *message);
+InternetAddressList *g_mime_message_get_from (GMimeMessage *message);
/**
* return string for From: address
* (owned by gmime)
*/
-const char * g_mime_message_get_from_string (GMimeMessage *message);
+const char *g_mime_message_get_from_string (GMimeMessage *message);
-InternetAddressList * g_mime_message_get_reply_to_list (GMimeMessage *message);
+InternetAddressList *g_mime_message_get_reply_to_list (GMimeMessage *message);
/**
* return talloc allocated reply-to string
*/
-char * g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
+char *g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
void g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag);
/**
* Return string for valid User ID (or NULL if no valid User ID exists)
*/
-const char * g_mime_certificate_get_valid_userid (GMimeCertificate *cert);
+const char *g_mime_certificate_get_valid_userid (GMimeCertificate *cert);
#ifdef __cplusplus
}
if (*out == NULL)
*out_size = 0;
- if (!maybe_realloc (ctx, needed, out, out_size))
+ if (! maybe_realloc (ctx, needed, out, out_size))
return HEX_OUT_OF_MEMORY;
q = *out;
if (is_output (*p)) {
*q++ = *p++;
} else {
- sprintf (q, "%%%02x", (unsigned char)*p++);
+ sprintf (q, "%%%02x", (unsigned char) *p++);
q += 3;
}
}
char *endp;
/* This also handles unexpected end-of-string. */
- if (!isxdigit ((unsigned char) in[1]) ||
- !isxdigit ((unsigned char) in[2]))
+ if (! isxdigit ((unsigned char) in[1]) ||
+ ! isxdigit ((unsigned char) in[2]))
return HEX_SYNTAX_ERROR;
buf[0] = in[1];
}
hex_status_t
-hex_decode (void *ctx, const char *in, char **out, size_t * out_size)
+hex_decode (void *ctx, const char *in, char **out, size_t *out_size)
{
const char *p;
- size_t needed = 1; /* for the NUL */
+ size_t needed = 1; /* for the NUL */
assert (ctx); assert (in); assert (out); assert (out_size);
else
needed += 1;
- if (!maybe_realloc (ctx, needed, out, out_size))
+ if (! maybe_realloc (ctx, needed, out, out_size))
return HEX_OUT_OF_MEMORY;
return hex_decode_internal (in, (unsigned char *) *out);
hex_status_t
hex_encode (void *talloc_ctx, const char *in, char **out,
- size_t *out_size);
+ size_t *out_size);
hex_status_t
hex_decode (void *talloc_ctx, const char *in, char **out,
- size_t *out_size);
+ size_t *out_size);
/*
* Non-allocating hex decode to decode 's' in-place. The length of the
{
/* strtok_len is already const-safe, but we can't express both
* versions in the C type system. */
- return strtok_len ((char*)s, delim, len);
+ return strtok_len ((char *) s, delim, len);
}
char *
for (loop = out; *loop; loop++) {
if (*loop == '\t' || *loop == '\n')
*loop = ' ';
- else if ((unsigned char)(*loop) < 32)
+ else if ((unsigned char) (*loop) < 32)
*loop = '?';
}
* beginning, and anything containing non-ASCII text. */
if (! term[0])
need_quoting = 1;
- for (in = term; *in && !need_quoting; in++)
+ for (in = term; *in && ! need_quoting; in++)
if (is_unquoted_terminator (*in) || *in == '"' || *in == '('
- || (unsigned char)*in > 127)
+ || (unsigned char) *in > 127)
need_quoting = 1;
if (need_quoting)
return 0;
}
-const char*
+const char *
skip_space (const char *str)
{
while (*str && isspace ((unsigned char) *str))
char **prefix_out, char **term_out)
{
int err = EINVAL;
+
*prefix_out = *term_out = NULL;
/* Parse prefix */
}
/* Did the term terminate without a closing quote or is there
* trailing text after the closing quote? */
- if (!closed || *pos)
+ if (! closed || *pos)
goto FAIL;
*out = '\0';
} else {
}
return 0;
- FAIL:
+ FAIL:
talloc_free (*prefix_out);
talloc_free (*term_out);
errno = err;
else if (! s1 && ! s2)
return 0;
else if (s1)
- return 1; /* s1 (non-NULL) is greater than s2 (NULL) */
+ return 1; /* s1 (non-NULL) is greater than s2 (NULL) */
else
- return -1; /* s1 (NULL) is less than s2 (non-NULL) */
+ return -1; /* s1 (NULL) is less than s2 (non-NULL) */
}
int
/* This is the djb2 hash. */
unsigned int hash = 5381;
+
while (s && *s) {
hash = ((hash << 5) + hash) + tolower (*s);
s++;
void strip_trailing (char *str, char ch);
-const char* skip_space (const char *str);
+const char *skip_space (const char *str);
#ifdef __cplusplus
}
#include "unicode-util.h"
/* Based on Xapian::Unicode::is_wordchar, to avoid forcing clients to
- link directly to libxapian.
-*/
+ * link directly to libxapian.
+ */
static bool
unicode_is_wordchar (notmuch_unichar ch)
/* we lack context to be more informative here */
return "zlib error";
default:
- INTERNAL_ERROR("unexpected error status %d", errnum);
+ INTERNAL_ERROR ("unexpected error status %d", errnum);
}
}
regerror (rerr, preg, error, error_size);
fprintf (stderr, "compiling regex %s: %s\n",
- regex, error);
+ regex, error);
free (error);
return 1;
}
if (buf == NULL)
return UTIL_OUT_OF_MEMORY;
}
- SUCCESS:
+ SUCCESS:
*bufptr = buf;
*bytes_read = offset;
return UTIL_SUCCESS;
}
-const char *gz_error_string (util_status_t status, gzFile file)
+const char *
+gz_error_string (util_status_t status, gzFile file)
{
if (status == UTIL_GZERROR)
return gzerror (file, NULL);