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
NoneFunction(void)23 GSM_Error NoneFunction(void)
24 {
25 return ERR_NONE;
26 }
27
NotImplementedFunction(void)28 GSM_Error NotImplementedFunction(void)
29 {
30 return ERR_NOTIMPLEMENTED;
31 }
32
NotSupportedFunction(void)33 GSM_Error NotSupportedFunction(void)
34 {
35 return ERR_NOTSUPPORTED;
36 }
37
38 /**
39 * Initializes locales from given path or from system default.
40 *
41 * @param path Optional path to locales, can be NULL.
42 */
43 #ifdef LIBINTL_LIB_FOUND
GSM_InitLocales(const char * path)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
GSM_InitLocales(const char UNUSED * path)57 void GSM_InitLocales(const char UNUSED *path) {
58 setlocale(LC_ALL, "");
59 }
60 #endif
61
62 /**
63 * Gammu errors descriptions.
64 */
65 typedef struct {
66 /**
67 * Error code.
68 */
69 GSM_Error ErrorNum;
70 /**
71 * Name of error.
72 */
73 const char *ErrorName;
74 /**
75 * Textual representation, not localised, use gettext to get localised string.
76 */
77 const char *ErrorText;
78 } PrintErrorEntry;
79
80 /**
81 * Mapping of error numbers to descriptions.
82 */
83 static PrintErrorEntry PrintErrorEntries[] = {
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 another app.")},
89 {ERR_DEVICENOPERMISSION, "DEVICENOPERMISSION", N_("Error opening device, you don't have the required permission.")},
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 the speed is 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 the phone is not connected.")},
98 {ERR_FRAMENOTREQUESTED, "FRAMENOTREQUESTED", N_("Frame not requested right now. See <https://wammu.eu/support/bugs/> for information on how to report it.")},
99 {ERR_UNKNOWNRESPONSE, "UNKNOWNRESPONSE", N_("Unknown response from phone. See <https://wammu.eu/support/bugs/> for information on how to report it.")},
100 {ERR_UNKNOWNFRAME, "UNKNOWNFRAME", N_("Unknown frame. See <https://wammu.eu/support/bugs/> for information on 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 are 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_("Empty entry.")},
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.")},
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 on the phone.")},
115 {ERR_INSIDEPHONEMENU, "INSIDEPHONEMENU", N_("You're inside the phone menu (maybe editing?). Exit it and try again.")},
116 {ERR_NOTCONNECTED, "NOTCONNECTED", N_("Phone 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 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 canceled by phone, maybe you pressed \"Cancel\" on the 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 supply folder name and not filename.")},
131 {ERR_SHOULDBEFILE, "SHOULDBEFILE", N_("You have to supply filename and not folder name.")},
132 {ERR_NOSIM, "NOSIM", N_("Can not access SIM card.")},
133 {ERR_GNAPPLETWRONG, "GNAPPLETWRONG", N_("Wrong GNAPPLET version in use on 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 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 {ERR_MEMORY_NOT_AVAILABLE, "MEMORY_NOT_AVAILABLE", N_("The type of memory is not available or has been disabled.")},
164 {ERR_INVALID_OPERATION, "INVALID_OPERATION", N_("The operation cannot be performed.")},
165
166 {0, "", ""}
167 };
168
GSM_ErrorName(GSM_Error e)169 const char *GSM_ErrorName(GSM_Error e)
170 {
171 const char *def = NULL;
172 int i = 0;
173
174 while (PrintErrorEntries[i].ErrorNum != 0) {
175 if (PrintErrorEntries[i].ErrorNum == e) {
176 def = PrintErrorEntries[i].ErrorName;
177 break;
178 }
179 i++;
180 }
181
182 return def;
183 }
184
GSM_ErrorString(GSM_Error e)185 const char *GSM_ErrorString(GSM_Error e)
186 {
187 const char *def = NULL;
188 int i = 0;
189
190 while (PrintErrorEntries[i].ErrorNum != 0) {
191 if (PrintErrorEntries[i].ErrorNum == e) {
192 def = PrintErrorEntries[i].ErrorText;
193 break;
194 }
195 i++;
196 }
197 if (def == NULL) def = N_("Unknown error description.");
198
199 return dgettext("libgammu", def);
200 }
201
GetGammuLocalePath(void)202 const char *GetGammuLocalePath(void)
203 {
204 #ifdef LOCALE_PATH
205 static const char Buffer[] = LOCALE_PATH;
206 return Buffer;
207 #else
208 return NULL;
209 #endif
210 }
211
GetGammuVersion(void)212 const char *GetGammuVersion(void)
213 {
214 static const char Buffer[] = GAMMU_VERSION;
215 return Buffer;
216 }
217
GSM_GetGlobalDebug()218 GSM_Debug_Info *GSM_GetGlobalDebug()
219 {
220 return &GSM_global_debug;
221 }
222
GSM_LogError(GSM_StateMachine * s,const char * message,const GSM_Error err)223 void GSM_LogError(GSM_StateMachine * s, const char * message, const GSM_Error err) {
224 if (err != ERR_NONE) {
225 smprintf(s, "%s failed with error %s[%d]: %s\n", message,
226 GSM_ErrorName(err), err,
227 GSM_ErrorString(err));
228 }
229 }
230
231 /* How should editor hadle tabs in this file? Add editor commands here.
232 * vim: noexpandtab sw=8 ts=8 sts=8:
233 */
234