| File: | src/camel/camel-search-utils.c |
| Warning: | line 41, column 2 Value stored to 'res' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * SPDX-FileCopyrightText: (C) 1999-2008 Novell, Inc. (www.novell.com) |
| 3 | * SPDX-License-Identifier: LGPL-2.0-or-later |
| 4 | * SPDX-FileContributor: Michael Zucchi <notzed@ximian.com> |
| 5 | */ |
| 6 | |
| 7 | #include "evolution-data-server-config.h" |
| 8 | |
| 9 | #include <glib.h> |
| 10 | |
| 11 | #include "camel-mime-utils.h" |
| 12 | #include "camel-sexp.h" |
| 13 | |
| 14 | #include "camel-search-utils.h" |
| 15 | |
| 16 | /** |
| 17 | * camel_search_util_add_months: |
| 18 | * @t: Initial time |
| 19 | * @months: number of months to add or subtract |
| 20 | * |
| 21 | * Increases time @t by the given number of months (or decreases, if |
| 22 | * @months is negative). |
| 23 | * |
| 24 | * Returns: a new #time_t value |
| 25 | * |
| 26 | * Since: 3.58 |
| 27 | **/ |
| 28 | time_t |
| 29 | camel_search_util_add_months (time_t t, |
| 30 | gint months) |
| 31 | { |
| 32 | GDateTime *dt, *dt2; |
| 33 | time_t res; |
| 34 | |
| 35 | if (!months) |
| 36 | return t; |
| 37 | |
| 38 | dt = g_date_time_new_from_unix_utc (t); |
| 39 | |
| 40 | /* just for issues, to return something inaccurate, but sane */ |
| 41 | res = t + (60 * 60 * 24 * 30 * months); |
Value stored to 'res' is never read | |
| 42 | |
| 43 | g_return_val_if_fail (dt != NULL, res)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_13 = 0; if (dt != ((void*)0)) _g_boolean_var_13 = 1; _g_boolean_var_13 ; }), 1))) { } else { g_return_if_fail_warning ("camel", ((const char*) (__func__)), "dt != NULL"); return (res); } } while ( 0); |
| 44 | |
| 45 | dt2 = g_date_time_add_months (dt, months); |
| 46 | g_date_time_unref (dt); |
| 47 | g_return_val_if_fail (dt2 != NULL, res)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_14 = 0; if (dt2 != ((void*)0)) _g_boolean_var_14 = 1; _g_boolean_var_14 ; }), 1))) { } else { g_return_if_fail_warning ("camel", ((const char*) (__func__)), "dt2 != NULL"); return (res); } } while ( 0); |
| 48 | |
| 49 | res = g_date_time_to_unix (dt2); |
| 50 | g_date_time_unref (dt2); |
| 51 | |
| 52 | return res; |
| 53 | } |
| 54 | |
| 55 | static time_t |
| 56 | folder_search_num_to_timet (gint num) |
| 57 | { |
| 58 | time_t res = (time_t) -1; |
| 59 | |
| 60 | if (num > 9999999) { |
| 61 | GDateTime *dtm; |
| 62 | |
| 63 | dtm = g_date_time_new_utc (num / 10000, (num / 100) % 100, num % 100, 0, 0, 0.0); |
| 64 | if (dtm) { |
| 65 | res = (time_t) g_date_time_to_unix (dtm); |
| 66 | g_date_time_unref (dtm); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return res; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * camel_search_util_str_to_time: |
| 75 | * @str: (nullable): string to convert to time, or %NULL |
| 76 | * |
| 77 | * Converts a string representation to a time_t (as gint64). |
| 78 | * When @str is %NULL, returns -1. |
| 79 | * |
| 80 | * Returns: a time_t representation of the @str, -1 on error |
| 81 | * |
| 82 | * Since: 3.58 |
| 83 | **/ |
| 84 | gint64 |
| 85 | camel_search_util_str_to_time (const gchar *str) |
| 86 | { |
| 87 | GDateTime *datetime; |
| 88 | gint64 res = -1; |
| 89 | |
| 90 | if (!str || !*str) |
| 91 | return -1; |
| 92 | |
| 93 | datetime = g_date_time_new_from_iso8601 (str, NULL((void*)0)); |
| 94 | if (datetime) { |
| 95 | res = g_date_time_to_unix (datetime); |
| 96 | g_date_time_unref (datetime); |
| 97 | } else if (strlen (str) == 8) { |
| 98 | gint num; |
| 99 | |
| 100 | num = atoi (str); |
| 101 | res = folder_search_num_to_timet (num); |
| 102 | } else { |
| 103 | res = camel_header_decode_date (str, NULL((void*)0)); |
| 104 | } |
| 105 | |
| 106 | return res; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * camel_search_util_make_time: |
| 111 | * @argc: number of arguments in @argv |
| 112 | * @argv: array or arguments |
| 113 | * |
| 114 | * Implementation of 'make-time' function, which expects one argument, |
| 115 | * a string or an integer, to be converted into time_t. |
| 116 | * |
| 117 | * Returns: time_t equivalent of the passed in argument, or (time_t) -1 on error. |
| 118 | * |
| 119 | * Since: 3.58 |
| 120 | **/ |
| 121 | time_t |
| 122 | camel_search_util_make_time (gint argc, |
| 123 | CamelSExpResult **argv) |
| 124 | { |
| 125 | time_t res = (time_t) -1; |
| 126 | |
| 127 | g_return_val_if_fail (argv != NULL, res)do { if ((__builtin_expect (__extension__ ({ int _g_boolean_var_15 = 0; if (argv != ((void*)0)) _g_boolean_var_15 = 1; _g_boolean_var_15 ; }), 1))) { } else { g_return_if_fail_warning ("camel", ((const char*) (__func__)), "argv != NULL"); return (res); } } while (0); |
| 128 | |
| 129 | if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_STRING && argv[0]->value.string) { |
| 130 | res = camel_search_util_str_to_time (argv[0]->value.string); |
| 131 | } else if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_TIME) { |
| 132 | res = argv[0]->value.time; |
| 133 | } else if (argc == 1 && argv[0]->type == CAMEL_SEXP_RES_INT) { |
| 134 | res = folder_search_num_to_timet (argv[0]->value.number); |
| 135 | } |
| 136 | |
| 137 | return res; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * camel_search_util_compare_date: |
| 142 | * @datetime1: a time_t-like value of the first date-time |
| 143 | * @datetime2: a time_t-like value of the second date-time |
| 144 | * |
| 145 | * Compares date portion of the two date-time values, first converted |
| 146 | * into the local time zone. The returned value is like with strcmp(). |
| 147 | * |
| 148 | * Returns: 0 when the dates are equal, < 0 when first is before second and |
| 149 | * > 0 when the first is after the second date |
| 150 | * |
| 151 | * Since: 3.58 |
| 152 | **/ |
| 153 | gint |
| 154 | camel_search_util_compare_date (gint64 datetime1, |
| 155 | gint64 datetime2) |
| 156 | { |
| 157 | struct tm tm; |
| 158 | time_t tt; |
| 159 | gint dt1, dt2; |
| 160 | |
| 161 | tt = (time_t) datetime1; |
| 162 | localtime_r (&tt, &tm); |
| 163 | dt1 = ((tm.tm_year + 1900) * 10000) + ((tm.tm_mon + 1) * 100) + tm.tm_mday; |
| 164 | |
| 165 | tt = (time_t) datetime2; |
| 166 | localtime_r (&tt, &tm); |
| 167 | dt2 = ((tm.tm_year + 1900) * 10000) + ((tm.tm_mon + 1) * 100) + tm.tm_mday; |
| 168 | |
| 169 | return dt1 - dt2; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * camel_search_util_hash_message_id: |
| 174 | * @message_id: a raw Message-ID header value |
| 175 | * @needs_decode: whether the @message_id requires camel_header_msgid_decode() first |
| 176 | * |
| 177 | * Calculates a hash of the Message-ID header value @message_id. |
| 178 | * |
| 179 | * Returns: hash of the @message_id, or 0 on any error. |
| 180 | * |
| 181 | * Since: 3.58 |
| 182 | **/ |
| 183 | guint64 |
| 184 | camel_search_util_hash_message_id (const gchar *message_id, |
| 185 | gboolean needs_decode) |
| 186 | { |
| 187 | GChecksum *checksum; |
| 188 | CamelSummaryMessageID message_id_struct; |
| 189 | gchar *msgid = NULL((void*)0); |
| 190 | guint8 *digest; |
| 191 | gsize length; |
| 192 | |
| 193 | if (!message_id) |
| 194 | return 0; |
| 195 | |
| 196 | if (needs_decode) |
| 197 | msgid = camel_header_msgid_decode (message_id); |
| 198 | |
| 199 | length = g_checksum_type_get_length (G_CHECKSUM_MD5); |
| 200 | digest = g_alloca (length)__builtin_alloca (length); |
| 201 | |
| 202 | checksum = g_checksum_new (G_CHECKSUM_MD5); |
| 203 | g_checksum_update (checksum, (guchar *) (msgid ? msgid : message_id), -1); |
| 204 | g_checksum_get_digest (checksum, digest, &length); |
| 205 | g_checksum_free (checksum); |
| 206 | |
| 207 | memcpy (message_id_struct.id.hash, digest, sizeof (message_id_struct.id.hash)); |
| 208 | g_free (msgid); |
| 209 | |
| 210 | return message_id_struct.id.id; |
| 211 | } |