summaryrefslogtreecommitdiff
path: root/libgammu/gsmstate.c
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2009-12-22 10:29:43 +0100
committerMichal Čihař <michal@cihar.com>2009-12-22 10:29:43 +0100
commitdb82aad8331a0e9aa7760091b781a2d5ede9f5fc (patch)
tree728bc9f271052184b7f5f1fd78a59fee7b47af3f /libgammu/gsmstate.c
parent7e547c4531756f1a265607a666e30b714bb4f066 (diff)
Imported Upstream version 1.27.0
Diffstat (limited to 'libgammu/gsmstate.c')
-rw-r--r--libgammu/gsmstate.c127
1 files changed, 62 insertions, 65 deletions
diff --git a/libgammu/gsmstate.c b/libgammu/gsmstate.c
index 14ecd9e..5662680 100644
--- a/libgammu/gsmstate.c
+++ b/libgammu/gsmstate.c
@@ -60,9 +60,21 @@ static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection,
}
}
+/**
+ * Information about connection names and parameters.
+ */
typedef struct {
+ /**
+ * Name of the connection used in config file.
+ */
const char *Name;
+ /**
+ * Connection type.
+ */
const GSM_ConnectionType Connection;
+ /**
+ * Whether to disable DTR/RTS handling on this connection.
+ */
gboolean SkipDtrRts;
} GSM_ConnectionInfo;
@@ -195,7 +207,7 @@ static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, const char *con
/* Free allocated memory */
free(buff);
- buff=NULL;
+ buff = NULL;
if (s->ConnectionType == 0) {
return ERR_UNKNOWNCONNECTIONTYPESTRING;
@@ -409,12 +421,12 @@ GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
#endif
if (model->model[0] == 0) return ERR_UNKNOWNMODELSTRING;
}
- s->Phone.Functions=NULL;
+ s->Phone.Functions = NULL;
#ifdef GSM_ENABLE_ATGEN
/* AT module can have the same models ID to "normal" Nokia modules */
if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT || s->ConnectionType==GCT_DKU2AT) {
GSM_RegisterModule(s,&ATGENPhone);
- if (s->Phone.Functions!=NULL) return ERR_NONE;
+ if (s->Phone.Functions != NULL) return ERR_NONE;
}
#endif
GSM_RegisterModule(s, &DUMMYPhone);
@@ -465,7 +477,7 @@ GSM_Error GSM_OpenConnection(GSM_StateMachine *s)
{
GSM_Error error;
- if (s->CurrentConfig->LockDevice != NULL && strcasecmp(s->CurrentConfig->LockDevice,"yes") == 0) {
+ if (s->CurrentConfig->LockDevice) {
error = lock_device(s, s->CurrentConfig->Device, &(s->LockFile));
if (error != ERR_NONE) return error;
}
@@ -494,16 +506,22 @@ GSM_Error GSM_CloseConnection(GSM_StateMachine *s)
{
GSM_Error error;
- smprintf(s,"[Closing]\n");
+ smprintf(s, "[Closing]\n");
- error=s->Protocol.Functions->Terminate(s);
- if (error!=ERR_NONE) return error;
+ /* Terminate protocol */
+ error = s->Protocol.Functions->Terminate(s);
+ if (error != ERR_NONE) return error;
+ /* Close the device */
error = s->Device.Functions->CloseDevice(s);
- if (error!=ERR_NONE) return error;
+ if (error != ERR_NONE) return error;
- if (s->LockFile!=NULL) unlock_device(s, &(s->LockFile));
+ /* Release lock if there was any */
+ if (s->LockFile != NULL) {
+ unlock_device(s, &(s->LockFile));
+ }
+ /* Null all structures in case we will be asked for new initialisation */
s->Phone.Data.ModelInfo = NULL;
s->Phone.Data.Manufacturer[0] = 0;
s->Phone.Data.Model[0] = 0;
@@ -572,18 +590,22 @@ GSM_Error GSM_TryGetModel(GSM_StateMachine *s)
default:
s->Phone.Functions = NULL;
}
- if (s->Phone.Functions == NULL) return ERR_UNKNOWN;
+ /* Did we find matching phone driver? */
+ if (s->Phone.Functions == NULL) {
+ smprintf(s, "ERROR: Could not find proper module for autodetection!\n");
+ return ERR_UNKNOWN;
+ }
- /* Please note, that AT module need to send first
- * command for enabling echo
- */
- error=s->Phone.Functions->Initialise(s);
+ /* Initialize the phone driver */
+ error = s->Phone.Functions->Initialise(s);
if (error != ERR_NONE) return error;
- error=s->Phone.Functions->GetModel(s);
+ /* Get model name from phone */
+ error = s->Phone.Functions->GetModel(s);
if (error != ERR_NONE) return error;
- error=s->Phone.Functions->Terminate(s);
+ /* And terminate it again */
+ error = s->Phone.Functions->Terminate(s);
if (error != ERR_NONE) return error;
}
return ERR_NONE;
@@ -741,12 +763,12 @@ autodetect:
return error;
}
- if (strcasecmp(s->CurrentConfig->StartInfo,"yes") == 0) {
+ if (s->CurrentConfig->StartInfo) {
s->Phone.Functions->ShowStartInfo(s,TRUE);
s->Phone.Data.StartInfoCounter = 30;
}
- if (strcasecmp(s->CurrentConfig->SyncTime,"yes") == 0) {
+ if (s->CurrentConfig->SyncTime) {
GSM_GetCurrentDateTime (&current_time);
s->Phone.Functions->SetDateTime(s,&current_time);
}
@@ -823,7 +845,7 @@ GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
smprintf(s,"[Terminating]\n");
- if (strcasecmp(s->CurrentConfig->StartInfo,"yes") == 0) {
+ if (s->CurrentConfig->StartInfo) {
if (s->Phone.Data.StartInfoCounter > 0) s->Phone.Functions->ShowStartInfo(s,FALSE);
}
@@ -871,8 +893,8 @@ GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned const char *buffer,
if (length != 0) {
free(sentmsg.Buffer);
- sentmsg.Buffer=NULL;
- Phone->SentMsg=NULL;
+ sentmsg.Buffer = NULL;
+ Phone->SentMsg = NULL;
}
/* Request completed */
@@ -893,7 +915,7 @@ GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned const char *buffer,
GSM_Error error;
int reply;
- if (strcasecmp(s->CurrentConfig->StartInfo,"yes") == 0) {
+ if (s->CurrentConfig->StartInfo) {
if (Phone->StartInfoCounter > 0) {
Phone->StartInfoCounter--;
if (Phone->StartInfoCounter == 0) s->Phone.Functions->ShowStartInfo(s,FALSE);
@@ -977,7 +999,7 @@ GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
GSM_DumpMessageLevel3Recv(s, msg->Buffer, msg->Length, msg->Type);
Reply=s->User.UserReplyFunctions;
- if (Reply!=NULL) error=CheckReplyFunctions(s,Reply,&reply);
+ if (Reply != NULL) error=CheckReplyFunctions(s,Reply,&reply);
if (error==ERR_UNKNOWNFRAME) {
Reply=s->Phone.Functions->ReplyFunctions;
@@ -1124,7 +1146,7 @@ void GSM_SetConfigNum(GSM_StateMachine *s, int sections)
*/
void GSM_ExpandUserPath(char **string)
{
- char *tmp=NULL, *home=NULL;
+ char *tmp = NULL, *home = NULL;
/* Is there something to expand */
if (*string[0] != '~') return;
@@ -1151,7 +1173,7 @@ GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
INI_Section *h;
unsigned char section[50]={0};
gboolean found = FALSE;
- char *Temp=NULL;
+ char *Temp = NULL;
#if defined(WIN32) || defined(DJGPP)
static const char *DefaultPort = "com2:";
@@ -1160,11 +1182,11 @@ GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
#endif
static const char *DefaultModel = "";
static const char *DefaultConnection = "fbus";
- static const char *DefaultSynchronizeTime = "no";
+ static gboolean DefaultSynchronizeTime = FALSE;
static const char *DefaultDebugFile = "";
static const char *DefaultDebugLevel = "";
- static const char *DefaultLockDevice = "no";
- static const char *DefaultStartInfo = "no";
+ static gboolean DefaultLockDevice = FALSE;
+ static gboolean DefaultStartInfo = FALSE;
/* By default all debug output will go to one filedescriptor */
static const gboolean DefaultUseGlobalDebugFile = TRUE;
@@ -1173,7 +1195,7 @@ GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
cfg->UseGlobalDebugFile = DefaultUseGlobalDebugFile;
/* If we don't have valid config, bail out */
- if (cfg_info==NULL) {
+ if (cfg_info == NULL) {
error = ERR_UNCONFIGURED;
goto fail;
}
@@ -1216,13 +1238,7 @@ GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
}
/* Set time sync */
- free(cfg->SyncTime);
- cfg->SyncTime = INI_GetValue(cfg_info, section, "synchronizetime", FALSE);
- if (cfg->SyncTime == NULL) {
- cfg->SyncTime = strdup(DefaultSynchronizeTime);
- } else {
- cfg->SyncTime = strdup(cfg->SyncTime);
- }
+ cfg->SyncTime = INI_GetBool(cfg_info, section, "synchronizetime", DefaultSynchronizeTime);
/* Set debug file */
free(cfg->DebugFile);
@@ -1235,13 +1251,7 @@ GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
}
/* Set file locking */
- free(cfg->LockDevice);
- cfg->LockDevice = INI_GetValue(cfg_info, section, "use_locking", FALSE);
- if (cfg->LockDevice == NULL) {
- cfg->LockDevice = strdup(DefaultLockDevice);
- } else {
- cfg->LockDevice = strdup(cfg->LockDevice);
- }
+ cfg->LockDevice = INI_GetBool(cfg_info, section, "use_locking", DefaultLockDevice);
/* Set model */
Temp = INI_GetValue(cfg_info, section, "model", FALSE);
@@ -1265,14 +1275,7 @@ GSM_Error GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
}
/* Set startup info */
- free(cfg->StartInfo);
- cfg->StartInfo = INI_GetValue(cfg_info, section, "startinfo", FALSE);
-
- if (cfg->StartInfo == NULL) {
- cfg->StartInfo = strdup(DefaultStartInfo);
- } else {
- cfg->StartInfo = strdup(cfg->StartInfo);
- }
+ cfg->StartInfo = INI_GetBool(cfg_info, section, "startinfo", DefaultStartInfo);
/* Read localised strings for some phones */
@@ -1345,12 +1348,12 @@ fail:
if (num == 0) {
cfg->Device = strdup(DefaultPort);
cfg->Connection = strdup(DefaultConnection);
- cfg->SyncTime = strdup(DefaultSynchronizeTime);
+ cfg->SyncTime = DefaultSynchronizeTime;
cfg->DebugFile = strdup(DefaultDebugFile);
- cfg->LockDevice = strdup(DefaultLockDevice);
+ cfg->LockDevice = DefaultLockDevice;
strcpy(cfg->Model,DefaultModel);
strcpy(cfg->DebugLevel,DefaultDebugLevel);
- cfg->StartInfo = strdup(DefaultStartInfo);
+ cfg->StartInfo = DefaultStartInfo;
strcpy(cfg->TextReminder,"Reminder");
strcpy(cfg->TextMeeting,"Meeting");
strcpy(cfg->TextCall,"Call");
@@ -1422,7 +1425,7 @@ void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
{
#ifdef WIN32
int i=0;
- unsigned char *lpMsgBuf=NULL;
+ unsigned char *lpMsgBuf = NULL;
#endif
GSM_Debug_Info *curdi;
@@ -1599,20 +1602,14 @@ void GSM_FreeStateMachine(GSM_StateMachine *s)
/* Free allocated memory */
for (i = 0; i <= MAX_CONFIG_NUM; i++) {
free(s->Config[i].Device);
- s->Config[i].Device=NULL;
+ s->Config[i].Device = NULL;
free(s->Config[i].Connection);
- s->Config[i].Connection=NULL;
- free(s->Config[i].SyncTime);
- s->Config[i].SyncTime=NULL;
+ s->Config[i].Connection = NULL;
free(s->Config[i].DebugFile);
- s->Config[i].DebugFile=NULL;
- free(s->Config[i].LockDevice);
- s->Config[i].LockDevice=NULL;
- free(s->Config[i].StartInfo);
- s->Config[i].StartInfo=NULL;
+ s->Config[i].DebugFile = NULL;
}
free(s);
- s=NULL;
+ s = NULL;
}