Gammu internals  1.38.0
gsmpbk.c File Reference
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <gammu-misc.h>
#include <gammu-bitmap.h>
#include "../misc/coding/coding.h"
#include "../debug.h"
#include "gsmpbk.h"
#include "gsmmisc.h"
Include dependency graph for gsmpbk.c:

Go to the source code of this file.

Macros

#define CHECK_NUM_ENTRIES
 

Functions

GSM_MemoryType GSM_StringToMemoryType (const char *s)
 
unsigned char * GSM_PhonebookGetEntryName (const GSM_MemoryEntry *entry)
 
void GSM_PhonebookFindDefaultNameNumberGroup (const GSM_MemoryEntry *entry, int *Name, int *Number, int *Group)
 
GSM_Error GSM_EncodeVCARD (GSM_Debug_Info *di, char *Buffer, const size_t buff_len, size_t *Length, GSM_MemoryEntry *pbk, const gboolean header, const GSM_VCardVersion Version)
 
void GSM_TweakInternationalNumber (unsigned char *Number, const GSM_NumberType numType)
 
GSM_Error GSM_DecodeVCARD (GSM_Debug_Info *di, char *Buffer, size_t *Pos, GSM_MemoryEntry *Pbk, GSM_VCardVersion Version)
 
void GSM_FreeMemoryEntry (GSM_MemoryEntry *Entry)
 

Macro Definition Documentation

§ CHECK_NUM_ENTRIES

#define CHECK_NUM_ENTRIES
Value:
{ \
if (Pbk->EntriesNum >= GSM_PHONEBOOK_ENTRIES) { error = ERR_MOREMEMORY; goto vcard_done; } \
Pbk->Entries[Pbk->EntriesNum].AddError = ERR_NONE; \
}
#define GSM_PHONEBOOK_ENTRIES
Definition: gammu-limits.h:98

Definition at line 669 of file gsmpbk.c.

Referenced by GSM_DecodeVCARD().

Function Documentation

§ GSM_FreeMemoryEntry()

void GSM_FreeMemoryEntry ( GSM_MemoryEntry Entry)

Frees any dynamically allocated memory inside memory entry structure.

Parameters
[in]EntryPointer to memory entry to process.

Definition at line 1089 of file gsmpbk.c.

References GSM_BinaryPicture::Buffer, GSM_MemoryEntry::Entries, GSM_MemoryEntry::EntriesNum, GSM_SubMemoryEntry::EntryType, GSM_BinaryPicture::Length, PBK_Photo, and GSM_SubMemoryEntry::Picture.

1090 {
1091  int i;
1092 
1093  for (i = 0; i < Entry->EntriesNum; i++) {
1094  switch (Entry->Entries[i].EntryType) {
1095  case PBK_Photo:
1096  free(Entry->Entries[i].Picture.Buffer);
1097  Entry->Entries[i].Picture.Buffer = NULL;
1098  Entry->Entries[i].Picture.Length = 0;
1099  break;
1100  default:
1101  break;
1102  }
1103  }
1104 }
unsigned char * Buffer
Definition: gammu-bitmap.h:45
GSM_BinaryPicture Picture
Definition: gammu-memory.h:403
GSM_EntryType EntryType
Definition: gammu-memory.h:372
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]
Definition: gammu-memory.h:427

§ GSM_StringToMemoryType()

GSM_MemoryType GSM_StringToMemoryType ( const char *  s)

Converts memory type from string.

Parameters
sString with memory type.
Returns
Parsed memory type or 0 on failure.

Definition at line 16 of file gsmpbk.c.

References MEM_DC, MEM_FD, MEM_MC, MEM_ME, MEM_MT, MEM_ON, MEM_QD, MEM_RC, MEM_SL, MEM_SM, and MEM_VM.

Referenced by GSM_DecodeVCARD().

16  {
17  if (strcmp(s, "ME") == 0) return MEM_ME;
18  else if (strcmp(s, "SM") == 0) return MEM_SM;
19  else if (strcmp(s, "ON") == 0) return MEM_ON;
20  else if (strcmp(s, "DC") == 0) return MEM_DC;
21  else if (strcmp(s, "RC") == 0) return MEM_RC;
22  else if (strcmp(s, "MC") == 0) return MEM_MC;
23  else if (strcmp(s, "MT") == 0) return MEM_MT;
24  else if (strcmp(s, "FD") == 0) return MEM_FD;
25  else if (strcmp(s, "VM") == 0) return MEM_VM;
26  else if (strcmp(s, "SL") == 0) return MEM_SL;
27  else if (strcmp(s, "QD") == 0) return MEM_QD;
28  else {
29  return 0;
30  }
31 }

§ GSM_TweakInternationalNumber()

void GSM_TweakInternationalNumber ( unsigned char *  Number,
const GSM_NumberType  numType 
)

Definition at line 620 of file gsmpbk.c.

References DecodeUnicodeString(), EncodeUnicode(), and NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN.

Referenced by GSM_DecodeVCARD().

621 {
622  /* Checks if International number needs to be corrected */
623  char* pos; /* current position in the buffer */
624  char buf[500]; /* Taken from DecodeUnicodeString(). How to get length of the encoded unicode string? There may be embedded 0s. */
625 
627  sprintf(buf+1,"%s",DecodeUnicodeString(Number)); /* leave 1 free char before the number, we'll need it */
628  /* International number may be without + (e.g. (Sony)Ericsson)
629  we can add it, but must handle numbers in the form:
630  NNNNNN N - any digit (char)
631  *code#NNNNNN any number of Ns
632  *[*]code*NNNNNN[...]
633  other combinations (like *code1*code2*number#)
634  will have to be added if found in real life
635  Or does somebody know the exact allowed syntax
636  from some standard?
637  */
638  pos=buf+1;
639  if (*pos=='*') { /* Code? Skip it. */
640  /* probably with code */
641  while (*pos=='*') { /* skip leading asterisks */
642  *(pos-1)=*pos; /* shift the chars by one */
643  pos++;
644  }
645  while ((*pos!='*')&&(*pos!='#')) { /* skip code - anything except * or # */
646  *(pos-1)=*pos;
647  pos++;
648  }
649  *(pos-1)=*pos; /* shift the last delimiter */
650  pos++;
651  }
652  /* check the guessed location, if + is correctly there */
653  if (*pos=='+') {
654  /* yes, just shift the rest of the string */
655  while (*pos) {
656  *(pos-1) = *pos;
657  pos++;
658  }
659  *(pos-1)=0; /* kill the last char, which now got doubled */
660  } else {
661  /* no, insert + and exit, no more shifting */
662  *(pos-1)='+';
663  }
664  EncodeUnicode(Number,buf,strlen(buf));
665  }
666 }
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301