Gammu internals  1.38.0
gsmcomon.c
Go to the documentation of this file.
1 /* (c) 2002-2005 by Marcin Wiacek & Michal Cihar */
2 
3 #include <ctype.h>
4 #include <string.h>
5 #include <time.h>
6 #include <stdio.h>
7 #ifdef HAVE_WCHAR_H
8 # include <wchar.h>
9 #endif
10 #ifdef WIN32
11 # define WIN32_LEAN_AND_MEAN
12 # include <windows.h>
13 #endif
14 
15 #include "misc/locales.h"
16 
17 #include "debug.h"
18 
19 #include <gammu-debug.h>
20 
21 #include "gsmcomon.h"
22 
24 {
25  return ERR_NONE;
26 }
27 
29 {
30  return ERR_NOTIMPLEMENTED;
31 }
32 
34 {
35  return ERR_NOTSUPPORTED;
36 }
37 
43 #ifdef LIBINTL_LIB_FOUND
44 void GSM_InitLocales(const char *path) {
45  setlocale(LC_ALL, "");
46  if (path == NULL || strlen(path) == 0) {
47 #if defined(LOCALE_PATH)
48  bindtextdomain("libgammu", LOCALE_PATH);
49 #else
50  bindtextdomain("libgammu", ".");
51 #endif
52  } else {
53  bindtextdomain("libgammu", path);
54  }
55 }
56 #else
57 void GSM_InitLocales(const char UNUSED *path) {
58  setlocale(LC_ALL, "");
59 }
60 #endif
61 
65 typedef struct {
73  const char *ErrorName;
77  const char *ErrorText;
79 
84  {ERR_NONE, "NONE", N_("No error.")},
85  {ERR_DEVICEOPENERROR, "DEVICEOPENERROR", N_("Error opening device. Unknown, busy or no permissions.")},
86  {ERR_DEVICELOCKED, "DEVICELOCKED", N_("Error opening device, it is locked.")},
87  {ERR_DEVICENOTEXIST, "DEVICENOTEXIST", N_("Error opening device, it doesn't exist.")},
88  {ERR_DEVICEBUSY, "DEVICEBUSY", N_("Error opening device, it is already opened by other application.")},
89  {ERR_DEVICENOPERMISSION, "DEVICENOPERMISSION", N_("Error opening device, you don't have permissions.")},
90  {ERR_DEVICENODRIVER, "DEVICENODRIVER", N_("Error opening device. No required driver in operating system.")},
91  {ERR_DEVICENOTWORK, "DEVICENOTWORK", N_("Error opening device. Some hardware not connected/wrongly configured.")},
92  {ERR_DEVICEDTRRTSERROR, "DEVICEDTRRTSERROR", N_("Error setting device DTR or RTS.")},
93  {ERR_DEVICECHANGESPEEDERROR, "DEVICECHANGESPEEDERROR", N_("Error setting device speed. Maybe speed not supported.")},
94  {ERR_DEVICEWRITEERROR, "DEVICEWRITEERROR", N_("Error writing to the device.")},
95  {ERR_DEVICEREADERROR, "DEVICEREADERROR", N_("Error during reading from the device.")},
96  {ERR_DEVICEPARITYERROR, "DEVICEPARITYERROR", N_("Can't set parity on the device.")},
97  {ERR_TIMEOUT, "TIMEOUT", N_("No response in specified timeout. Probably phone not connected.")},
98  {ERR_FRAMENOTREQUESTED, "FRAMENOTREQUESTED", N_("Frame not requested right now. See <https://wammu.eu/support/bugs/> for information how to report it.")},
99  {ERR_UNKNOWNRESPONSE, "UNKNOWNRESPONSE", N_("Unknown response from phone. See <https://wammu.eu/support/bugs/> for information how to report it.")},
100  {ERR_UNKNOWNFRAME, "UNKNOWNFRAME", N_("Unknown frame. See <https://wammu.eu/support/bugs/> for information how to report it.")},
101  {ERR_UNKNOWNCONNECTIONTYPESTRING, "UNKNOWNCONNECTIONTYPESTRING",N_("Unknown connection type string. Check config file.")},
102  {ERR_UNKNOWNMODELSTRING, "UNKNOWNMODELSTRING", N_("Unknown model type string. Check config file.")},
103  {ERR_SOURCENOTAVAILABLE, "SOURCENOTAVAILABLE", N_("Some functions not available for your system (disabled in config or not implemented).")},
104  {ERR_NOTSUPPORTED, "NOTSUPPORTED", N_("Function not supported by phone.")},
105  {ERR_EMPTY, "EMPTY", N_("Entry is empty.")},
106  {ERR_SECURITYERROR, "SECURITYERROR", N_("Security error. Maybe no PIN?")},
107  {ERR_INVALIDLOCATION, "INVALIDLOCATION", N_("Invalid location. Maybe too high?")},
108  {ERR_NOTIMPLEMENTED, "NOTIMPLEMENTED", N_("Functionality not implemented. You are welcome to help authors with it.")},
109  {ERR_FULL, "FULL", N_("Memory full.")},
110  {ERR_UNKNOWN, "UNKNOWN", N_("Unknown error.")},
111  {ERR_CANTOPENFILE, "CANTOPENFILE", N_("Can not open specified file.")},
112  {ERR_MOREMEMORY, "MOREMEMORY", N_("More memory required...")},
113  {ERR_PERMISSION, "PERMISSION", N_("Operation not allowed by phone.")},
114  {ERR_EMPTYSMSC, "EMPTYSMSC", N_("No SMSC number given. Provide it manually or use the one configured in phone.")},
115  {ERR_INSIDEPHONEMENU, "INSIDEPHONEMENU", N_("You're inside phone menu (maybe editing?). Leave it and try again.")},
116  {ERR_NOTCONNECTED, "NOTCONNECTED", N_("Phone is not connected.")},
117  {ERR_WORKINPROGRESS, "WORKINPROGRESS", N_("Function is currently being implemented. If you want to help, please contact authors.")},
118  {ERR_PHONEOFF, "PHONEOFF", N_("Phone is disabled and connected to charger.")},
119  {ERR_FILENOTSUPPORTED, "FILENOTSUPPORTED", N_("File format not supported by Gammu.")},
120  {ERR_BUG, "BUG", N_("Nobody is perfect, some bug appeared in protocol implementation. Please contact authors.")},
121  {ERR_CANCELED, "CANCELED", N_("Transfer was canceled by phone, maybe you pressed cancel on phone.")},
122  {ERR_NEEDANOTHERANSWER, "NEEDANOTHERANSWER", N_("Phone module need to send another answer frame.")}, /* This should be only internal. */
123  {ERR_OTHERCONNECTIONREQUIRED, "OTHERCONNECTIONREQUIRED", N_("Current connection type doesn't support called function.")},
124  {ERR_WRONGCRC, "WRONGCRC", N_("CRC error.")},
125  {ERR_INVALIDDATETIME, "INVALIDDATETIME", N_("Invalid date or time specified.")},
126  {ERR_MEMORY, "MEMORY", N_("Phone memory error, maybe it is read only.")},
127  {ERR_INVALIDDATA, "INVALIDDATA", N_("Invalid data given to phone.")},
128  {ERR_FILEALREADYEXIST, "FILEALREADYEXIST", N_("File with specified name already exists.")},
129  {ERR_FILENOTEXIST, "FILENOTEXIST", N_("File with specified name doesn't exist.")},
130  {ERR_SHOULDBEFOLDER, "SHOULDBEFOLDER", N_("You have to give folder name and not file name.")},
131  {ERR_SHOULDBEFILE, "SHOULDBEFILE", N_("You have to give file name and not folder name.")},
132  {ERR_NOSIM, "NOSIM", N_("Can not access SIM card.")},
133  {ERR_GNAPPLETWRONG, "GNAPPLETWRONG", N_("Wrong GNAPPLET version in phone. Use version from currently used Gammu.")},
134  {ERR_FOLDERPART, "FOLDERPART", N_("Only part of folder has been listed.")},
135  {ERR_FOLDERNOTEMPTY, "FOLDERNOTEMPTY", N_("Folder must be empty.")},
136  {ERR_DATACONVERTED, "DATACONVERTED", N_("Data were converted.")},
137  {ERR_UNCONFIGURED, "UNCONFIGURED", N_("Gammu is not configured.")},
138  {ERR_WRONGFOLDER, "WRONGFOLDER", N_("Wrong folder used.")},
139  {ERR_PHONE_INTERNAL, "PHONE_INTERNAL", N_("Internal phone error.")},
140  {ERR_WRITING_FILE, "WRITING_FILE", N_("Error writing file to disk.")},
141  {ERR_NONE_SECTION, "NONE_SECTION", N_("No such section exists.")},
142  {ERR_USING_DEFAULTS, "USING_DEFAULTS", N_("Using default values.")},
143  {ERR_CORRUPTED, "CORRUPTED", N_("Corrupted data returned by phone.")},
144  {ERR_BADFEATURE, "BADFEATURE", N_("Bad feature string in configuration.")},
145  {ERR_DISABLED, "DISABLED", N_("Desired functionality has been disabled on compile time.")},
146  {ERR_SPECIFYCHANNEL, "SPECIFYCHANNEL", N_("Bluetooth configuration requires channel option.")},
147  {ERR_NOTRUNNING, "NOTRUNNING", N_("Service is not running.")},
148  {ERR_NOSERVICE, "NOSERVICE", N_("Service configuration is missing.")},
149  {ERR_BUSY, "BUSY", N_("Command rejected because device was busy. Wait and restart.")},
150  {ERR_COULDNT_CONNECT, "COULDNT_CONNECT", N_("Could not connect to the server.")},
151  {ERR_COULDNT_RESOLVE, "COULDNT_RESOLVE", N_("Could not resolve the host name.")},
152  {ERR_GETTING_SMSC, "GETTING_SMSC", N_("Failed to get SMSC number from phone.")},
153  {ERR_ABORTED, "ABORTED", N_("Operation aborted.")},
154  {ERR_INSTALL_NOT_FOUND, "INSTALL_NOT_FOUND", N_("Installation data not found, please consult debug log and/or documentation for more details.")},
155  {ERR_READ_ONLY, "READ_ONLY", N_("Entry is read only.")},
156  {ERR_NETWORK_ERROR, "NETWORK_ERROR", N_("Network error.")},
157  {ERR_DB_VERSION, "DB_VERSION", N_("Invalid database version.")},
158  {ERR_DB_DRIVER, "DB_DRIVER", N_("Failed to initialize DB driver.")},
159  {ERR_DB_CONFIG, "DB_CONFIG", N_("Failed to configure DB driver.")},
160  {ERR_DB_CONNECT, "DB_CONNECT", N_("Failed to connect to database.")},
161  {ERR_DB_TIMEOUT, "DB_TIMEOUT", N_("Database connection timeout.")},
162  {ERR_SQL, "SQL", N_("Error in executing SQL query.")},
163 
164  {0, "", ""}
165 };
166 
167 const char *GSM_ErrorName(GSM_Error e)
168 {
169  const char *def = NULL;
170  int i = 0;
171 
172  while (PrintErrorEntries[i].ErrorNum != 0) {
173  if (PrintErrorEntries[i].ErrorNum == e) {
174  def = PrintErrorEntries[i].ErrorName;
175  break;
176  }
177  i++;
178  }
179 
180  return def;
181 }
182 
184 {
185  const char *def = NULL;
186  int i = 0;
187 
188  while (PrintErrorEntries[i].ErrorNum != 0) {
189  if (PrintErrorEntries[i].ErrorNum == e) {
190  def = PrintErrorEntries[i].ErrorText;
191  break;
192  }
193  i++;
194  }
195  if (def == NULL) def = N_("Unknown error description.");
196 
197  return dgettext("libgammu", def);
198 }
199 
200 const char *GetGammuLocalePath(void)
201 {
202 #ifdef LOCALE_PATH
203  static const char Buffer[] = LOCALE_PATH;
204  return Buffer;
205 #else
206  return NULL;
207 #endif
208 }
209 
210 const char *GetGammuVersion(void)
211 {
212  static const char Buffer[] = GAMMU_VERSION;
213  return Buffer;
214 }
215 
217 {
218  return &GSM_global_debug;
219 }
220 
221 void GSM_LogError(GSM_StateMachine * s, const char * message, const GSM_Error err) {
222  if (err != ERR_NONE) {
223  smprintf(s, "%s failed with error %s[%d]: %s\n", message,
224  GSM_ErrorName(err), err,
225  GSM_ErrorString(err));
226  }
227 }
228 
229 /* How should editor hadle tabs in this file? Add editor commands here.
230  * vim: noexpandtab sw=8 ts=8 sts=8:
231  */
#define GAMMU_VERSION
Definition: gammu-config.h:7
const char * ErrorName
Definition: gsmcomon.c:73
GSM_Error
Definition: gammu-error.h:23
#define dgettext(d, x)
Definition: locales.h:22
const char * GSM_ErrorName(GSM_Error e)
Definition: gsmcomon.c:167
GSM_Error NotImplementedFunction(void)
Definition: gsmcomon.c:28
GSM_Error ErrorNum
Definition: gsmcomon.c:69
GSM_Error NotSupportedFunction(void)
Definition: gsmcomon.c:33
#define LOCALE_PATH
Definition: gammu-config.h:377
const char * ErrorText
Definition: gsmcomon.c:77
GSM_Debug_Info GSM_global_debug
Definition: debug.c:33
const char * GSM_ErrorString(GSM_Error e)
Definition: gsmcomon.c:183
static PrintErrorEntry PrintErrorEntries[]
Definition: gsmcomon.c:83
const char * GetGammuLocalePath(void)
Definition: gsmcomon.c:200
void GSM_LogError(GSM_StateMachine *s, const char *message, const GSM_Error err)
Definition: gsmcomon.c:221
GSM_Debug_Info * GSM_GetGlobalDebug()
Definition: gsmcomon.c:216
GSM_Error NoneFunction(void)
Definition: gsmcomon.c:23
const char * GetGammuVersion(void)
Definition: gsmcomon.c:210
#define N_(x)
Definition: locales.h:26
void GSM_InitLocales(const char UNUSED *path)
Definition: gsmcomon.c:57
#define UNUSED
Definition: gammu-misc.h:105
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261