Gammu internals  1.38.0
gsmphones.c File Reference
#include <gammu-config.h>
#include <gammu-info.h>
#include "gsmphones.h"
#include "gsmstate.h"
#include "debug.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "../helper/string.h"
Include dependency graph for gsmphones.c:

Go to the source code of this file.

Data Structures

struct  GSM_FeatureName
 

Macros

#define MAX_FEATURE_NAME_LEN   20
 

Functions

const char * GSM_FeatureToString (GSM_Feature feature)
 
GSM_Feature GSM_FeatureFromString (const char *feature)
 
GSM_Error GSM_SetFeatureString (GSM_Feature *list, const char *string)
 
GSM_PhoneModelGetModelData (GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
 
gboolean GSM_IsPhoneFeatureAvailable (GSM_PhoneModel *model, GSM_Feature feature)
 
gboolean GSM_AddPhoneFeature (GSM_PhoneModel *model, GSM_Feature feature)
 

Variables

GSM_FeatureName AllFeatureNames []
 
GSM_PhoneModel allmodels []
 

Detailed Description

Phone features database.

Definition in file gsmphones.c.

Macro Definition Documentation

§ MAX_FEATURE_NAME_LEN

#define MAX_FEATURE_NAME_LEN   20

Definition at line 24 of file gsmphones.c.

Function Documentation

§ GetModelData()

GSM_PhoneModel* GetModelData ( GSM_StateMachine s,
const char *  model,
const char *  number,
const char *  irdamodel 
)

Converts model string to model record record describing it's features. If state machine structure is provided, phone features can be overrided from current state machine configuration.

Parameters
sPointer to state machine structure, can be NULL.
modelModel name string, NULL if not to be searched.
numberModel number string, NULL if not to be searched.
irdamodelIrDA model name string, NULL if not to be searched.
Returns
Pointer to static structure containing phone information.

Definition at line 1002 of file gsmphones.c.

References _GSM_StateMachine::CurrentConfig, GSM_PhoneModel::features, GSM_MAX_PHONE_FEATURES, and GSM_Config::PhoneFeatures.

Referenced by GSM_InitConnection_Log(), GSM_RegisterAllPhoneModules(), GSM_RegisterModule(), and NOKIA_EncodeDateTime().

1003 {
1004  int i, j;
1005 
1006  /* Find model record if we have one */
1007  for (i = 0; strcmp(allmodels[i].number, "") != 0; i++) {
1008  if (model !=NULL && strcmp (model, allmodels[i].model) == 0)
1009  break;
1010  if (number !=NULL && strcmp (number, allmodels[i].number) == 0)
1011  break;
1012  if (irdamodel !=NULL && strcmp (irdamodel, allmodels[i].irdamodel) == 0)
1013  break;
1014  }
1015 
1016  /* Force user configured features */
1017  if (s != NULL && s->CurrentConfig != NULL && s->CurrentConfig->PhoneFeatures[0] != 0) {
1018  for (j = 0; j <= GSM_MAX_PHONE_FEATURES && s->CurrentConfig->PhoneFeatures[j] != 0; j++) {
1020  }
1021  }
1022 
1023  return (&allmodels[i]);
1024 }
GSM_Config * CurrentConfig
Definition: gsmstate.h:1415
GSM_PhoneModel allmodels[]
Definition: gsmphones.c:207
GSM_Feature PhoneFeatures[GSM_MAX_PHONE_FEATURES+1]
#define GSM_MAX_PHONE_FEATURES
Definition: gammu-limits.h:302
GSM_Feature features[GSM_MAX_PHONE_FEATURES+1]
Definition: gammu-info.h:776

§ GSM_SetFeatureString()

GSM_Error GSM_SetFeatureString ( GSM_Feature list,
const char *  string 
)

Converts string to list of features.

Parameters
listStorage where features will be stored, needs to be long enough (GSM_MAX_PHONE_FEATURES + 1).
stringString with features to be parsed, will be parsed using GSM_FeatureFromString.
Returns
Error code.

Definition at line 155 of file gsmphones.c.

References ERR_BADFEATURE, ERR_MOREMEMORY, ERR_NONE, ERR_UNKNOWN, GSM_FeatureFromString(), GSM_MAX_PHONE_FEATURES, and smfprintf().

Referenced by GSM_ReadConfig().

156 {
157  char *buffer, *pos, *end, *tmp;
158  int out = 0;
159  GSM_Error error = ERR_UNKNOWN;
160 
161  /* Working copy */
162  buffer = strdup(string);
163  if (buffer == NULL)
164  return ERR_MOREMEMORY;
165 
166  pos = buffer;
167  while (strlen(pos) > 0) {
168  end = strchr(pos, ',');
169  if (end != NULL) {
170  *end = 0;
171  }
172 
173  while (isspace(*pos))
174  pos++;
175 
176  while ((tmp = strchr(pos, ' ')) != NULL)
177  *tmp = 0;
178 
179  list[out] = GSM_FeatureFromString(pos);
180  if (list[out] == 0) {
181  smfprintf(NULL, "Bad feature string: %s\n", pos);
182  error = ERR_BADFEATURE;
183  break;
184  }
185  out++;
186  if (out >= GSM_MAX_PHONE_FEATURES) {
187  smfprintf(NULL, "Too many features: %s\n", pos);
188  error = ERR_MOREMEMORY;
189  break;
190  }
191  if (end != NULL) {
192  pos = end + 1;
193  } else {
194  /* We're done */
195  error = ERR_NONE;
196  break;
197  }
198  }
199  free(buffer);
200  buffer=NULL;
201  return error;
202 }
GSM_Error
Definition: gammu-error.h:23
GSM_Feature GSM_FeatureFromString(const char *feature)
Definition: gsmphones.c:145
#define GSM_MAX_PHONE_FEATURES
Definition: gammu-limits.h:302
int smfprintf(GSM_Debug_Info *d, const char *format,...)
Definition: debug.c:240

Variable Documentation

§ AllFeatureNames

GSM_FeatureName AllFeatureNames[]

Definition at line 31 of file gsmphones.c.

§ allmodels

GSM_PhoneModel allmodels[]

Flags needed for various phone models.

Definition at line 207 of file gsmphones.c.