Gammu internals  1.38.0
gsmpbk.h File Reference
#include <stdlib.h>
#include <gammu-memory.h>
#include "../misc/coding/coding.h"
Include dependency graph for gsmpbk.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

Function Documentation

§ 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