"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/src/libexchangemapi/e-mapi-debug.c" (2 Dec 2022, 9414 Bytes) of package /linux/misc/evolution-mapi-3.46.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "e-mapi-debug.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * This program is free software; you can redistribute it and/or
    3  * modify it under the terms of the GNU Lesser General Public
    4  * License as published by the Free Software Foundation; either
    5  * version 2 of the License, or (at your option) version 3.
    6  *
    7  * This program is distributed in the hope that it will be useful,
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10  * Lesser General Public License for more details.
   11  *
   12  * You should have received a copy of the GNU Lesser General Public
   13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
   14  *
   15  *
   16  * Copyright (C) 2011 Red Hat, Inc. (www.redhat.com)
   17  *
   18  */
   19 
   20 #include <stdarg.h>
   21 
   22 #include "e-mapi-debug.h"
   23 
   24 gboolean
   25 e_mapi_debug_is_enabled (void)
   26 {
   27     static gchar enabled = -1;
   28 
   29     if (enabled == -1)
   30         enabled = g_getenv ("MAPI_DEBUG") != NULL ? 1 : 0;
   31 
   32     return enabled == 1;
   33 }
   34 
   35 void
   36 e_mapi_debug_print (const gchar *format, ...)
   37 {
   38     va_list args;
   39 
   40     g_return_if_fail (format != NULL);
   41 
   42     if (!e_mapi_debug_is_enabled ())
   43         return;
   44 
   45     va_start (args, format);
   46     vfprintf (stdout, format, args);
   47     va_end (args);
   48 
   49     fprintf (stdout, "\n");
   50     fflush (stdout);
   51 }
   52 
   53 void
   54 e_mapi_debug_dump_bin (const uint8_t *bin,
   55                uint32_t bin_sz,
   56                gint indent)
   57 {
   58     gint k, l, last;
   59 
   60     g_print ("%*s", indent, "");
   61 
   62     if (!bin) {
   63         g_print ("NULL");
   64         return;
   65     }
   66 
   67     last = 0;
   68     for (k = 0; k < bin_sz; k++) {
   69         if ((k > 0 && (k % 16) == 0)) {
   70             g_print ("  ");
   71             for (l = last; l < k; l++) {
   72                 uint8_t u8 = bin[l];
   73 
   74                 if ((l % 8) == 0)
   75                     g_print (" ");
   76                 if (u8 <= 32 || u8 >= 128)
   77                     g_print (".");
   78                 else
   79                     g_print ("%c", u8);
   80             }
   81 
   82             last = l;
   83             g_print ("\n%*s", indent, "");
   84         } else if (k > 0 && (k % 8) == 0) {
   85             g_print ("  ");
   86         }
   87         g_print (" %02X", bin[k]);
   88     }
   89 
   90     if (last < k) {
   91         l = k;
   92 
   93         while ((l % 16) != 0) {
   94             g_print ("   ");
   95             if (l > 0 && (l % 8) == 0)
   96                 g_print ("  ");
   97             l++;
   98         }
   99 
  100         g_print ("  ");
  101         for (l = last; l < k; l++) {
  102             uint8_t u8 = bin[l];
  103 
  104             if ((l % 8) == 0)
  105                 g_print (" ");
  106             if (u8 <= 32 || u8 >= 128)
  107                 g_print (".");
  108             else
  109                 g_print ("%c", u8);
  110         }
  111     }
  112 }
  113 
  114 void
  115 e_mapi_debug_dump_properties (struct mapi_SPropValue_array *properties,
  116                   gint indent)
  117 {
  118     gint i = 0;
  119 
  120     g_return_if_fail (properties != NULL);
  121 
  122     for (i = 0; i < properties->cValues; i++) {
  123         struct mapi_SPropValue *lpProp = &properties->lpProps[i];
  124         const gchar *tmp;
  125         gchar t_str[26];
  126         gint j = 0;
  127 
  128         tmp = get_proptag_name (lpProp->ulPropTag);
  129         if (!tmp || !*tmp)
  130             tmp = get_namedid_name (lpProp->ulPropTag);
  131 
  132         if (tmp && *tmp)
  133             g_print ("%*s%s ", indent, "", tmp);
  134         else
  135             g_print ("%*s0x%08X   ", indent, "", lpProp->ulPropTag);
  136         switch (lpProp->ulPropTag & 0xFFFF) {
  137         case PT_UNSPECIFIED:
  138             g_print (" PT_UNSPECIFIED");
  139             break;
  140         case PT_NULL:
  141             g_print (" PT_NULL");
  142             break;
  143         case PT_BOOLEAN:
  144             g_print (" (bool) - %d", lpProp->value.b);
  145             break;
  146         case PT_I2:
  147             g_print (" (uint16_t) - %d", lpProp->value.i);
  148             break;
  149         case PT_LONG:
  150             g_print (" (long) - %u", lpProp->value.l);
  151             break;
  152         case PT_FLOAT:
  153             g_print (" PT_FLOAT");
  154             break;
  155         case PT_DOUBLE:
  156             g_print (" (double) -  %lf", (double)lpProp->value.dbl);
  157             break;
  158         case PT_CURRENCY:
  159             g_print (" PT_CURRENCY");
  160             break;
  161         case PT_APPTIME:
  162             g_print (" PT_APPTIME");
  163             break;
  164         case PT_I8:
  165             g_print (" (gint) - 0x%016" G_GINT64_MODIFIER "X", lpProp->value.d);
  166             break;
  167         case PT_SYSTIME: {
  168                 struct timeval t;
  169                 struct tm tm;
  170                 if (get_mapi_SPropValue_array_date_timeval (&t, properties, lpProp->ulPropTag) == MAPI_E_SUCCESS) {
  171                     gmtime_r (&(t.tv_sec), &tm);
  172                     strftime (t_str, 26, "%Y-%m-%dT%H:%M:%SZ", &tm);
  173                     g_print (" (struct FILETIME *) - %p   (struct timeval) %s", &lpProp->value.ft, t_str);
  174                 }
  175             }
  176             break;
  177         case PT_ERROR:
  178             g_print (" (error) - "/* , lpProp->value.err */);
  179             break;
  180         case PT_STRING8:
  181             g_print (" (string) - '%s'", lpProp->value.lpszA ? lpProp->value.lpszA : "null");
  182             break;
  183         case PT_UNICODE:
  184             g_print (" (unicodestring) - '%s'", lpProp->value.lpszW ? lpProp->value.lpszW : lpProp->value.lpszA ? lpProp->value.lpszA : "null");
  185             break;
  186         case PT_OBJECT:
  187             g_print (" PT_OBJECT");
  188             break;
  189         case PT_CLSID:
  190             g_print (" PT_CLSID");
  191             break;
  192         case PT_SVREID:
  193             g_print (" PT_SVREID");
  194             break;
  195         case PT_SRESTRICT:
  196             g_print (" PT_SRESTRICT");
  197             break;
  198         case PT_ACTIONS:
  199             g_print (" PT_ACTIONS");
  200             break;
  201         case PT_BINARY:
  202             g_print (" (struct SBinary_short *) - %p Binary data follows (size %d): %s", &lpProp->value.bin, lpProp->value.bin.cb, lpProp->value.bin.cb > 0 ? "\n" : "");
  203             e_mapi_debug_dump_bin (lpProp->value.bin.lpb, lpProp->value.bin.cb, indent + 3);
  204             break;
  205         case PT_MV_STRING8:
  206             g_print (" (struct mapi_SLPSTRArray *) (%d items)", lpProp->value.MVszA.cValues);
  207             for (j = 0; j < lpProp->value.MVszA.cValues; j++) {
  208                 g_print ("\n%*sitem[%d] = '%s'", indent + 2, "", j, lpProp->value.MVszA.strings[j].lppszA ? lpProp->value.MVszA.strings[j].lppszA : "[NULL]");
  209             }
  210             break;
  211         case PT_MV_SHORT:
  212             g_print (" PT_MV_SHORT");
  213             break;
  214         case PT_MV_LONG:
  215             g_print (" PT_MV_LONG");
  216             break;
  217         case PT_MV_FLOAT:
  218             g_print (" PT_MV_FLOAT");
  219             break;
  220         case PT_MV_DOUBLE:
  221             g_print (" PT_MV_DOUBLE");
  222             break;
  223         case PT_MV_CURRENCY:
  224             g_print (" PT_MV_CURRENCY");
  225             break;
  226         case PT_MV_APPTIME:
  227             g_print (" PT_MV_APPTIME");
  228             break;
  229         case PT_MV_I8:
  230             g_print (" PT_MV_I8");
  231             break;
  232         case PT_MV_UNICODE:
  233             g_print (" PT_MV_UNICODE (%d items)", lpProp->value.MVszW.cValues);
  234             for (j = 0; j < lpProp->value.MVszW.cValues; j++) {
  235                 g_print ("\n%*sitem[%d] = '%s'", indent + 2, "", j, lpProp->value.MVszW.strings[j].lppszW ? lpProp->value.MVszW.strings[j].lppszW : "[NULL]");
  236             }
  237             break;
  238         case PT_MV_SYSTIME:
  239             g_print (" PT_MV_SYSTIME");
  240             break;
  241         case PT_MV_CLSID:
  242             g_print (" PT_MV_CLSID");
  243             break;
  244         case PT_MV_BINARY:
  245             g_print (" PT_MV_BINARY (%d items)", lpProp->value.MVbin.cValues);
  246             for (j = 0; j < lpProp->value.MVbin.cValues; j++) {
  247                 g_print ("\n%*sitem[%d] (size %d)\n", indent + 2, "", j, lpProp->value.MVbin.bin[j].cb);
  248                 e_mapi_debug_dump_bin (lpProp->value.MVbin.bin[j].lpb, lpProp->value.MVbin.bin[j].cb, indent + 3);
  249             }
  250             break;
  251         default:
  252             g_print (" - Unknown type 0x%04X", lpProp->ulPropTag & 0xFFFF);
  253             break;
  254         }
  255 
  256         g_print ("\n");
  257     }
  258 }
  259 
  260 static void
  261 e_mapi_debug_dump_streamed_properties (guint32 streamed_properties_count,
  262                        const EMapiStreamedProp *streamed_properties,
  263                        gint indent)
  264 {
  265     guint32 ii;
  266 
  267     if (!streamed_properties || streamed_properties_count <= 0)
  268         return;
  269 
  270     for (ii = 0; ii < streamed_properties_count; ii++) {
  271         const gchar *tmp;
  272 
  273         tmp = get_proptag_name (streamed_properties[ii].proptag);
  274         if (!tmp || !*tmp)
  275             tmp = get_namedid_name (streamed_properties[ii].proptag);
  276 
  277         if (tmp && *tmp)
  278             g_print ("%*s%s ", indent, "", tmp);
  279         else
  280             g_print ("%*s0x%08X   ", indent, "", streamed_properties[ii].proptag);
  281 
  282         switch (streamed_properties[ii].proptag & 0xFFFF) {
  283         case PT_STRING8:
  284             g_print (" (streamed string) - '%s'", streamed_properties[ii].cb == 0 ? "" : streamed_properties[ii].lpb ? (const gchar *) streamed_properties[ii].lpb : "null");
  285             break;
  286         case PT_UNICODE:
  287             g_print (" (streamed unicodestring) - '%s'", streamed_properties[ii].cb == 0 ? "" : streamed_properties[ii].lpb ? (const gchar *) streamed_properties[ii].lpb : "null");
  288             break;
  289         case PT_BINARY:
  290             g_print (" (streamed Binary %p, size %" G_GINT64_MODIFIER "d): %s", streamed_properties[ii].lpb, streamed_properties[ii].cb, streamed_properties[ii].cb > 0 ? "\n" : "");
  291             e_mapi_debug_dump_bin (streamed_properties[ii].lpb, streamed_properties[ii].cb, indent + 3);
  292             break;
  293         default:
  294             g_print (" (other streamed type %p, size %" G_GINT64_MODIFIER "d): %s", streamed_properties[ii].lpb, streamed_properties[ii].cb, streamed_properties[ii].cb > 0 ? "\n" : "");
  295             e_mapi_debug_dump_bin (streamed_properties[ii].lpb, streamed_properties[ii].cb, indent + 3);
  296             break;
  297         }
  298 
  299         g_print ("\n");
  300     }
  301 }
  302 
  303 void
  304 e_mapi_debug_dump_object (EMapiObject *object, gboolean with_properties, gint indent)
  305 {
  306     EMapiRecipient *recipient;
  307     EMapiAttachment *attachment;
  308     gint index;
  309 
  310     g_print ("%*sEMapiObject: %p (parent:%p)\n", indent, "", object, object ? object->parent : NULL);
  311 
  312     if (!object)
  313         return;
  314 
  315     if (with_properties) {
  316         e_mapi_debug_dump_properties (&object->properties, indent + 3);
  317         e_mapi_debug_dump_streamed_properties (object->streamed_properties_count, object->streamed_properties, indent + 3);
  318     }
  319 
  320     for (index = 0, recipient = object->recipients; recipient; index++, recipient = recipient->next) {
  321         g_print ("%*sRecipient[%d]:\n", indent + 2, "", index);
  322         if (with_properties)
  323             e_mapi_debug_dump_properties (&recipient->properties, indent + 5);
  324     }
  325 
  326     for (index = 0, attachment = object->attachments; attachment; index++, attachment = attachment->next) {
  327         g_print ("%*sAttachment[%d]:\n", indent + 2, "", index);
  328         if (with_properties) {
  329             e_mapi_debug_dump_properties (&attachment->properties, indent + 3);
  330             e_mapi_debug_dump_streamed_properties (attachment->streamed_properties_count, attachment->streamed_properties, indent + 3);
  331         }
  332 
  333         if (attachment->embedded_object) {
  334             g_print ("%*sEmbedded object:\n", indent + 3, "");
  335             e_mapi_debug_dump_object (attachment->embedded_object, with_properties, indent + 5);
  336         }
  337     }
  338 }