00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00030 #include <string.h>
00031 #include <stdio.h>
00032 #include <ctype.h>
00033
00034 #include <glib.h>
00035
00036 #include "setupLog.h"
00037 #include "system.h"
00038 #include "iLiadPincodeData.h"
00039
00040
00041
00042 static sysPincodeSetting_t *g_current_pincode = NULL;
00043
00044 static sysPincodeSetting_t *g_stored_pincode = NULL;
00045
00046 static sysPincodeSetting_t *pincode_setting_dup(const sysPincodeSetting_t * settings);
00047 static void iLiad_pincode_data_read_pincode(sysPincodeSetting_t * settings);
00048 static void iLiad_pincode_data_write_pincode(const sysPincodeSetting_t * settings);
00049
00050
00051 void iLiad_pincode_data_init(void)
00052 {
00053 iLiad_pincode_data_destroy();
00054
00055 g_current_pincode = g_new0(sysPincodeSetting_t, 1);
00056 iLiad_pincode_data_read_pincode(g_current_pincode);
00057
00058 if (NULL == g_current_pincode)
00059 {
00060 ST_WARNPRINTF("use default values");
00061 g_current_pincode = g_new0(sysPincodeSetting_t, 1);
00062 g_current_pincode->enable = FALSE;
00063 g_current_pincode->pincode[0] = '\0';
00064 }
00065 else
00066 {
00067 g_stored_pincode = pincode_setting_dup(g_current_pincode);
00068 }
00069 }
00070
00071 void iLiad_pincode_data_destroy(void)
00072 {
00073 if (g_current_pincode)
00074 {
00075 g_free(g_current_pincode);
00076 g_current_pincode = NULL;
00077 }
00078
00079 if (g_stored_pincode)
00080 {
00081 g_free(g_stored_pincode);
00082 g_stored_pincode = NULL;
00083 }
00084 }
00085
00086 gboolean iLiad_pincode_data_is_pincode_on(void)
00087 {
00088 if (NULL == g_current_pincode)
00089 return FALSE;
00090 return g_current_pincode->enable;
00091 }
00092
00093 void iLiad_pincode_data_set_pincode_on(gboolean enable)
00094 {
00095 if (NULL == g_current_pincode)
00096 return;
00097 g_current_pincode->enable = enable;
00098 }
00099
00100 unsigned char *iLiad_pincode_data_get_pincode(void)
00101 {
00102 if (NULL == g_current_pincode)
00103 return NULL;
00104 return g_current_pincode->pincode;
00105 }
00106
00107 void iLiad_pincode_data_set_pincode(const gchar * text)
00108 {
00109 int len;
00110 if (NULL == text)
00111 return;
00112 if (NULL == g_current_pincode)
00113 return;
00114 len = strlen(text);
00115 if (len > PINCODE_MAX_LENGTH)
00116 len = PINCODE_MAX_LENGTH;
00117 strncpy(g_current_pincode->pincode, text, len);
00118 }
00119
00120
00121
00122
00123 gboolean iLiad_pincode_data_check_pincode(gchar * text)
00124 {
00125 int i, len;
00126 gboolean is_digital = FALSE;
00127 gboolean returnVal = FALSE;
00128 gchar c;
00129
00130 if (NULL == text)
00131 return FALSE;
00132 len = strlen(text);
00133 if (len < PINCODE_MIN_LENGTH || len > PINCODE_MAX_LENGTH)
00134 return FALSE;
00135 for (i = 0; i < len; i++)
00136 {
00137 c = text[i];
00138 is_digital = (isdigit(c)) ? TRUE : FALSE;
00139 if (FALSE == is_digital)
00140 break;
00141 }
00142 if (TRUE == is_digital)
00143 returnVal = TRUE;
00144 else
00145 returnVal = FALSE;
00146 return returnVal;
00147 }
00148
00149
00150 void iLiad_pincode_data_store()
00151 {
00152 if ((NULL == g_current_pincode) || (NULL == g_stored_pincode))
00153 return;
00154
00155 if ((g_current_pincode->enable != g_stored_pincode->enable)
00156 || (0 != strcmp(g_current_pincode->pincode, g_stored_pincode->pincode)))
00157 {
00158 iLiad_pincode_data_write_pincode(g_current_pincode);
00159
00160 if (g_stored_pincode->enable != g_current_pincode->enable)
00161 g_stored_pincode->enable = g_current_pincode->enable;
00162
00163 if (strcmp(g_current_pincode->pincode, g_stored_pincode->pincode))
00164 strcpy(g_stored_pincode->pincode, g_current_pincode->pincode);
00165 }
00166 }
00167
00168 static sysPincodeSetting_t *pincode_setting_dup(const sysPincodeSetting_t * settings)
00169 {
00170 sysPincodeSetting_t *dup = NULL;
00171
00172 if (NULL == settings)
00173 return NULL;
00174
00175 dup = g_new0(sysPincodeSetting_t, 1);
00176
00177 dup->enable = settings->enable;
00178
00179 if (0 == strlen(settings->pincode))
00180 dup->pincode[0] = '\0';
00181 else
00182 strcpy(dup->pincode, settings->pincode);
00183
00184 return dup;
00185 }
00186
00187
00188 static void iLiad_pincode_data_read_pincode(sysPincodeSetting_t * settings)
00189 {
00190 if (NULL == settings)
00191 return;
00192 sysset_read_pincode_onoff(&(settings->enable));
00193 sysset_read_pincode_string(settings->pincode);
00194 }
00195
00196 static void iLiad_pincode_data_write_pincode(const sysPincodeSetting_t * settings)
00197 {
00198 if (NULL == settings)
00199 return;
00200
00201 sysset_write_pincode_onoff(settings->enable);
00202 sysset_write_pincode_string(settings->pincode);
00203 }