Gammu internals  1.38.0
Debug

Macros

#define dbgprintf
 

Typedefs

typedef struct _GSM_Debug_Info GSM_Debug_Info
 

Functions

int smprintf_level (GSM_StateMachine *s, GSM_DebugSeverity severity, const char *format,...)
 
GSM_Error GSM_SetDebugFunction (GSM_Log_Function info, void *data, GSM_Debug_Info *privdi)
 
GSM_Error GSM_SetDebugFile (const char *info, GSM_Debug_Info *privdi)
 
GSM_Error GSM_SetDebugFileDescriptor (FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
 
GSM_Debug_InfoGSM_GetGlobalDebug (void)
 
gboolean GSM_SetDebugLevel (const char *info, GSM_Debug_Info *privdi)
 
gboolean GSM_SetDebugCoding (const char *info, GSM_Debug_Info *privdi)
 
gboolean GSM_SetDebugGlobal (gboolean info, GSM_Debug_Info *privdi)
 
void GSM_LogError (GSM_StateMachine *s, const char *message, const GSM_Error err)
 
int smprintf (GSM_StateMachine *s, const char *format,...)
 

Detailed Description

Debuging handling.

Macro Definition Documentation

§ dbgprintf

Typedef Documentation

§ GSM_Debug_Info

Debugging configuration.

Definition at line 28 of file gammu-debug.h.

Function Documentation

§ GSM_GetGlobalDebug()

GSM_Debug_Info* GSM_GetGlobalDebug ( void  )

Returns global debug settings.

Returns
Pointer to global settings.

Definition at line 216 of file gsmcomon.c.

References GSM_global_debug.

217 {
218  return &GSM_global_debug;
219 }
GSM_Debug_Info GSM_global_debug
Definition: debug.c:33

§ GSM_LogError()

void GSM_LogError ( GSM_StateMachine s,
const char *  message,
const GSM_Error  err 
)

Logs error to debug log with additional message.

Parameters
sState machine structure pointer.
messageString to be show in message.
errError code.

Definition at line 221 of file gsmcomon.c.

References ERR_NONE, GSM_ErrorName(), GSM_ErrorString(), and smprintf().

Referenced by GSM_InitConnection_Log().

221  {
222  if (err != ERR_NONE) {
223  smprintf(s, "%s failed with error %s[%d]: %s\n", message,
224  GSM_ErrorName(err), err,
225  GSM_ErrorString(err));
226  }
227 }
const char * GSM_ErrorName(GSM_Error e)
Definition: gsmcomon.c:167
const char * GSM_ErrorString(GSM_Error e)
Definition: gsmcomon.c:183
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ GSM_SetDebugCoding()

gboolean GSM_SetDebugCoding ( const char *  info,
GSM_Debug_Info privdi 
)

Sets debug encoding.

Parameters
infoEncoding to set.
privdiPointer to debug information data.
Returns
True on success.

Definition at line 227 of file debug.c.

References _GSM_Debug_Info::coding, and TRUE.

228 {
229  privdi->coding = info;
230  return TRUE;
231 }
const char * coding
Definition: debug.h:38
#define TRUE
Definition: gammu-types.h:28

§ GSM_SetDebugFile()

GSM_Error GSM_SetDebugFile ( const char *  info,
GSM_Debug_Info privdi 
)

Sets debug file.

Parameters
infoFile path.
privdiPointer to debug information data.
Returns
Error code.

Definition at line 144 of file debug.c.

References COMMIT_FLAG, dbgprintf, _GSM_Debug_Info::dl, DL_BINARY, DL_TEXTERROR, DL_TEXTERRORDATE, ERR_CANTOPENFILE, FALSE, GSM_SetDebugFileDescriptor(), and TRUE.

Referenced by GSM_InitConnection_Log().

145 {
146  FILE *testfile;
147 
148  if (info == NULL || strlen(info) == 0) {
149  return GSM_SetDebugFileDescriptor(NULL, FALSE, privdi);
150  }
151 
152  switch (privdi->dl) {
153  case DL_BINARY:
154  testfile = fopen(info,"wb" COMMIT_FLAG);
155  break;
156  case DL_TEXTERROR:
157  case DL_TEXTERRORDATE:
158  testfile = fopen(info,"a" COMMIT_FLAG);
159  if (testfile != NULL) {
160  fseek(testfile, 0, SEEK_END);
161  if (ftell(testfile) > 5000000) {
162  fclose(testfile);
163  testfile = fopen(info,"w" COMMIT_FLAG);
164  }
165  }
166  break;
167  default:
168  testfile = fopen(info,"w" COMMIT_FLAG);
169  }
170 
171  if (testfile == NULL) {
172  dbgprintf(privdi, "Can't open debug file\n");
173  return ERR_CANTOPENFILE;
174  } else {
175  return GSM_SetDebugFileDescriptor(testfile, TRUE, privdi);
176  }
177 }
GSM_Error GSM_SetDebugFileDescriptor(FILE *fd, gboolean closable, GSM_Debug_Info *privdi)
Definition: debug.c:127
#define FALSE
Definition: gammu-types.h:25
#define COMMIT_FLAG
Definition: debug.c:15
#define dbgprintf
Definition: debug.h:72
#define TRUE
Definition: gammu-types.h:28
Debug_Level dl
Definition: debug.h:35

§ GSM_SetDebugFileDescriptor()

GSM_Error GSM_SetDebugFileDescriptor ( FILE *  fd,
gboolean  closable,
GSM_Debug_Info privdi 
)

Sets debug file.

Parameters
fdFile descriptor.
privdiPointer to debug information data.
closableWhether Gammu can close the file when it is no longer needed for debug output. Please note that stderr or stdout are never closed.
Returns
Error code.

Definition at line 127 of file debug.c.

References _GSM_Debug_Info::closable, _GSM_Debug_Info::df, ERR_NONE, TRUE, and _GSM_Debug_Info::was_lf.

Referenced by GSM_SetDebugFile(), and GSM_TerminateConnection().

128 {
129  privdi->was_lf = TRUE;
130 
131  if (privdi->df != NULL
132  && fileno(privdi->df) != fileno(stderr)
133  && fileno(privdi->df) != fileno(stdout)
134  && privdi->closable) {
135  fclose(privdi->df);
136  }
137 
138  privdi->df = fd;
139  privdi->closable = closable;
140 
141  return ERR_NONE;
142 }
FILE * df
Definition: debug.h:36
gboolean was_lf
Definition: debug.h:39
gboolean closable
Definition: debug.h:40
#define TRUE
Definition: gammu-types.h:28

§ GSM_SetDebugFunction()

GSM_Error GSM_SetDebugFunction ( GSM_Log_Function  info,
void *  data,
GSM_Debug_Info privdi 
)

Sets logging function.

Parameters
infoFunction to call.
dataUser data to pass as a second parameter to callback.
privdiPointer to debug information data.
Returns
Error code.

Definition at line 179 of file debug.c.

References ERR_NONE, _GSM_Debug_Info::log_function, and _GSM_Debug_Info::user_data.

Referenced by GSM_InitConnection_Log().

180 {
181  privdi->log_function = info;
182  privdi->user_data = data;
183  return ERR_NONE;
184 }
GSM_Log_Function log_function
Definition: debug.h:44
void * user_data
Definition: debug.h:48

§ GSM_SetDebugGlobal()

gboolean GSM_SetDebugGlobal ( gboolean  info,
GSM_Debug_Info privdi 
)

Enables using of global debugging configuration. Makes no effect on global debug configuration.

Parameters
infoEnable global debug usage..
privdiPointer to debug information data.
Returns
True on success.

Definition at line 233 of file debug.c.

References PRINTF_STYLE, TRUE, and _GSM_Debug_Info::use_global.

234 {
235  privdi->use_global = info;
236  return TRUE;
237 }
gboolean use_global
Definition: debug.h:37
#define TRUE
Definition: gammu-types.h:28

§ GSM_SetDebugLevel()

gboolean GSM_SetDebugLevel ( const char *  info,
GSM_Debug_Info privdi 
)

Sets debug level.

Parameters
infoLevel as text.
privdiPointer to debug information data.
Returns
True on success.

Definition at line 186 of file debug.c.

References _GSM_Debug_Info::dl, DL_BINARY, DL_NONE, DL_TEXT, DL_TEXTALL, DL_TEXTALLDATE, DL_TEXTDATE, DL_TEXTERROR, DL_TEXTERRORDATE, FALSE, and TRUE.

Referenced by GSM_InitConnection_Log().

187 {
188  if (info == NULL) {
189  privdi->dl = DL_NONE;
190  return TRUE;
191  }
192  if (strcasecmp(info, "nothing") == 0) {
193  privdi->dl = DL_NONE;
194  return TRUE;
195  }
196  if (strcasecmp(info, "text") == 0) {
197  privdi->dl = DL_TEXT;
198  return TRUE;
199  }
200  if (strcasecmp(info, "textall") == 0) {
201  privdi->dl = DL_TEXTALL;
202  return TRUE;
203  }
204  if (strcasecmp(info, "binary") == 0) {
205  privdi->dl = DL_BINARY;
206  return TRUE;
207  }
208  if (strcasecmp(info, "errors") == 0) {
209  privdi->dl = DL_TEXTERROR;
210  return TRUE;
211  }
212  if (strcasecmp(info, "textdate") == 0) {
213  privdi->dl = DL_TEXTDATE;
214  return TRUE;
215  }
216  if (strcasecmp(info, "textalldate") == 0) {
217  privdi->dl = DL_TEXTALLDATE;
218  return TRUE;
219  }
220  if (strcasecmp(info, "errorsdate") == 0) {
221  privdi->dl = DL_TEXTERRORDATE;
222  return TRUE;
223  }
224  return FALSE;
225 }
Definition: debug.h:26
#define FALSE
Definition: gammu-types.h:25
Definition: debug.h:24
#define TRUE
Definition: gammu-types.h:28
Debug_Level dl
Definition: debug.h:35

§ smprintf()

int smprintf ( GSM_StateMachine s,
const char *  format,
  ... 
)

Prints string to defined debug log.

Parameters
sState machine, where to print.
formatFormat string as for printf.
Returns
Upon successful return, these functions return the number of characters printed (as printf).

Definition at line 261 of file debug.c.

References dbg_vprintf(), GSM_GetDI(), and PRINTF_STYLE.

Referenced by DUMMY_DeleteFolder(), DUMMY_Error(), DUMMY_GetFolderListing(), DUMMY_GetNextFileFolder(), DUMMY_Initialise(), DUMMY_PreAPICall(), DUMMY_SendSMS(), GSM_CloseConnection(), GSM_CreateFirmwareNumber(), GSM_DispatchMessage(), GSM_DumpMessageBinary_Custom(), GSM_DumpMessageText_Custom(), GSM_InitConnection_Log(), GSM_LogError(), GSM_OSErrorInfo(), GSM_RegisterAllConnections(), GSM_RegisterAllPhoneModules(), GSM_RegisterModule(), GSM_SendSavedSMS(), GSM_TerminateConnection(), GSM_TryGetModel(), lock_device(), N71_65_DecodePhonebook(), N71_65_EncodePhonebookFrame(), N71_65_PackPBKBlock(), N71_65_PB_CopyString(), NOKIA_DecodeDateTime(), NOKIA_EncodeDateTime(), NoneReply(), PHONE_EncodeSMSFrame(), PHONE_FindDataFile(), proxy_write(), and unlock_device().

262 {
263  va_list argp;
264  int result=0;
265  GSM_Debug_Info *curdi;
266 
267  curdi = GSM_GetDI(s);
268 
269  va_start(argp, format);
270 
271  result = dbg_vprintf(curdi, format, argp);
272 
273  va_end(argp);
274  return result;
275 }
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
int dbg_vprintf(GSM_Debug_Info *d, const char *format, va_list argp)
Definition: debug.c:57

§ smprintf_level()

int smprintf_level ( GSM_StateMachine s,
GSM_DebugSeverity  severity,
const char *  format,
  ... 
)

Prints string to defined debug log.

Parameters
sState machine, where to print.
severitySeverity of printed message.
formatFormat string as for printf.
Returns
Upon successful return, these functions return the number of characters printed (as printf).

Definition at line 278 of file debug.c.

References D_ERROR, D_TEXT, dbg_vprintf(), _GSM_Debug_Info::dl, DL_TEXT, DL_TEXTALL, DL_TEXTALLDATE, DL_TEXTDATE, DL_TEXTERROR, DL_TEXTERRORDATE, and GSM_GetDI().

Referenced by GSM_DispatchMessage(), GSM_InitConnection_Log(), GSM_WaitFor(), and NOKIA_EncodeDateTime().

279 {
280  va_list argp;
281  int result=0;
282  GSM_Debug_Info *curdi;
283 
284  curdi = GSM_GetDI(s);
285 
286  if (severity == D_TEXT) {
287  if (curdi->dl != DL_TEXT &&
288  curdi->dl != DL_TEXTALL &&
289  curdi->dl != DL_TEXTDATE &&
290  curdi->dl != DL_TEXTALLDATE) {
291  return 0;
292  }
293  } else if (severity == D_ERROR) {
294  if (curdi->dl != DL_TEXT &&
295  curdi->dl != DL_TEXTALL &&
296  curdi->dl != DL_TEXTDATE &&
297  curdi->dl != DL_TEXTALLDATE &&
298  curdi->dl != DL_TEXTERROR &&
299  curdi->dl != DL_TEXTERRORDATE) {
300  return 0;
301  }
302  }
303  va_start(argp, format);
304 
305  result = dbg_vprintf(curdi, format, argp);
306 
307  va_end(argp);
308  return result;
309 }
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
Definition: debug.h:26
int dbg_vprintf(GSM_Debug_Info *d, const char *format, va_list argp)
Definition: debug.c:57
Definition: debug.h:87
Debug_Level dl
Definition: debug.h:35
Definition: debug.h:91