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

Go to the source code of this file.

Macros

#define MAX(a, b)   ((a)>(b) ? (a) : (b))
 
#define MIN(a, b)   ((a)<(b) ? (a) : (b))
 
#define GSM_GNUC_PREREQ(maj, min)   0
 
#define PRINTF_STYLE(f, a)
 
#define SCANF_STYLE(f, a)
 
#define WARNUNUSED
 
#define UNUSED
 
#define NORETURN
 
#define __FUNCTION__WORKING
 

Functions

size_t GetLine (FILE *File, char *Line, int count)
 
const char * GetGammuVersion (void)
 
const char * GetCompiler (void)
 
const char * GetOS (void)
 
const char * GetGammuLocalePath (void)
 
void GSM_InitLocales (const char *path)
 
void EncodeHexBin (char *dest, const unsigned char *src, size_t len)
 
gboolean GSM_IsNewerVersion (const char *latest_version, const char *current_version)
 
GSM_Error GSM_SetPower (GSM_StateMachine *s, gboolean on)
 

Detailed Description

Author
Michal Čihař

Miscellaneous helper functions.

Definition in file gammu-misc.h.

Macro Definition Documentation

§ __FUNCTION__WORKING

#define __FUNCTION__WORKING

Definition at line 128 of file gammu-misc.h.

§ GSM_GNUC_PREREQ

#define GSM_GNUC_PREREQ (   maj,
  min 
)    0

Definition at line 84 of file gammu-misc.h.

§ MAX

#define MAX (   a,
 
)    ((a)>(b) ? (a) : (b))

Definition at line 68 of file gammu-misc.h.

Referenced by PHONE_FindDataFile().

§ MIN

#define MIN (   a,
 
)    ((a)<(b) ? (a) : (b))

§ NORETURN

#define NORETURN

Definition at line 111 of file gammu-misc.h.

§ PRINTF_STYLE

#define PRINTF_STYLE (   f,
 
)

§ SCANF_STYLE

#define SCANF_STYLE (   f,
 
)

Definition at line 93 of file gammu-misc.h.

§ UNUSED

#define UNUSED

Definition at line 105 of file gammu-misc.h.

Referenced by NOKIA_EncodeDateTime().

§ WARNUNUSED

#define WARNUNUSED

Definition at line 99 of file gammu-misc.h.

Function Documentation

§ EncodeHexBin()

void EncodeHexBin ( char *  dest,
const unsigned char *  src,
size_t  len 
)

Encodes text to hexadecimal binary representation.

Definition at line 426 of file coding.c.

References EncodeWithHexBinAlphabet().

Referenced by EncodeHexUnicode().

427 {
428  size_t i, outpos = 0;
429 
430  for (i = 0; i < len; i++) {
431  dest[outpos++] = EncodeWithHexBinAlphabet(src[i] >> 4);
432  dest[outpos++] = EncodeWithHexBinAlphabet(src[i] & 0xF);
433  }
434  dest[outpos] = 0;
435 }
char EncodeWithHexBinAlphabet(int digit)
Definition: coding.c:375

§ GetCompiler()

const char* GetCompiler ( void  )

Gets compiler which was used to compile Gammu library.

Definition at line 659 of file misc.c.

