Gammu internals  1.38.0
debug.h File Reference
#include <gammu-debug.h>
#include <stdarg.h>
Include dependency graph for debug.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _GSM_Debug_Info
 

Macros

#define dbgprintf
 

Enumerations

enum  Debug_Level {
  DL_NONE = 0, DL_BINARY = 1, DL_TEXT, DL_TEXTALL,
  DL_TEXTERROR, DL_TEXTDATE, DL_TEXTALLDATE, DL_TEXTERRORDATE
}
 
enum  GSM_DebugSeverity { D_NONE, D_TEXT, D_ERROR }
 

Functions

void DumpMessage (GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
 
void DumpMessageText (GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
 
int smfprintf (GSM_Debug_Info *d, const char *format,...)
 
int dbg_vprintf (GSM_Debug_Info *d, const char *format, va_list argp)
 
int smprintf_level (GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
 

Variables

GSM_Debug_Info GSM_global_debug
 
GSM_Debug_Info GSM_none_debug
 

Enumeration Type Documentation

§ Debug_Level

Debugging level.

Enumerator
DL_NONE 

No debug messages

DL_BINARY 

Binary transmission dump

DL_TEXT 

Text transmission dump

DL_TEXTALL 

Everything

DL_TEXTERROR 

Only errors

DL_TEXTDATE 

Text transmission dump

DL_TEXTALLDATE 

Everything

DL_TEXTERRORDATE 

Only errors

Definition at line 23 of file debug.h.

23  {
24  DL_NONE = 0,
25  DL_BINARY = 1,
26  DL_TEXT,
27  DL_TEXTALL,
28  DL_TEXTERROR,
29  DL_TEXTDATE,
32 } Debug_Level;
Definition: debug.h:26
Debug_Level
Definition: debug.h:23
Definition: debug.h:24

§ GSM_DebugSeverity

Severity of printed message.

Enumerator
D_NONE 

Message will not be printed.

D_TEXT 

Message is printed in all text log levels.

D_ERROR 

Message is printed on all text error log levels.

Definition at line 79 of file debug.h.

79  {
83  D_NONE,
87  D_TEXT,
91  D_ERROR
Definition: debug.h:83
Definition: debug.h:87
GSM_DebugSeverity
Definition: debug.h:79
Definition: debug.h:91

Function Documentation

§ dbg_vprintf()

int dbg_vprintf ( GSM_Debug_Info d,
const char *  format,
va_list  argp 
)

Definition at line 57 of file debug.c.

References GSM_DateTime::Day, DayOfWeek(), dbg_write(), DL_NONE, DL_TEXTALLDATE, DL_TEXTDATE, DL_TEXTERRORDATE, FALSE, GSM_GetCurrentDateTime(), GSM_DateTime::Hour, GSM_DateTime::Minute, GSM_DateTime::Month, GSM_DateTime::Second, TRUE, and GSM_DateTime::Year.

Referenced by smfprintf(), smprintf(), and smprintf_level().

58 {
59  int result=0;
60  char buffer[3000], timestamp[60];
61  char *pos, *end;
62  char save = 0;
63  GSM_DateTime date_time;
64  Debug_Level l;
65 
66  l = d->dl;
67 
68  if (l == DL_NONE) return 0;
69 
70  result = vsnprintf(buffer, sizeof(buffer) - 1, format, argp);
71  pos = buffer;
72 
73  while (*pos != 0) {
74 
75  /* Find new line in string */
76  end = strstr(pos, "\n");
77 
78  /* Are we at start of line? */
79  if (d->was_lf) {
80  /* Show date? */
81  if (l == DL_TEXTALLDATE || l == DL_TEXTERRORDATE || l == DL_TEXTDATE) {
82  GSM_GetCurrentDateTime(&date_time);
83  sprintf(timestamp, "%s %4d/%02d/%02d %02d:%02d:%02d: ",
84  DayOfWeek(date_time.Year, date_time.Month, date_time.Day),
85  date_time.Year, date_time.Month, date_time.Day,
86  date_time.Hour, date_time.Minute, date_time.Second);
87  dbg_write(d, timestamp);
88  }
89  d->was_lf = FALSE;
90  }
91 
92  /* Remember end char */
93  if (end != NULL) {
94  save = *end;
95  *end = 0;
96  }
97 
98  /* Output */
99  dbg_write(d, pos);
100 
101  if (end != NULL) {
102  /* We had new line */
103  dbg_write(d, "\n");
104  d->was_lf = TRUE;
105 
106  /* Restore saved char */
107  *end = save;
108 
109  /* Advance to next line */
110  pos = end + strlen("\n");
111  } else {
112  /* We hit end of string */
113  break;
114  }
115  }
116 
117  /* Flush buffers, this might be configurable, but it could cause drop of last log messages */
118 #ifndef WIN32
119  if (d->df != NULL) {
120  fflush(d->df);
121  }
122 #endif
123 
124  return result;
125 }
FILE * df
Definition: debug.h:36
char * DayOfWeek(unsigned int year, unsigned int month, unsigned int day)
Definition: misc.c:129
Debug_Level
Definition: debug.h:23
gboolean was_lf
Definition: debug.h:39
#define FALSE
Definition: gammu-types.h:25
Definition: debug.h:24
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
#define TRUE
Definition: gammu-types.h:28
void dbg_write(GSM_Debug_Info *d, const char *text)
Definition: debug.c:47
Debug_Level dl
Definition: debug.h:35

§ DumpMessage()

void DumpMessage ( GSM_Debug_Info d,
const unsigned char *  message,
const size_t  messagesize 
)

Definition at line 314 of file debug.c.

References CHARS_PER_LINE, and smfprintf().

Referenced by DumpMessageText(), GSM_DecodeMMSIndication(), GSM_DispatchMessage(), GSM_DumpMessageText_Custom(), GSM_EncodeEMSMultiPartSMS(), GSM_EncodeMultiPartSMS(), and N71_65_DecodePhonebook().

315 {
316  size_t i, j = 0;
317  char buffer[(CHARS_PER_LINE * 5) + 1];
318 
319  smfprintf(d, "\n");
320 
321  if (messagesize == 0) return;
322 
323  memset(buffer, ' ', CHARS_PER_LINE * 5);
324  buffer[CHARS_PER_LINE * 5] = 0;
325 
326  for (i = 0; i < messagesize; i++) {
327  /* Write hex number */
328  snprintf(buffer + (j * 4), 3, "%02X", message[i]);
329  buffer[(j * 4) + 2] = ' '; /* wipe snprintf's \0 */
330 
331  /* Write char if possible */
332  if (isprint(message[i])
333  /* 0x09 = tab */
334  && message[i] != 0x09
335  /* 0x01 = beep in windows xp */
336  && message[i] != 0x01
337  /* these are empty in windows xp */
338  && message[i] != 0x85
339  && message[i] != 0x95
340  && message[i] != 0xA6
341  && message[i] != 0xB7) {
342  buffer[(j * 4) + 2] = message[i];
343  buffer[(CHARS_PER_LINE - 1) * 4 + j + 4] = message[i];
344  } else {
345  buffer[(CHARS_PER_LINE - 1) * 4 + j + 4] = '.';
346  }
347 
348  /* Write char separator */
349  if (j != CHARS_PER_LINE - 1 && i != messagesize - 1) {
350  buffer[j * 4 + 3] = '|';
351  }
352 
353  /* Print out buffer */
354  if (j == CHARS_PER_LINE - 1) {
355  smfprintf(d, "%s\n", buffer);
356  memset(buffer, ' ', CHARS_PER_LINE * 5);
357  j = 0;
358  } else {
359  j++;
360  }
361  }
362 
363  /* Anything remains to be printed? */
364  if (j != 0) {
365  smfprintf(d, "%s\n", buffer);
366  }
367 }
#define CHARS_PER_LINE
Definition: debug.c:311
int smfprintf(GSM_Debug_Info *d, const char *format,...)
Definition: debug.c:240

§ DumpMessageText()

void DumpMessageText ( GSM_Debug_Info d,
const unsigned char *  message,
const size_t  messagesize 
)

Definition at line 371 of file debug.c.

References _GSM_Debug_Info::dl, DL_TEXTALL, DL_TEXTALLDATE, and DumpMessage().

Referenced by DecodeDefault(), EncodeDefault(), GSM_DecodePDUFrame(), GSM_DecodeSMSFrameText(), GSM_DecodeUDHHeader(), and GSM_EncodeSMSFrameText().

372 {
373  if (d == NULL || (d->dl != DL_TEXTALL && d->dl == DL_TEXTALLDATE)) return;
374  DumpMessage(d, message, messagesize);
375 
376 }
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
Definition: debug.c:314
Debug_Level dl
Definition: debug.h:35

§ smfprintf()

int smfprintf ( GSM_Debug_Info d,
const char *  format,
  ... 
)

Variable Documentation

§ GSM_global_debug

§ GSM_none_debug

GSM_Debug_Info GSM_none_debug

Definition at line 22 of file debug.c.

Referenced by GSM_InitConnection(), and GSM_InitConnection_Log().