660 {
661  static char Buffer[100] = {0x00};
662 
663  /* Value was already calculated */
664  if (Buffer[0] != 0) return Buffer;
665 
666 #ifdef _MSC_VER
667  if (_MSC_VER == 1200) { /* ? */
668  snprintf(Buffer, sizeof(Buffer) - 1, "MS VC 6.0");
669  } else if (_MSC_VER == 1300) {
670  snprintf(Buffer, sizeof(Buffer) - 1, "MS VC .NET 2002");
671  } else if (_MSC_VER == 1310) {
672  snprintf(Buffer, sizeof(Buffer) - 1, "MS VC .NET 2003");
673  } else if (_MSC_VER == 1400) {
674  snprintf(Buffer, sizeof(Buffer) - 1, "MS VC .NET 2005");
675  } else {
676  snprintf(Buffer, sizeof(Buffer) - 1, "MS VC %i",_MSC_VER);
677  }
678 #elif defined(__BORLANDC__)
679  snprintf(Buffer, sizeof(Buffer) - 1, "Borland C++ %i",__BORLANDC__);
680 #elif defined(__MINGW32__)
681  snprintf(Buffer, sizeof(Buffer) - 1, "GCC %i.%i, MinGW %i.%i", __GNUC__, __GNUC_MINOR__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
682 #elif defined(__CYGWIN__)
683  snprintf(Buffer, sizeof(Buffer) - 1, "GCC %i.%i, Cygwin %i.%i", __GNUC__, __GNUC_MINOR__, CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR);
684 #elif defined(__GNUC__)
685  snprintf(Buffer, sizeof(Buffer) - 1, "GCC %i.%i", __GNUC__, __GNUC_MINOR__);
686 #elif defined(DJGPP)
687  snprintf(Buffer, sizeof(Buffer) - 1, "djgpp %d.%d", __DJGPP, __DJGPP_MINOR);
688 #elif defined(__SUNPRO_CC)
689  snprintf(Buffer, sizeof(Buffer) - 1, "Sun C++ %x", __SUNPRO_CC);
690 #elif defined(__INTEL_COMPILER)
691  snprintf(Buffer, sizeof(Buffer) - 1, "Intel Compiler %ld", __INTEL_COMPILER);
692 #else
693  snprintf(Buffer, sizeof(Buffer) - 1, "unknown compiler");
694 #endif
695 
696  return Buffer;
697 }

§ GetGammuLocalePath()

const char* GetGammuLocalePath ( void  )

Returns path to Gammu locales.

Definition at line 200 of file gsmcomon.c.

References LOCALE_PATH.

201 {
202 #ifdef LOCALE_PATH
203  static const char Buffer[] = LOCALE_PATH;
204  return Buffer;
205 #else
206  return NULL;
207 #endif
208 }
#define LOCALE_PATH
Definition: gammu-config.h:377

§ GetGammuVersion()

const char* GetGammuVersion ( void  )

Gets Gammu library version.

Definition at line 210 of file gsmcomon.c.

References GAMMU_VERSION.

211 {
212  static const char Buffer[] = GAMMU_VERSION;
213  return Buffer;
214 }
#define GAMMU_VERSION
Definition: gammu-config.h:7

§ GetLine()

size_t GetLine ( FILE *  File,
char *  Line,
int  count 
)

Reads single line from file.

Parameters
FileFile descriptor to read from.
LineBuffer where t ostore result.
countMaximal length of text which can be stored in buffer.
Returns
Length of read line, -1 on error.

Definition at line 370 of file misc.c.

371 {
372  int num;
373 
374  if (fgets(Line, count, File) != NULL) {
375  num = strlen(Line) - 1;
376  while (num > 0) {
377  if (Line[num] != '\n' && Line[num] != '\r') break;
378  Line[num--] = '\0';
379  }
380  return strlen(Line);
381  }
382  return -1;
383 }

§ GetOS()

const char* GetOS ( void  )

Gets host OS.

Definition at line 537 of file misc.c.

References FALSE, and TRUE.

Referenced by GSM_InitConnection_Log().

538 {
539 #ifdef WIN32
540  OSVERSIONINFOEX Ver;
541  gboolean Extended = TRUE;
542 #else
543 # ifdef HAVE_SYS_UTSNAME_H
544  struct utsname Ver;
545 # endif
546 #endif
547  static char Buffer[100] = {0x00};
548 
549  /* Value was already calculated */
550  if (Buffer[0] != 0) return Buffer;
551 
552 #ifdef WIN32
553  memset(&Ver,0,sizeof(OSVERSIONINFOEX));
554  Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
555 
556  if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
557  Extended = FALSE;
558  Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
559  if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
560  snprintf(Buffer, sizeof(Buffer) - 1, "Windows");
561  return Buffer;
562  }
563  }
564 
565  /* ----------------- 9x family ------------------ */
566 
567  /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */
568  if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 950) {
569  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 95");
570  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1111) {
571  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 95 OSR2.x");
572 
573  /* no info about Win98 SP1.... */
574  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 1998) {
575  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 98");
576  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 2222) {
577  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 98 SE");
578 
579  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 90 && Ver.dwBuildNumber == 3000) {
580  snprintf(Buffer, sizeof(Buffer) - 1, "Windows ME");
581 
582  /* ---------------- NT family ------------------- */
583 
584  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1381) {
585  snprintf(Buffer, sizeof(Buffer) - 1, "Windows NT 4.0");
586 
587  } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 2195) {
588  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 2000");
589 
590  } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) {
591  snprintf(Buffer, sizeof(Buffer) - 1, "Windows XP");
592 #if _MSC_VER > 1200 /* 6.0 has it undeclared */
593  if (Extended) {
594  if (Ver.wSuiteMask & VER_SUITE_PERSONAL) {
595  snprintf(Buffer+strlen(Buffer), sizeof(Buffer) - 1 - strlen(Buffer)," Home");
596  } else {
597  snprintf(Buffer+strlen(Buffer), sizeof(Buffer) - 1 - strlen(Buffer)," Pro");
598  }
599  }
600 #endif
601 
602  } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) {
603  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 2003");
604 
605  } else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 0) {
606  snprintf(Buffer, sizeof(Buffer) - 1, "Windows Vista");
607 
608  } else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion > 0) {
609  snprintf(Buffer, sizeof(Buffer) - 1, "Windows Server 2007");
610 
611  } else {
612  snprintf(Buffer, sizeof(Buffer) - 1, "Windows %i.%i.%i",(int)Ver.dwMajorVersion,(int)Ver.dwMinorVersion,(int)Ver.dwBuildNumber);
613  }
614 
615  if (Extended && Ver.wServicePackMajor != 0) {
616  snprintf(Buffer+strlen(Buffer), sizeof(Buffer) - 1 - strlen(Buffer)," SP%i",Ver.wServicePackMajor);
617  }
618 #elif defined(HAVE_SYS_UTSNAME_H)
619  uname(&Ver);
620  snprintf(Buffer, sizeof(Buffer) - 1, "%s, kernel %s (%s)", Ver.sysname, Ver.release, Ver.version);
621 #elif defined(__FreeBSD__)
622  snprintf(Buffer, sizeof(Buffer) - 1, "FreeBSD");
623 #elif defined(__NetBSD__)
624  snprintf(Buffer, sizeof(Buffer) - 1, "NetBSD");
625 #elif defined(__OpenBSD__)
626  snprintf(Buffer, sizeof(Buffer) - 1, "OpenBSD");
627 #elif defined(__GNU__)
628  snprintf(Buffer, sizeof(Buffer) - 1, "GNU/Hurd");
629 #elif defined(sun) || defined(__sun) || defined(__sun__)
630 # ifdef __SVR4
631  snprintf(Buffer, sizeof(Buffer) - 1, "Sun Solaris");
632 # else
633  snprintf(Buffer, sizeof(Buffer) - 1, "SunOS");
634 # endif
635 #elif defined(hpux) || defined(__hpux) || defined(__hpux__)
636  snprintf(Buffer, sizeof(Buffer) - 1, "HP-UX");
637 #elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__)
638  snprintf(Buffer, sizeof(Buffer) - 1, "DEC Ultrix");
639 #elif defined(sgi) || defined(__sgi)
640  snprintf(Buffer, sizeof(Buffer) - 1, "SGI Irix");
641 #elif defined(__osf__)
642  snprintf(Buffer, sizeof(Buffer) - 1, "OSF Unix");
643 #elif defined(bsdi) || defined(__bsdi__)
644  snprintf(Buffer, sizeof(Buffer) - 1, "BSDI Unix");
645 #elif defined(_AIX)
646  snprintf(Buffer, sizeof(Buffer) - 1, "AIX Unix");
647 #elif defined(_UNIXWARE)
648  snprintf(Buffer, sizeof(Buffer) - 1, "SCO Unixware");
649 #elif defined(DGUX)
650  snprintf(Buffer, sizeof(Buffer) - 1, "DG Unix");
651 #elif defined(__QNX__)
652  snprintf(Buffer, sizeof(Buffer) - 1, "QNX");
653 #else
654  snprintf(Buffer, sizeof(Buffer) - 1, "unknown OS");
655 #endif
656  return Buffer;
657 }
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ GSM_InitLocales()

void GSM_InitLocales ( const char *  path)

Initializes locales. This sets up things needed for proper string conversion from local charset as well as initializes gettext based translation.

Parameters
pathPath to gettext translation. If NULL compiled in default is used.

§ GSM_IsNewerVersion()

gboolean GSM_IsNewerVersion ( const char *  latest_version,
const char *  current_version 
)

Returns TRUE if firmware version is newer.

Parameters
latest_versionString containing version (eg. latest available).
current_versionString containing version (eg. current one).
Returns
True if latest_version > current_version.

Definition at line 699 of file misc.c.

References FALSE, and TRUE.

700 {
701  size_t i;
702  size_t len = strlen(latest_version);
703 
704  for (i = 0; i < len ; i++) {
705  if (latest_version[i] > current_version[i]) {
706  return TRUE;
707  }
708  }
709 
710  return FALSE;
711 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ GSM_SetPower()

GSM_Error GSM_SetPower ( GSM_StateMachine s,
gboolean  on 
)

Set Power On/Off the phone

Parameters
sState machine pointer.
onTRUE to power on the phone, FALSE to power off
Returns
Error code.

Power on/off the phone.

Definition at line 307 of file api.c.

References CHECK_PHONE_CONNECTION, GSM_Phone::Functions, _GSM_StateMachine::Phone, PRINT_LOG_ERROR, and GSM_Phone_Functions::SetPower.

308 {
309  GSM_Error err;
310 
312 
313  err = s->Phone.Functions->SetPower(s, on);
314  PRINT_LOG_ERROR(err);
315  return err;
316 }
GSM_Error(* SetPower)(GSM_StateMachine *s, gboolean on)
Definition: gsmstate.h:1309
GSM_Error
Definition: gammu-error.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define PRINT_LOG_ERROR(err)
Definition: api.c:28
#define CHECK_PHONE_CONNECTION()
Definition: api.c:38
GSM_Phone_Functions * Functions
Definition: gsmstate.h:1373