sp_cfg.cpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  1. #include "precompile.h"
  2. #include "sp_cfg.h"
  3. #include "sp_def.h"
  4. //#include "sp_sal.h"
  5. #include "sp_dir.h"
  6. #include "sp_dbg_export.h"
  7. #include "sp_env.h"
  8. #include "sp_var.h"
  9. #include "iniutil.h"
  10. #include "strutil.h"
  11. #include "memutil.h"
  12. #include "shm_mem.h"
  13. #include "fileutil.h"
  14. #include "SpBase.h"
  15. #include "CodeSignVerify.h"
  16. #include <fstream>
  17. #include <ostream>
  18. #include <string>
  19. #include <vector>
  20. #include <stdio.h>
  21. #include <winpr/ini.h>
  22. #include <winpr/string.h>
  23. #define MAX_ENTITY_LEN 33
  24. #ifdef _WIN32
  25. #define MOD_LIB_SUFFIX ".dll"
  26. #else
  27. #define MOD_LIB_SUFFIX ".so"
  28. #endif //_WIN32
  29. #define T_MALLOC_T(type, shm) \
  30. shm ? (type*)shm_malloc(sizeof(type)) : (type*)malloc(sizeof(type))
  31. #define T_MALLOC(size, shm) \
  32. shm ? shm_malloc(size) : malloc(size)
  33. #define T_FREE(p, shm) \
  34. shm ? shm_free(p) : free(p)
  35. #define T_STRDUP(s, shm) \
  36. shm ? shm_strdup(s) : _strdup(s)
  37. #define T_ARRAY_MAKE(n, size, shm) \
  38. shm ? shm_array_make(n, size) : array_make(n, size)
  39. std::vector<std::string> g_arrKill;
  40. std::vector<std::string> g_arrStart;
  41. std::vector<std::string> getKillArr() {
  42. return g_arrKill;
  43. }
  44. std::vector<std::string> getStartArr() {
  45. return g_arrStart;
  46. }
  47. static int verify_entity_name(const char *name)
  48. {
  49. const char *p = name;
  50. int len = 0;
  51. while (*p) {
  52. if (!isalnum(*p)) {
  53. return FALSE;
  54. }
  55. len++;
  56. if (len > MAX_ENTITY_LEN)
  57. return FALSE;
  58. p++;
  59. }
  60. return TRUE;
  61. }
  62. static int parse_install_state(const char *str)
  63. {
  64. const struct {
  65. int ch;
  66. int val;
  67. } tbl[] = {
  68. {'A', Install_Active},
  69. {'I', Install_Pending},
  70. {'S', Install_SetToStart},
  71. {'F', Install_FailRun},
  72. {'R', Install_RollBack},
  73. {'U', Install_Upgraded},
  74. {'C',Install_Cancelled},
  75. {'W',Install_WaitConfirm},
  76. {'D', Install_Installed},
  77. };
  78. int i;
  79. for (i = 0; i < array_size(tbl); ++i) {
  80. if (tbl[i].ch == str[0]) {
  81. return tbl[i].val;
  82. }
  83. }
  84. return -1; // error
  85. }
  86. int read_ini_install_state(const char *file, const char *section, const char *key)
  87. {
  88. char *p = inifile_read_str(file, section, key, "");
  89. int ret = parse_install_state(p);
  90. toolkit_free(p);
  91. return ret;
  92. }
  93. static __inline int file_write(FILE *fp, const void *buf, int n)
  94. {
  95. size_t t = fwrite(buf, n, 1, fp);
  96. return t == n ? 0 : Error_IO;
  97. }
  98. static __inline int file_read(FILE *fp, void *buf, int n)
  99. {
  100. size_t t = fread(buf, n, 1, fp);
  101. return t == n ? 0 : Error_IO;
  102. }
  103. static void destroy_entity(sp_cfg_shell_entity_t *entity)
  104. {
  105. if (entity) {
  106. if (entity->name)
  107. shm_free(entity->name);
  108. if (entity->argv)
  109. shm_free((void*)entity->argv);
  110. if (entity->cmdline)
  111. shm_free(entity->cmdline);
  112. shm_free(entity);
  113. }
  114. }
  115. static void destroy_module(sp_cfg_shell_module_t* mod)
  116. {
  117. if (mod) {
  118. if (mod->name)
  119. shm_free(mod->name);
  120. if (mod->author)
  121. shm_free(mod->author);
  122. if (mod->company)
  123. shm_free(mod->company);
  124. shm_free(mod);
  125. }
  126. }
  127. static void destroy_sysevent(sp_cfg_shell_sysevent_t *sysevent)
  128. {
  129. if (sysevent) {
  130. if (sysevent->name)
  131. shm_free(sysevent->name);
  132. if (sysevent->arr_owner_entity)
  133. shm_array_free(sysevent->arr_owner_entity);
  134. shm_free(sysevent);
  135. }
  136. }
  137. static sp_cfg_path_t *find_path(sp_cfg_t *cfg, const char *path_prefix)
  138. {
  139. int i;
  140. for (i = 0; i < cfg->root_ini->arr_path->nelts; ++i) {
  141. sp_cfg_path_t *tpath = ARRAY_IDX(cfg->root_ini->arr_path, i, sp_cfg_path_t*);
  142. if (strcmp(tpath->name, path_prefix) == 0) {
  143. return tpath;
  144. }
  145. }
  146. return NULL;
  147. }
  148. static sp_cfg_shell_module_t* find_module(sp_cfg_shell_ini_t *shell, const char *mod_name)
  149. {
  150. int i;
  151. sp_cfg_shell_module_t* mod;
  152. const int len = (strstr(mod_name, "lib") == mod_name) ? 3 : 0; //linux .so name
  153. ARRAY_FOR_EACH_ENTRY(mod, i, shell->arr_module, sp_cfg_shell_module_t*) {
  154. if (_stricmp(mod->name, mod_name + len) == 0)
  155. return mod;
  156. }
  157. return NULL;
  158. }
  159. static sp_cfg_shell_entity_t *find_entity(sp_cfg_shell_ini_t *shell, const char *entity_name)
  160. {
  161. int i;
  162. sp_cfg_shell_entity_t *entity;
  163. ARRAY_FOR_EACH_ENTRY(entity, i, shell->arr_entity, sp_cfg_shell_entity_t*) {
  164. if (_stricmp(entity->name, entity_name) == 0)
  165. return entity;
  166. }
  167. return NULL;
  168. }
  169. static int read_ini_version(const char *file, const char *section, const char *key, int *major, int *minor, int *revision, int *build)
  170. {
  171. int n;
  172. int ret = -1;
  173. char *str = inifile_read_str(file, section, key, "");
  174. if (str) {
  175. if (strlen(str) == 0) {
  176. if (major)
  177. *major = 0;
  178. if (minor)
  179. *minor = 0;
  180. if (revision)
  181. *revision = 0;
  182. if (build)
  183. *build = 0;
  184. return 0;
  185. }
  186. toolkit_free(str);
  187. }
  188. if (build) {
  189. n = inifile_format_read(file, section, key, "%d.%d.%d.%d", major, minor, revision, build);
  190. if (n == 4)
  191. ret = 0;
  192. } else if (revision) {
  193. n = inifile_format_read(file, section, key, "%d.%d.%d", major, minor, revision);
  194. if (n == 3)
  195. ret = 0;
  196. } else {
  197. n = inifile_format_read(file, section, key, "%d.%d", major, minor);
  198. if (n == 2)
  199. ret = 0;
  200. }
  201. return ret;
  202. }
  203. static int read_ini_str(const char *file, const char *section, const char *key, char **pstr, int shm)
  204. {
  205. int rc = Error_Param;
  206. char *str = inifile_read_str(file, section, key, "");
  207. if (str){
  208. if (shm) {
  209. *pstr = shm_strdup(str);
  210. rc = 0;
  211. toolkit_free(str);
  212. } else {
  213. *pstr = str;
  214. rc = 0;
  215. }
  216. }
  217. return rc;
  218. }
  219. static int read_ini_date(const char *file, const char *section, const char *key,
  220. int *year, int *month, int *day, int *hour, int *minute, int *second, int shm)
  221. {
  222. int ret;
  223. if (second)
  224. *second = 0;
  225. ret = inifile_format_read(file, section, key, "%d-%d-%d %d:%d", year, month, day, hour, minute);
  226. return ret == 5 ? 0 : Error_Param;
  227. }
  228. static int read_ini_position(const char *file, const char *section, const char *key, float *x, float *y, int shm)
  229. {
  230. int ret;
  231. ret = inifile_format_read(file, section, key, "%f,%f", x, y);
  232. return ret == 2 ? 0 : Error_Param;
  233. }
  234. static int read_ini_path(const char *file, const char *section, const char *key, char **path, int shm)
  235. {
  236. int rc = read_ini_str(file, section, key, path, shm);
  237. if (rc == 0) {
  238. char *s = *path;
  239. int slen = strlen(s);
  240. if (s[slen - 1] == SPLIT_SLASH)
  241. s[slen - 1] = 0;
  242. }
  243. return rc;
  244. }
  245. static int read_terminal(const char *file, sp_cfg_root_ini_t *root, int shm)
  246. {
  247. int rc;
  248. rc = read_ini_str(file, "Terminal", "TerminalNo", &root->terminal_no, shm);
  249. if (rc != 0)
  250. return rc;
  251. rc = read_ini_str(file, "Terminal", "MachineType", &root->machine_type, shm);
  252. if (rc != 0)
  253. return rc;
  254. rc = read_ini_str(file, "Terminal", "MachineModel", &root->machine_model, shm);
  255. rc = read_ini_version(file, "Terminal", "MachineVersion",
  256. &root->machine_version.major, &root->machine_version.minor, NULL, NULL);
  257. if (rc != 0)
  258. return rc;
  259. rc = read_ini_str(file, "Terminal", "Site", &root->site, shm);
  260. if (rc != 0)
  261. return rc;
  262. root->screen = inifile_read_int(file, "Terminal", "Screen", -1);
  263. if (root->screen == -1) {
  264. rc = -1;
  265. return rc;
  266. }
  267. rc = read_ini_position(file, "Terminal", "EnrolGPS", &root->enroll_gps_x, &root->enroll_gps_y, shm);
  268. if (rc != 0)
  269. return rc;
  270. rc = read_ini_str(file, "Terminal", "EnrolAddr", &root->enroll_address, shm);
  271. if (rc != 0)
  272. return rc;
  273. return rc;
  274. }
  275. static int read_path(const char *file, sp_cfg_root_ini_t *root, int shm)
  276. {
  277. int rc = 0;
  278. array_header_t *arr_kvp = NULL;
  279. char *pos;
  280. int i;
  281. arr_kvp = inifile_read_section_key_all(file, "Path");
  282. if (!arr_kvp)
  283. return Error_NotExist;
  284. root->arr_path = T_ARRAY_MAKE(arr_kvp->nelts, sizeof(sp_cfg_path_t*), shm);
  285. ARRAY_FOR_EACH_ENTRY(pos, i, arr_kvp, char*) {
  286. sp_cfg_path_t *path = T_MALLOC_T(sp_cfg_path_t, shm);
  287. path->name = T_STRDUP(pos, shm);
  288. rc = read_ini_path(file, "Path", pos, &path->path, shm);
  289. if (rc != 0)
  290. return rc;
  291. if (shm) {
  292. SHM_ARRAY_PUSH(root->arr_path, sp_cfg_path_t*) = path;
  293. } else {
  294. ARRAY_PUSH(root->arr_path, sp_cfg_path_t*) = path;
  295. }
  296. if (strcmp(path->name, "SysRoot") == 0) {
  297. root->ref_sysroot_path = path->path;
  298. } else if (strcmp(path->name, "ADData") == 0) {
  299. root->ref_addata_path = path->path;
  300. } else if (strcmp(path->name, "SysLog") == 0) {
  301. root->ref_syslog_path = path->path;
  302. } else if (strcmp(path->name, "InterLog") == 0) {
  303. root->ref_intlog_path = path->path;
  304. } else if (strcmp(path->name, "UploadVideo") == 0) {
  305. root->ref_uploadvideo_path = path->path;
  306. } else if (strcmp(path->name, "UploadPhoto") == 0) {
  307. root->ref_uploadphoto_path = path->path;
  308. } else if (strcmp(path->name, "LocalVideo") == 0) {
  309. root->ref_localvideo_path = path->path;
  310. } else if (strcmp(path->name, "Downloads") == 0) {
  311. root->ref_downloads_path = path->path;
  312. } else if (strcmp(path->name, "Upgraded") == 0) {
  313. root->ref_upgraded_path = path->path;
  314. } else if (strcmp(path->name, "Temp") == 0) {
  315. root->ref_tmp_path = path->path;
  316. } else if (strcmp(path->name, "CenterSetting") == 0) {
  317. root->ref_centersetting_path = path->path;
  318. }
  319. }
  320. toolkit_array_free2(arr_kvp);
  321. return rc;
  322. }
  323. static sp_cfg_pack_info_t *read_pack_info(const char *file, const char *pack, int shm)
  324. {
  325. sp_cfg_pack_info_t *pack_info = T_MALLOC_T(sp_cfg_pack_info_t, shm);
  326. memset(pack_info, 0, sizeof(sp_cfg_pack_info_t));
  327. pack_info->name = T_STRDUP(pack, shm);
  328. pack_info->install_time = inifile_read_int(file, pack, "InstalledDate", 0);
  329. pack_info->state = read_ini_install_state(file, pack, "PackState");
  330. return pack_info;
  331. }
  332. static array_header_t *parse_packs(const char *file, const char *str, int shm)
  333. {
  334. array_header_t *arr = T_ARRAY_MAKE(-1, sizeof(sp_cfg_pack_info_t*), shm);
  335. char *packs = _strdup(str);
  336. if (packs) {
  337. char *token;
  338. const char *seps = " \t,";
  339. token = strtok(packs, seps);
  340. while (token != NULL) {
  341. sp_cfg_pack_info_t *pack_info = read_pack_info(file, token, shm);
  342. if (pack_info) {
  343. if (shm) {
  344. SHM_ARRAY_PUSH(arr, sp_cfg_pack_info_t*) = pack_info;
  345. } else {
  346. ARRAY_PUSH(arr, sp_cfg_pack_info_t*) = pack_info;
  347. }
  348. }
  349. token = strtok(NULL, seps);
  350. }
  351. free(packs);
  352. }
  353. return arr;
  354. }
  355. static int load_root_ini(sp_dir_t *dir, sp_cfg_root_ini_t *root, const char *file, int shm)
  356. {
  357. int rc;
  358. rc = read_terminal(file, root, shm);
  359. if (rc != 0)
  360. return rc;
  361. rc = read_path(file, root, shm);
  362. return rc;
  363. }
  364. static int unload_root_ini(sp_cfg_root_ini_t *root, int shm)
  365. {
  366. int i;
  367. if (shm) {
  368. shm_free(root->terminal_no);
  369. shm_free(root->machine_type);
  370. shm_free(root->enroll_address);
  371. for (i = 0; i < root->arr_path->nelts; ++i) {
  372. sp_cfg_path_t *path = ARRAY_IDX(root->arr_path, i, sp_cfg_path_t*);
  373. shm_free(path->name);
  374. shm_free(path->path);
  375. shm_free(path);
  376. }
  377. shm_array_free(root->arr_path);
  378. } else {
  379. free(root->terminal_no);
  380. free(root->machine_type);
  381. free(root->enroll_address);
  382. for (i = 0; i < root->arr_path->nelts; ++i) {
  383. sp_cfg_path_t *path = ARRAY_IDX(root->arr_path, i, sp_cfg_path_t*);
  384. free(path->name);
  385. free(path->path);
  386. free(path);
  387. }
  388. array_free(root->arr_path);
  389. }
  390. memset(root, 0, sizeof(sp_cfg_root_ini_t));
  391. return 0;
  392. }
  393. static inline int shell_ini__load_debug_level(const char* shell_ini_path, const char* entity_name)
  394. {
  395. int level = inifile_read_int(shell_ini_path, "Debug", entity_name, 0);
  396. /*to see: DebugLevelEnum*/
  397. if (level > 2 || level < 0)
  398. level = 0;
  399. return level;
  400. }
  401. /*add intrinsic spshell module*/
  402. static inline void shell_ini__load_init_shell(sp_cfg_shell_ini_t* shell, const char* shell_ini_path, const CVersionInfo* shell_ver)
  403. {
  404. sp_cfg_shell_entity_t* ent = NULL;
  405. sp_cfg_shell_module_t* mod = NULL;
  406. mod = (sp_cfg_shell_module_t*)shm_malloc(sizeof(sp_cfg_shell_module_t));
  407. memset(mod, 0, sizeof(sp_cfg_shell_module_t));
  408. sp_version_copy(&mod->version, &shell->software_version);
  409. mod->author = shm_strdup(shell_ver->strAuthorName);
  410. mod->company = shm_strdup(shell_ver->strCompanyName);
  411. mod->name = shm_strdup("SpShell");
  412. mod->mem_trace = inifile_read_int(shell_ini_path, "MemTrace", mod->name, 0);
  413. mod->idx = shell->arr_module->nelts; //the first mod id is spshell
  414. /*increment netls at the same time*/
  415. SHM_ARRAY_PUSH(shell->arr_module, sp_cfg_shell_module_t*) = mod;
  416. ent = (sp_cfg_shell_entity_t*)shm_malloc(sizeof(sp_cfg_shell_entity_t));
  417. memset(ent, 0, sizeof(sp_cfg_shell_entity_t));
  418. ent->mod = mod;
  419. ent->name = shm_strdup("SpShell");
  420. ent->idx = shell->arr_entity->nelts;
  421. ent->privilege = 1;
  422. ent->debug_level = shell_ini__load_debug_level(shell_ini_path, ent->name);
  423. SHM_ARRAY_PUSH(shell->arr_entity, sp_cfg_shell_entity_t*) = ent;
  424. }
  425. static inline void shell_ini__get_mod_version(sp_cfg_shell_module_t* mod, const char* mod_path)
  426. {
  427. #ifdef _WIN32
  428. CCodeSignVerify ver;
  429. CVersionInfo verInfo;
  430. if (!ver.GetVersionInfo(mod_path, verInfo))
  431. sp_dbg_warn("read file %s version info fail, %s", mod_path, (const char*)ver.GetErrorMsg());
  432. mod->author = shm_strdup(verInfo.strAuthorName);
  433. mod->company = shm_strdup(verInfo.strCompanyName);
  434. mod->version.major = verInfo.FileVersion.GetMajor();
  435. mod->version.minor = verInfo.FileVersion.GetMajor();
  436. mod->version.revision = verInfo.FileVersion.GetRevision();
  437. mod->version.build = verInfo.FileVersion.GetBuild();
  438. #endif
  439. }
  440. static inline int shell_ini__veritify_core_file_legality(sp_dir_t* dir, sp_cfg_shell_ini_t* shell)
  441. {
  442. #ifdef _WIN32
  443. // SpBase.dll、SpShell.exe、SpHost.exe代码签名校验
  444. char sal_tmp[MAX_PATH] = { 0 };
  445. const char* sal_files[] = { "SpBase.dll", "SpHost.exe", "SpShell.exe" };
  446. int i;
  447. CCodeSignVerify ver;
  448. for (i = 0; i < sizeof(sal_files) / sizeof(sal_files[0]); i++) {
  449. sprintf(sal_tmp, "%s" SPLIT_SLASH_STR "%s", dir->bin_path, sal_files[i]);
  450. CSignInfo signInfo;
  451. if (!ver.VerifySignature(sal_tmp, signInfo)) {
  452. sp_dbg_error("file %s sign verify fail, %s", sal_files[i], (const char*)ver.GetErrorMsg());
  453. return Error_FailVerify;
  454. }
  455. sp_dbg_info("file %s sign verify pass, signer: %s, sign time: %s, cert hash: %s", sal_files[i],
  456. (const char*)signInfo.strSignCertSubject, (const char*)signInfo.dtSignTime.ToTimeString(), (const char*)signInfo.strSignCertHash);
  457. if (shell->spbase_sign_cert_hash == NULL) {
  458. shell->spbase_sign_cert_hash = shm_strdup(signInfo.strSignCertHash);
  459. }
  460. else if (stricmp(shell->spbase_sign_cert_hash, signInfo.strSignCertHash) != 0) {
  461. sp_dbg_error("sign cert hash not equal, last : [%s], current: [%s]", shell->spbase_sign_cert_hash, (const char*)signInfo.strSignCertHash);
  462. return Error_FailVerify;
  463. }
  464. }
  465. #endif
  466. return 0;
  467. }
  468. static inline int shell_ini__vertify_mod_legality(sp_cfg_shell_ini_t* shell, const char* lib_file_path, const char* mod_name)
  469. {
  470. int rc = 0;
  471. #ifdef _WIN32
  472. CCodeSignVerify ver;
  473. CSignInfo signInfo;
  474. if (!ver.VerifySignature(lib_file_path, signInfo)) {
  475. sp_dbg_error("file %s sign verify fail, %s", mod_name, (const char*)ver.GetErrorMsg());
  476. rc = Error_FailVerify;
  477. }
  478. sp_dbg_info("file %s sign verify pass, signer: %s, sign time: %s, cert hash: %s", mod_name,
  479. (const char*)signInfo.strSignCertSubject, (const char*)signInfo.dtSignTime.ToTimeString(), (const char*)signInfo.strSignCertHash);
  480. if (stricmp(shell->spbase_sign_cert_hash, signInfo.strSignCertHash) != 0) {
  481. sp_dbg_error("entity %s sign cert hash [%s] not equal to spbase sign cert hash [%s]",
  482. mod_name, (const char*)signInfo.strSignCertHash, shell->spbase_sign_cert_hash);
  483. rc = Error_FailVerify;
  484. }
  485. #endif
  486. return rc;
  487. }
  488. static int shell_ini__load_entities_list(sp_dir_t* dir, sp_cfg_shell_ini_t* shell, const char* shell_ini_path, bool vertify_or_not)
  489. {
  490. //read Main:EntityGroupNum
  491. int entityGroupNum = inifile_read_int(shell_ini_path, "Main", "EntityGroupNum", 0);
  492. int curGroup = 0;
  493. int rc = 0;
  494. int i;
  495. array_header_t* arr;
  496. do {
  497. char sectionName[MAX_PATH] = "";
  498. if (0 == curGroup)
  499. sprintf_s(sectionName, MAX_PATH, "Entity");
  500. else
  501. sprintf_s(sectionName, MAX_PATH, "Group%d", curGroup);
  502. arr = inifile_read_section_key_all(shell_ini_path, sectionName);
  503. for (i = 0; i < arr->nelts; ++i) {
  504. char tmp[MAX_PATH];
  505. int ret;
  506. sp_cfg_shell_entity_t* entity = (sp_cfg_shell_entity_t*)shm_malloc(sizeof(sp_cfg_shell_entity_t));
  507. memset(entity, 0, sizeof(sp_cfg_shell_entity_t));
  508. entity->name = shm_strdup(ARRAY_IDX(arr, i, char*));
  509. if (!verify_entity_name(entity->name)) {
  510. rc = Error_Unexpect;
  511. sp_dbg_warn("verify entity %s name failed!", entity->name);
  512. break;
  513. }
  514. entity->debug_level = shell_ini__load_debug_level(shell_ini_path, entity->name);
  515. ret = inifile_format_read(shell_ini_path, sectionName, entity->name, "%d,%[^,],%x", &entity->privilege, tmp, &entity->devel_id);
  516. if (ret == 3) {
  517. sp_cfg_shell_module_t* mod;
  518. if (str_has_suffix(tmp, MOD_LIB_SUFFIX)) {
  519. const int len = strlen(tmp);
  520. tmp[len - strlen(MOD_LIB_SUFFIX)] = 0;
  521. }
  522. mod = find_module(shell, tmp);
  523. if (!mod) {
  524. char mod_lib_path[MAX_PATH];
  525. const int len = (strstr(tmp, "lib") == tmp) ? 3 : 0;
  526. mod = (sp_cfg_shell_module_t*)shm_malloc(sizeof(sp_cfg_shell_module_t));
  527. memset(mod, 0, sizeof(sp_cfg_shell_module_t));
  528. mod->name = shm_strdup(tmp + len);
  529. tmp[strlen(tmp)] = '.';
  530. sprintf(mod_lib_path, "%s" SPLIT_SLASH_STR "%s", dir->mod_path, tmp);
  531. mod->group = curGroup;
  532. if (vertify_or_not) {
  533. rc = shell_ini__vertify_mod_legality(shell, mod_lib_path, mod->name);
  534. }
  535. if (rc == 0) {
  536. shell_ini__get_mod_version(mod, mod_lib_path);
  537. mod->mem_trace = inifile_read_int(shell_ini_path, "MemTrace", mod->name, 0);
  538. mod->idx = shell->arr_module->nelts;
  539. SHM_ARRAY_PUSH(shell->arr_module, sp_cfg_shell_module_t*) = mod;
  540. }
  541. else {
  542. sp_dbg_warn("sal verify file %s failed!", mod_lib_path);
  543. destroy_module(mod);
  544. destroy_entity(entity);
  545. break;
  546. }
  547. }
  548. entity->mod = mod;
  549. entity->idx = shell->arr_entity->nelts;
  550. SHM_ARRAY_PUSH(shell->arr_entity, sp_cfg_shell_entity_t*) = entity;
  551. sp_dbg_info("entity: %s, id: %d", entity->name, entity->idx);
  552. }
  553. else {
  554. sp_dbg_warn("read entity line failed! bad format!");
  555. rc = Error_Param;
  556. destroy_entity(entity);
  557. break;
  558. }
  559. }
  560. if (rc != 0)
  561. break;
  562. toolkit_array_free2(arr);
  563. } while (curGroup++ < entityGroupNum);
  564. return rc;
  565. }
  566. static int shell_ini__load_mod_entity(sp_dir_t* dir, sp_cfg_shell_ini_t* shell, const char* shell_ini_path, const sp_cfg_start_args_t* args, const CVersionInfo* ver)
  567. {
  568. shell->arr_entity = shm_array_make(0, sizeof(sp_cfg_shell_entity_t*));
  569. // BugFix: replace char* with sp_cfg_shell_module_t* [Gifur@2020422]
  570. shell->arr_module = shm_array_make(0, sizeof(sp_cfg_shell_module_t*));
  571. shell_ini__load_init_shell(shell, shell_ini_path, ver);
  572. return shell_ini__load_entities_list(dir, shell, shell_ini_path, args->sign_verifity);
  573. }
  574. static int shell_ini__load_sysevent(sp_cfg_shell_ini_t* shell, const char* shell_ini_path, const char* shell_var_path)
  575. {
  576. int rc = 0;
  577. int i, index;
  578. array_header_t* arr;
  579. shell->arr_sysevent = shm_array_make(0, sizeof(sp_cfg_shell_sysevent_t*));
  580. index = 0;
  581. {
  582. sp_cfg_shell_sysevent_t* sysevent = T_MALLOC_T(sp_cfg_shell_sysevent_t, 1);
  583. memset(sysevent, 0, sizeof(sp_cfg_shell_sysevent_t));
  584. sysevent->name = T_STRDUP(VAR_RSERVERD_KEY_TERM_STATE, 1);
  585. sysevent->init_value[0] = '0', sysevent->init_value[1] = '\0';
  586. sysevent->arr_owner_entity = shm_array_make(0, sizeof(sp_cfg_shell_entity_t*));
  587. sp_cfg_shell_entity_t* owner_entity = find_entity(shell, "SpShell");
  588. if (owner_entity) {
  589. sp_dbg_debug("add framework level sys val: %s", VAR_RSERVERD_KEY_TERM_STATE);
  590. SHM_ARRAY_PUSH(sysevent->arr_owner_entity, sp_cfg_shell_entity_t*) = owner_entity;
  591. sysevent->idx = shell->arr_sysevent->nelts;
  592. SHM_ARRAY_PUSH(shell->arr_sysevent, sp_cfg_shell_sysevent_t*) = sysevent;
  593. } else {
  594. sp_dbg_warn("cannot find specified entity for sys val: %s", VAR_RSERVERD_KEY_TERM_STATE);
  595. destroy_sysevent(sysevent);
  596. }
  597. }
  598. arr = inifile_read_section_key_all(shell_ini_path, "SysEvent");
  599. for (i = 0; i < arr->nelts; ++i) {
  600. char tmp[1024], tmp2[1024];
  601. char initVar[SP_CFG_MAX_SYSEVT_BUF];
  602. int ret;
  603. sp_cfg_shell_sysevent_t* sysevent = (sp_cfg_shell_sysevent_t*)shm_malloc(sizeof(sp_cfg_shell_sysevent_t));
  604. memset(sysevent, 0, sizeof(sp_cfg_shell_sysevent_t));
  605. sysevent->name = shm_strdup(ARRAY_IDX(arr, i, char*));
  606. sysevent->arr_owner_entity = shm_array_make(0, sizeof(sp_cfg_shell_entity_t*));
  607. ret = inifile_format_read(shell_ini_path, "SysEvent", sysevent->name, "%[^,], \"%[^\"]", tmp, sysevent->init_value);
  608. auto varRet = inifile_format_read(shell_var_path, "SysEvent", sysevent->name, "%[^,], \"%[^\"]", tmp2, initVar);
  609. if (varRet > 0) {
  610. memcpy(tmp, tmp2, sizeof(tmp));
  611. memcpy(sysevent->init_value, initVar, sizeof(sysevent->init_value)); //如果在shellvar.ini中也能找到该数据,则替换该数值
  612. //情况1:shell.ini添加一个长期有效变量,则在write时在shellvar.ini中生成一个相应的副本。下次读取时从shellvar.ini中读取
  613. //情况2:shell.ini中删除一个长期有效变量,shellvar.ini中并不会相应删除.优先从shell.ini中读取相应变量
  614. }
  615. // 为安全起见,准入实体状态强制设为初始状态I
  616. if (stricmp(sysevent->name, "EntryPermit") == 0)
  617. strcpy(sysevent->init_value, "I");
  618. if (ret > 0) {
  619. const char* seps = ";\t ";
  620. char* tok = strtok(tmp, seps);
  621. while (tok) {
  622. sp_cfg_shell_entity_t* owner_entity = find_entity(shell, tok);
  623. if (owner_entity) {
  624. SHM_ARRAY_PUSH(sysevent->arr_owner_entity, sp_cfg_shell_entity_t*) = owner_entity;
  625. }
  626. else {
  627. sp_dbg_error("cannot find entity: %s", tok);
  628. rc = Error_NotExist;
  629. destroy_sysevent(sysevent);
  630. break;
  631. }
  632. tok = strtok(NULL, seps);
  633. }
  634. if(rc != 0)
  635. break;
  636. sysevent->idx = shell->arr_sysevent->nelts;
  637. SHM_ARRAY_PUSH(shell->arr_sysevent, sp_cfg_shell_sysevent_t*) = sysevent;
  638. }
  639. else {
  640. sp_dbg_warn("read SysEvent failed! bad format!");
  641. rc = Error_Param;
  642. destroy_sysevent(sysevent);
  643. break;
  644. }
  645. }
  646. toolkit_array_free2(arr);
  647. return rc;
  648. }
  649. static int shell_ini__load_entity_list(sp_cfg_shell_ini_t* shell, array_header_t** arr, const char* shell_ini_path, int test_mode)
  650. {
  651. int i;
  652. int rc = 0;
  653. char section_name[128] = { "Startup" };
  654. if (test_mode) {
  655. sp_dbg_debug("test mode: override startup list");
  656. strcpy(section_name, "Test");
  657. }
  658. assert(arr);
  659. assert(*arr == NULL);
  660. i = inifile_read_int(shell_ini_path, section_name, "Number", 0);
  661. if (i >= 0) {
  662. int n = i;
  663. *arr = shm_array_make(i, sizeof(char*));
  664. assert(*arr);
  665. for (i = 1; i <= n; ++i) {
  666. char key[512];
  667. char* s;
  668. _itoa(i, key, 10);
  669. s = inifile_read_str(shell_ini_path, section_name, key, "");
  670. if (s) {
  671. if (strlen(s)) {
  672. int numargs, numchars;
  673. char** argv = NULL;
  674. char* p;
  675. sp_cfg_shell_entity_t* ent;
  676. char* cmdline = strchr(s, ' ');
  677. if (cmdline) {
  678. *cmdline = 0;
  679. cmdline++;
  680. str_parse_cmdline(cmdline, NULL, NULL, &numargs, &numchars);
  681. p = (char*)shm_malloc(numargs * sizeof(char*) + numchars);
  682. argv = (char**)p;
  683. str_parse_cmdline(cmdline, (char**)p, p + numargs * sizeof(char*), &numargs, &numchars);
  684. }
  685. ent = find_entity(shell, s);
  686. if (ent) {
  687. if (cmdline) {
  688. //TODO: detect only use entity::cmdline, never seem use of argc and argv [Gifur@2020426]
  689. ent->argc = numargs;
  690. ent->argv = argv;
  691. if (numargs) {
  692. ent->cmdline = shm_strdup(cmdline);
  693. }
  694. }
  695. SHM_ARRAY_PUSH(*arr, sp_cfg_shell_entity_t*) = ent;
  696. }
  697. else {
  698. sp_dbg_warn("read %s failed! find startup list [%s] defined entity [%s] fail!", section_name, key, s);
  699. rc = Error_Param;
  700. }
  701. }
  702. else {
  703. sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
  704. rc = Error_Param;
  705. }
  706. toolkit_free(s);
  707. }
  708. else {
  709. sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
  710. rc = Error_Param;
  711. }
  712. if (rc != 0)
  713. break;
  714. }
  715. }
  716. else {
  717. sp_dbg_warn("read %s failed! startup number invalid!", section_name);
  718. rc = Error_Param;
  719. }
  720. return rc;
  721. }
  722. /*
  723. static int shell_ini__load_bootup_entities(sp_cfg_shell_ini_t* shell, const char* shell_ini_path, int test_mode)
  724. {
  725. int i;
  726. int rc = 0;
  727. char section_name[128] = { "Startup" };
  728. if (test_mode) {
  729. sp_dbg_debug("test mode: override startup list");
  730. strcpy(section_name, "Test");
  731. }
  732. i = inifile_read_int(shell_ini_path, section_name, "Number", 0);
  733. if (i >= 0) {
  734. int n = i;
  735. shell->arr_startlist = shm_array_make(i, sizeof(char*));
  736. for (i = 1; i <= n; ++i) {
  737. char key[512];
  738. char* s;
  739. _itoa(i, key, 10);
  740. s = inifile_read_str(shell_ini_path, section_name, key, "");
  741. if (s) {
  742. if (strlen(s)) {
  743. int numargs, numchars;
  744. char** argv = NULL;
  745. char* p;
  746. sp_cfg_shell_entity_t* ent;
  747. char* cmdline = strchr(s, ' ');
  748. if (cmdline) {
  749. *cmdline = 0;
  750. cmdline++;
  751. str_parse_cmdline(cmdline, NULL, NULL, &numargs, &numchars);
  752. p = (char*)shm_malloc(numargs * sizeof(char*) + numchars);
  753. argv = (char**)p;
  754. str_parse_cmdline(cmdline, (char**)p, p + numargs * sizeof(char*), &numargs, &numchars);
  755. }
  756. ent = find_entity(shell, s);
  757. if (ent) {
  758. if (cmdline) {
  759. //TODO: detect only use entity::cmdline, never seem use of argc and argv [Gifur@2020426]
  760. ent->argc = numargs;
  761. ent->argv = argv;
  762. if (numargs) {
  763. ent->cmdline = shm_strdup(cmdline);
  764. }
  765. }
  766. SHM_ARRAY_PUSH(shell->arr_startlist, sp_cfg_shell_entity_t*) = ent;
  767. }
  768. else {
  769. sp_dbg_warn("read %s failed! find startup list [%s] defined entity [%s] fail!", section_name, key, s);
  770. rc = Error_Param;
  771. }
  772. }
  773. else {
  774. sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
  775. rc = Error_Param;
  776. }
  777. toolkit_free(s);
  778. }
  779. else {
  780. sp_dbg_warn("read %s failed! startup list [%s] define invalid!", section_name, key);
  781. rc = Error_Param;
  782. }
  783. if (rc != 0)
  784. break;
  785. }
  786. }
  787. else {
  788. sp_dbg_warn("read %s failed! startup number invalid!", section_name);
  789. rc = Error_Param;
  790. }
  791. return rc;
  792. }
  793. */
  794. static int shell_init__load_startup_list(sp_cfg_shell_ini_t* shell, const char* shell_ini_path)
  795. {
  796. return shell_ini__load_entity_list(shell, &shell->arr_startlist, shell_ini_path, 0);
  797. }
  798. static inline int shell_ini__load_software_version(sp_cfg_shell_ini_t* shell, const char* shell_ini_path, const char* shell_runinfo_file)
  799. {
  800. int rc = 0;
  801. shell->software_version.build = 0;
  802. if (NULL != shell_runinfo_file)
  803. rc = read_ini_version(shell_runinfo_file, "Main", "SoftwareVersion",
  804. &shell->software_version.major, &shell->software_version.minor, &shell->software_version.revision, NULL);
  805. if (rc != 0)
  806. rc = read_ini_version(shell_ini_path, "Main", "SoftwareVersion",
  807. &shell->software_version.major, &shell->software_version.minor, &shell->software_version.revision, NULL);
  808. if (rc != 0) {
  809. sp_dbg_warn("read Main::SoftwareVersion failed!");
  810. }
  811. return rc;
  812. }
  813. static int sp_cfg_get_vertify_sign(sp_dir_t* dir, sp_cfg_root_ini_t* root)
  814. {
  815. CSimpleStringA strCenterSettingFullPath;
  816. strCenterSettingFullPath = dir->cfg_path;
  817. if ((stricmp(root->site, "CMB.LIB") == 0) // 行内大堂
  818. || (stricmp(root->site, "CMB.SSB") == 0))// 自助网点
  819. {
  820. strCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.LAN.ini";
  821. }
  822. else if ((stricmp(root->site, "CMB.LSS") == 0) // 生活销售机
  823. || (stricmp(root->site, "CMB.FLB") == 0) // 离行机器
  824. || (stricmp(root->site, "CMB.OSB") == 0) // 外拓PAD
  825. || (stricmp(root->site, "CMB.SMM") == 0)) // 商户终端
  826. {
  827. strCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.DMZ.ini";
  828. }
  829. else {
  830. strCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.DMZ.ini";
  831. }
  832. //add (const char*) for fixing string print bug. Gifur
  833. sp_dbg_info("strCenterSettingFullPath=%s!", (const char*)strCenterSettingFullPath);
  834. //add by zl 20170717,从集中配置读取代码签名开关[VerifyCodeSign]
  835. int nVerifyCodeSign = inifile_read_int(strCenterSettingFullPath.GetData(), "SpBase", "VerifyCodeSign", 0);
  836. sp_dbg_info("get VerifyCodeSign=%d from [%s] ini", nVerifyCodeSign, strCenterSettingFullPath.GetData());
  837. return nVerifyCodeSign > 0 ? 1 : 0;
  838. }
  839. static int load_shell_ini(sp_dir_t *dir, sp_cfg_shell_ini_t *shell, const sp_cfg_start_args_t* args, const char *shell_ini_path, const char *fileVar)
  840. {
  841. int rc = -1;
  842. int i;
  843. array_header_t *arr;
  844. if((rc = shell_ini__load_software_version(shell, shell_ini_path, fileVar)) != 0)
  845. return rc;
  846. if (args->sign_verifity && (rc = shell_ini__veritify_core_file_legality(dir, shell)) != 0)
  847. return rc;
  848. CCodeSignVerify signVerify;
  849. CVersionInfo shellVerInfo;
  850. char spshell_path[MAX_PATH] = { 0 };
  851. sprintf(spshell_path, "%s" SPLIT_SLASH_STR "%s", dir->bin_path, "SpShell.exe");
  852. if (!signVerify.GetVersionInfo(spshell_path, shellVerInfo)) {
  853. sp_dbg_warn("read file %s version info fail, %s", spshell_path, (const char*)signVerify.GetErrorMsg());
  854. }
  855. if ((rc = shell_ini__load_mod_entity(dir, shell, shell_ini_path, args, &shellVerInfo)) != 0)
  856. return rc;
  857. if ((rc = shell_ini__load_sysevent(shell, shell_ini_path, fileVar)) != 0) {
  858. return rc;
  859. }
  860. if (args->debug_mode && shell->arr_entity) {
  861. sp_dbg_debug("override entities' debug level!");
  862. for (i = 0; i < shell->arr_entity->nelts; ++i) {
  863. sp_cfg_shell_entity_t* entity = ARRAY_IDX(shell->arr_entity, i, sp_cfg_shell_entity_t*);
  864. entity->debug_level = 2; /*Debug_High*/
  865. }
  866. }
  867. if (args->start_entities != NULL) {
  868. char* value;
  869. char* name;
  870. char* context = NULL;
  871. array_header_t* t = NULL;
  872. sp_dbg_debug("override start entity list!");
  873. value = _strdup(args->start_entities);
  874. if (!value) {
  875. sp_dbg_error("_strdup start_entities failed!");
  876. return -1;
  877. }
  878. shell->arr_startlist = shm_array_make(1, sizeof(char*));
  879. name = strtok_s(value, ";", &context);
  880. while (name != NULL) {
  881. sp_cfg_shell_entity_t* ent = find_entity(shell, name);
  882. if (ent) {
  883. SHM_ARRAY_PUSH(shell->arr_startlist, sp_cfg_shell_entity_t*) = ent;
  884. } else {
  885. sp_dbg_error("cannot find entity name %s defined at cmdline!", name);
  886. rc = Error_Param;
  887. }
  888. name = strtok_s(NULL, ";", &context);
  889. }
  890. free(value);
  891. if (rc != 0)
  892. return rc;
  893. }
  894. else {
  895. if ((rc = shell_init__load_startup_list(shell, shell_ini_path)) != 0) {
  896. return rc;
  897. }
  898. if (args->test_mode) {
  899. array_header_t* arr = NULL;
  900. if ((rc = shell_ini__load_entity_list(shell, &arr, shell_ini_path, 1)) != 0)
  901. return rc;
  902. if (arr && arr->nelts > 0) {
  903. sp_dbg_info("append additional test entity: %d", arr->nelts);
  904. shm_array_cat(shell->arr_startlist, arr);
  905. }
  906. shm_array_free(arr);
  907. }
  908. }
  909. shell->shell_debug_level = args->debug_mode ? 2 : shell_ini__load_debug_level(shell_ini_path, "SpShell");
  910. shell->nConsolePort = inifile_read_int(shell_ini_path, "Main", "ConsolePort", 0);
  911. auto killNum = inifile_read_int(shell_ini_path, "killProcess", "Number", 0);
  912. g_arrKill.clear();
  913. for (int i = 1; i <= killNum; i++)
  914. {
  915. char key[512];
  916. char* s;
  917. _itoa(i, key, 10);
  918. s = inifile_read_str(shell_ini_path, "killProcess", key, "");
  919. if (s && strlen(s) > 0) {
  920. g_arrKill.push_back(s);
  921. toolkit_free(s);
  922. }
  923. else
  924. {
  925. sp_dbg_warn("read kill failed! killProcess list [%s] define invalid!", key);
  926. rc = Error_Param;
  927. break;
  928. }
  929. }
  930. auto startNum = inifile_read_int(shell_ini_path, "RunScript", "Number", 0);
  931. g_arrStart.clear();
  932. for (int i = 1; i <= startNum; i++)
  933. {
  934. char key[512];
  935. char* s;
  936. _itoa(i, key, 10);
  937. s = inifile_read_str(shell_ini_path, "RunScript", key, "");
  938. if (s && strlen(s) > 0) {
  939. std::string fullPath = std::string(dir->bin_path) + SPLIT_SLASH_STR "spScript" SPLIT_SLASH_STR + s;
  940. g_arrStart.push_back(fullPath);
  941. toolkit_free(s);
  942. }
  943. else
  944. {
  945. sp_dbg_warn("read start failed! RunScript list [%s] define invalid!", key);
  946. rc = Error_Param;
  947. break;
  948. }
  949. }
  950. return rc;
  951. }
  952. static int unload_shell_ini(sp_cfg_shell_ini_t *shell)
  953. {
  954. int i;
  955. if (shell->arr_entity) {
  956. for (i = 0; i< shell->arr_entity->nelts; ++i) {
  957. sp_cfg_shell_entity_t *entity = ARRAY_IDX(shell->arr_entity, i, sp_cfg_shell_entity_t*);
  958. destroy_entity(entity);
  959. }
  960. shm_array_free(shell->arr_entity);
  961. }
  962. if (shell->arr_module) {
  963. for (i = 0; i < shell->arr_module->nelts; ++i) {
  964. sp_cfg_shell_module_t *mod = ARRAY_IDX(shell->arr_module, i, sp_cfg_shell_module_t*);
  965. destroy_module(mod);
  966. }
  967. shm_array_free(shell->arr_module);
  968. }
  969. if (shell->arr_sysevent) {
  970. for (i = 0; i < shell->arr_sysevent->nelts; ++i) {
  971. sp_cfg_shell_sysevent_t *sysevent = ARRAY_IDX(shell->arr_sysevent, i, sp_cfg_shell_sysevent_t*);
  972. destroy_sysevent(sysevent);
  973. }
  974. shm_array_free(shell->arr_sysevent);
  975. }
  976. if (shell->arr_startlist) {
  977. shm_array_free(shell->arr_startlist);
  978. }
  979. return 0;
  980. }
  981. static int load_install_ini(sp_dir_t *dir, sp_cfg_install_ini_t *inst, const char *file, int shm)
  982. {
  983. int rc = 0;
  984. array_header_t *arr_section = NULL;
  985. int nLastStartTime =0;
  986. sp_version_t active_version = { 0 };
  987. rc = read_ini_version(file, "Main", "InstallVersion",
  988. &inst->install_version.major,
  989. &inst->install_version.minor,
  990. &inst->install_version.revision,
  991. &inst->install_version.build);
  992. if (rc != 0) {
  993. sp_dbg_warn("read ini file failed, %s Main::InstallVersion failed!", file);
  994. return rc;
  995. }
  996. // 校验版本目录名与软件版本是否一致
  997. sscanf(strrchr(dir->base_path, SPLIT_SLASH) + 1, "%d.%d.%d.%d",
  998. &active_version.major, &active_version.minor, &active_version.revision, &active_version.build);
  999. if (sp_version_cmp(&active_version, &inst->install_version) != 0)
  1000. {
  1001. sp_dbg_warn("version dir %d.%d.%d.%d not equals install version %d.%d.%d.%d",
  1002. active_version.major, active_version.minor, active_version.revision, active_version.build,
  1003. inst->install_version.major, inst->install_version.minor, inst->install_version.revision, inst->install_version.build);
  1004. return -1;
  1005. }
  1006. inst->install_time = inifile_read_int(file, "Main", "CreateDate", 0);
  1007. if (inst->install_time == 0) {
  1008. sp_dbg_warn("read ini file failed, %s Main::CreateDate failed", file);
  1009. return -1;
  1010. }
  1011. rc = read_ini_version(file, "Main", "LatterInstallVersion",
  1012. &inst->latter_install_version.major,
  1013. &inst->latter_install_version.minor,
  1014. &inst->latter_install_version.revision,
  1015. &inst->latter_install_version.build);
  1016. if (rc != 0) {
  1017. sp_dbg_warn("read ini file failed, %s Main::LatterInstallVersion failed!", file);
  1018. return rc;
  1019. }
  1020. rc = read_ini_str(file, "Main", "LightPack", &inst->light_packs, shm);
  1021. if (rc != 0 || inst->light_packs == NULL) {
  1022. sp_dbg_warn("read ini file failed, %s Main::LightPack", file);
  1023. return rc;
  1024. }
  1025. inst->arr_light_pack = parse_packs(file, inst->light_packs, shm);
  1026. nLastStartTime = inifile_read_int(file, "Main", "CurrentTime", 0);
  1027. inst->current_startup_time = y2k_time_now();
  1028. {
  1029. char tmp[32];
  1030. sprintf(tmp, "0x%08X", inst->current_startup_time);
  1031. inifile_write_str(file, "Main", "CurrentTime", tmp);
  1032. }
  1033. inst->today_run_count = inifile_read_int(file, "Main", "TodayRunCount", 0);
  1034. if (inst->today_run_count >=0)
  1035. {
  1036. if (y2k_time_is_today(nLastStartTime))
  1037. inst->today_run_count++;
  1038. else
  1039. inst->today_run_count = 1;
  1040. inifile_write_int(file, "Main", "TodayRunCount", inst->today_run_count);
  1041. }
  1042. inst->total_run_count = inifile_read_int(file, "Main", "TotalRunCount", 0);
  1043. if (inst->total_run_count >=0)
  1044. {
  1045. inst->total_run_count++;
  1046. inifile_write_int(file, "Main", "TotalRunCount", inst->total_run_count);
  1047. }
  1048. // read all history version
  1049. arr_section = inifile_read_section_all(file);
  1050. if (arr_section) {
  1051. int i;
  1052. inst->arr_version = T_ARRAY_MAKE(0, sizeof(sp_cfg_version_info_t*), shm);
  1053. for (i = 0; i < arr_section->nelts; ++i) {
  1054. char *sec = ARRAY_IDX(arr_section, i, char*);
  1055. if (_stricmp(sec, "Main") != 0) {
  1056. if (isdigit(sec[0]) && ('.' == sec[1] || '.' == sec[2])) //
  1057. { // skip light pack
  1058. sp_cfg_version_info_t *ver_info = T_MALLOC_T(sp_cfg_version_info_t, shm);
  1059. memset(ver_info, 0, sizeof(sp_cfg_version_info_t));
  1060. sscanf(sec, "%d.%d.%d.%d", &ver_info->version.major, &ver_info->version.minor,
  1061. &ver_info->version.revision, &ver_info->version.build);
  1062. rc = read_ini_version(file, sec, "PreviousInstallVersion",
  1063. &ver_info->previous_version.major, &ver_info->previous_version.minor,
  1064. &ver_info->previous_version.revision, &ver_info->previous_version.build);
  1065. if (rc != 0)
  1066. break;
  1067. rc = read_ini_str(file, sec, "InstallPack", &ver_info->install_pack, shm);
  1068. if (rc != 0)
  1069. break;
  1070. // 轻量安装包没有安装历史
  1071. //ver_info->arr_pack = parse_packs(file, ver_info->packs, shm);
  1072. ver_info->switch_time = inifile_read_int(file, sec, "SwitchOverDate", 0);
  1073. ver_info->install_state = read_ini_install_state(file, sec, "InstallState");
  1074. if (ver_info->install_state == -1)
  1075. break;
  1076. if (shm) {
  1077. SHM_ARRAY_PUSH(inst->arr_version, sp_cfg_version_info_t*) = ver_info;
  1078. } else {
  1079. ARRAY_PUSH(inst->arr_version, sp_cfg_version_info_t*) = ver_info;
  1080. }
  1081. }
  1082. }
  1083. }
  1084. toolkit_array_free2(arr_section);
  1085. } else {
  1086. sp_dbg_warn("read ini file failed, %s, section all failed", file);
  1087. return -1;
  1088. }
  1089. //////////////////////////////
  1090. return rc;
  1091. }
  1092. static void unload_install_ini(sp_cfg_install_ini_t *inst, int shm)
  1093. {
  1094. //...
  1095. }
  1096. // c:\run\version\0.0.0.1\bin
  1097. static int is_valid_version_dir(const char *path)
  1098. {
  1099. const char* p = strrchr(path, SPLIT_SLASH) + 1;
  1100. //sp_version_t ver;
  1101. if (p) {
  1102. while (isdigit(*p))
  1103. p++;
  1104. if (*p++ != '.')
  1105. return FALSE;
  1106. while (isdigit(*p))
  1107. p++;
  1108. if (*p++ != '.')
  1109. return FALSE;
  1110. while (isdigit(*p))
  1111. p++;
  1112. if (*p++ != '.')
  1113. return FALSE;
  1114. while (isdigit(*p))
  1115. p++;
  1116. if (*p == '\0')
  1117. return TRUE;
  1118. }
  1119. return FALSE;
  1120. }
  1121. static int generate_install_ini(sp_dir_t *dir)
  1122. {
  1123. char szIniPath[MAX_PATH] = {0};
  1124. sp_version_t active_version = {0};
  1125. int rc;
  1126. sp_version_t last_verion = {0};
  1127. int l = -1;
  1128. char *packs = NULL;
  1129. rc = sp_dir_get_path(dir, SP_DIR_INSTALL_INI, NULL, szIniPath, MAX_PATH);
  1130. assert(rc == 0);
  1131. sscanf(strrchr(dir->base_path, SPLIT_SLASH) + 1, "%d.%d.%d.%d",
  1132. &active_version.major, &active_version.minor, &active_version.revision, &active_version.build);
  1133. //// copy install.ini
  1134. //{
  1135. // array_header_t *arr = fileutil_get_sub_dirs_a(dir->root_ver_path);
  1136. // array_header_t *arr1 = array_make(0, sizeof(const char*));
  1137. //
  1138. // if (arr) {
  1139. // int i;
  1140. // for (i = 0; i < arr->nelts; ++i)
  1141. // {
  1142. // const char *tmp = (const char*)ARRAY_IDX(arr, i, const char*);
  1143. // if (_stricmp(tmp, dir->base_path) != 0) {
  1144. // if (is_valid_version_dir(tmp)) {
  1145. // ARRAY_PUSH(arr1, const char*) = tmp;
  1146. // } else {
  1147. // sp_dbg_warn("caution: %s is not a version dir", tmp);
  1148. // }
  1149. // }
  1150. // }
  1151. // for (i = 0; i < arr1->nelts; ++i)
  1152. // {
  1153. // const char *tmp1 = (const char*)ARRAY_IDX(arr, i, const char*);
  1154. // sp_version_t ver1;
  1155. // sscanf(strrchr(tmp1, '\\')+1, "%d.%d.%d.%d", &ver1.major, &ver1.minor, &ver1.revision, &ver1.build);
  1156. // if (sp_version_cmp(&ver1, &last_verion) > 0) {
  1157. // l = i;
  1158. // sp_version_copy(&last_verion, &ver1);
  1159. // }
  1160. // }
  1161. // toolkit_array_free2(arr);
  1162. // array_free(arr1);
  1163. // }
  1164. // // 找到除当前版本外最大的版本,拷贝对应版本Install.ini
  1165. // if (l != -1) {
  1166. // char tmp[MAX_PATH];
  1167. // char *install_version = NULL;
  1168. // rc = sp_dir_get_path_version(dir, last_verion.major, last_verion.minor, last_verion.revision, last_verion.build, SP_DIR_INSTALL_INI, NULL, tmp, MAX_PATH);
  1169. // if (rc != 0) {
  1170. // sp_dbg_warn("get path version failed!");
  1171. // return rc;
  1172. // }
  1173. // CopyFileA(tmp, szIniPath, TRUE);
  1174. // // 设置前一版本安装链
  1175. // install_version = inifile_read_str(tmp, "Main", "InstallVersion", "");
  1176. // inifile_write_str(tmp, "Main", "LatterInstallVersion", strrchr(dir->base_path, '\\')+1);
  1177. // inifile_write_str(tmp, install_version, "InstallState", "U");
  1178. // toolkit_free(install_version);
  1179. // }
  1180. //}
  1181. // write install.ini main section
  1182. {
  1183. char szVer[128];
  1184. char szNow[128];
  1185. y2k_time_t now;
  1186. sprintf(szVer, "%d.%d.%d.%d", active_version.major, active_version.minor, active_version.revision, active_version.build);
  1187. inifile_write_str(szIniPath, "Main", "InstallVersion", szVer);
  1188. now = y2k_time_now();
  1189. sprintf(szNow, "0x%08X", now);
  1190. inifile_write_str(szIniPath, "Main", "CreateDate", szNow);
  1191. inifile_write_str(szIniPath, "Main", "LatterInstallVersion", "");
  1192. packs = inifile_read_str(szIniPath, "Main", "LightPack", "");
  1193. inifile_write_str(szIniPath, "Main", "LightPack", "");
  1194. inifile_write_str(szIniPath, "Main", "TotalRunCount", "0");
  1195. inifile_write_str(szIniPath, "Main", "TodayRunCount", "0");
  1196. inifile_write_str(szIniPath, "Main", "CurrentTime", szNow);
  1197. if (l != -1)
  1198. {
  1199. char szPreVer[128];
  1200. sprintf(szPreVer, "%d.%d.%d.%d", last_verion.major, last_verion.minor, last_verion.revision, last_verion.build);
  1201. inifile_write_str(szIniPath, szVer, "PreviousInstallVersion", szPreVer);
  1202. }
  1203. inifile_write_str(szIniPath, szVer, "SwitchOverDate", szNow);
  1204. inifile_write_str(szIniPath, szVer, "InstallPack", "");
  1205. inifile_write_str(szIniPath, szVer, "InstallState", "A");
  1206. }
  1207. // 去掉所有历史版本中轻量安装记录
  1208. if (packs)
  1209. {
  1210. if (strlen(packs) >0)
  1211. {
  1212. char *p = NULL;
  1213. while((p = strrchr(packs, ',')) != NULL)
  1214. {
  1215. *p = 0;
  1216. WritePrivateProfileSectionA(p+1, NULL, szIniPath);
  1217. }
  1218. WritePrivateProfileSectionA(packs, NULL, szIniPath);
  1219. }
  1220. toolkit_free(packs);
  1221. }
  1222. return 0;
  1223. }
  1224. int sp_cfg_create(sp_dir_t *dir, const sp_cfg_start_args_t* args, sp_cfg_t **p_cfg)
  1225. {
  1226. sp_cfg_t *cfg;
  1227. int rc = Error_Unexpect;
  1228. char tmp[MAX_PATH], shell_var_path[MAX_PATH];
  1229. char *shellvarPath = NULL;
  1230. cfg = (sp_cfg_t *)shm_malloc(sizeof(sp_cfg_t));
  1231. memset(cfg, 0, sizeof(sp_cfg_t));
  1232. cfg->root_ini = (sp_cfg_root_ini_t *)shm_malloc(sizeof(sp_cfg_root_ini_t));
  1233. memset(cfg->root_ini, 0, sizeof(sp_cfg_root_ini_t));
  1234. cfg->shell_ini = (sp_cfg_shell_ini_t *)shm_malloc(sizeof(sp_cfg_shell_ini_t));
  1235. memset(cfg->shell_ini, 0, sizeof(sp_cfg_shell_ini_t));
  1236. cfg->install_ini = (sp_cfg_install_ini_t*)shm_malloc(sizeof(sp_cfg_install_ini_t));
  1237. memset(cfg->install_ini, 0, sizeof(sp_cfg_install_ini_t));
  1238. cfg->run_info = (sp_cfg_run_info_t*)shm_malloc(sizeof(sp_cfg_run_info_t));
  1239. memset(cfg->run_info, 0, sizeof(sp_cfg_run_info_t));
  1240. {
  1241. cfg->args = (sp_cfg_start_args_t*)shm_malloc(sizeof(sp_cfg_start_args_t));
  1242. memset(cfg->args, 0, sizeof(sp_cfg_start_args_t));
  1243. cfg->args->start_entities = shm_strdup(args->start_entities);
  1244. cfg->args->test_mode = args->test_mode;
  1245. cfg->args->debug_mode = args->debug_mode;
  1246. cfg->args->guardian_mode = args->guardian_mode;
  1247. cfg->args->sign_verifity = args->sign_verifity;
  1248. cfg->args->ipc_type = args->ipc_type;
  1249. }
  1250. cfg->run_info->startup_time = y2k_time_now();
  1251. rc = sp_dir_get_path(dir, SP_DIR_ROOT_INI, NULL, tmp, MAX_PATH);
  1252. if (rc != 0) {
  1253. sp_dbg_warn("get root ini path failed!");
  1254. return rc;
  1255. }
  1256. rc = load_root_ini(dir, cfg->root_ini, tmp, 1);
  1257. if (rc != 0) {
  1258. sp_dbg_warn("load root.ini failed!");
  1259. return rc;
  1260. }
  1261. cfg->root_ini_path = shm_strdup(tmp);
  1262. rc = sp_dir_get_path(dir, SP_DIR_SHELL_INI, NULL, tmp, MAX_PATH);
  1263. if (rc != 0) {
  1264. sp_dbg_warn("get shell.ini path failed!");
  1265. return rc;
  1266. }
  1267. rc = sp_dir_get_path(dir, SP_DIR_SHELLVAR_INI, NULL, shell_var_path, MAX_PATH);
  1268. if (rc != 0) {
  1269. sp_dbg_warn("get shellvar.ini path failed!");
  1270. return rc;
  1271. }
  1272. std::fstream shellVarFile;
  1273. shellVarFile.open(shell_var_path, std::ios::in);
  1274. if (!shellVarFile) {
  1275. /*cannot found shellVar.ini, then create one.*/
  1276. std::ofstream file(shell_var_path, std::fstream::out);
  1277. }
  1278. shellvarPath = shell_var_path;
  1279. /*override*/
  1280. cfg->args->sign_verifity = sp_cfg_get_vertify_sign(dir, cfg->root_ini);
  1281. if (cfg->args->sign_verifity)
  1282. sp_dbg_info("verify code sign required.");
  1283. rc = load_shell_ini(dir, cfg->shell_ini, cfg->args, tmp, shellvarPath);
  1284. if (rc != 0) {
  1285. sp_dbg_warn("load shell.ini failed!");
  1286. return rc;
  1287. }
  1288. cfg->shell_ini_path = shm_strdup(tmp);
  1289. cfg->shellvar_ini_path = shm_strdup(shell_var_path);
  1290. rc = sp_dir_get_path(dir, SP_DIR_INSTALL_INI, NULL, tmp, MAX_PATH);
  1291. if (rc != 0) {
  1292. sp_dbg_warn("get install.ini path failed!");
  1293. return rc;
  1294. }
  1295. cfg->install_ini_path = shm_strdup(tmp);
  1296. if (!ExistsFileA(tmp)) {
  1297. rc = generate_install_ini(dir);
  1298. if (rc != 0) {
  1299. sp_dbg_warn("generate install.ini failed!");
  1300. return rc;
  1301. }
  1302. }
  1303. rc = load_install_ini(dir, cfg->install_ini, tmp, 1);
  1304. if (rc != 0) {
  1305. sp_dbg_warn("load install.ini failed!");
  1306. return rc;
  1307. }
  1308. spinlock_init(&cfg->lock);
  1309. *p_cfg = cfg;
  1310. sp_dbg_info("create cfg object ok! %08x, lock = %d", cfg, cfg->lock);
  1311. rc = 0;
  1312. return rc;
  1313. }
  1314. void sp_cfg_destroy(sp_cfg_t *cfg)
  1315. {
  1316. unload_root_ini(cfg->root_ini, 1);
  1317. unload_shell_ini(cfg->shell_ini);
  1318. unload_install_ini(cfg->install_ini, 1);
  1319. shm_free(cfg->root_ini);
  1320. shm_free(cfg->root_ini_path);
  1321. shm_free(cfg->shell_ini);
  1322. shm_free(cfg->shell_ini_path);
  1323. shm_free(cfg->install_ini);
  1324. shm_free(cfg->args->start_entities);
  1325. shm_free(cfg->args);
  1326. shm_free(cfg);
  1327. }
  1328. void sp_cfg_lock(sp_cfg_t *cfg)
  1329. {
  1330. spinlock_enter(&cfg->lock, 0);
  1331. }
  1332. void sp_cfg_unlock(sp_cfg_t *cfg)
  1333. {
  1334. spinlock_leave(&cfg->lock);
  1335. }
  1336. sp_cfg_shell_entity_t *sp_cfg_get_entity_by_name(sp_cfg_t *cfg, const char *name)
  1337. {
  1338. return find_entity(cfg->shell_ini, name);
  1339. }
  1340. sp_cfg_shell_entity_t *sp_cfg_get_entity_by_idx(sp_cfg_t *cfg, int idx)
  1341. {
  1342. if (idx >= 0 && idx < cfg->shell_ini->arr_entity->nelts) {
  1343. return ARRAY_IDX(cfg->shell_ini->arr_entity, idx, sp_cfg_shell_entity_t*);
  1344. } else {
  1345. return NULL;
  1346. }
  1347. }
  1348. sp_cfg_shell_entity_t *sp_cfg_get_entity_shell(sp_cfg_t *cfg)
  1349. {
  1350. return ARRAY_IDX(cfg->shell_ini->arr_entity, 0, sp_cfg_shell_entity_t*);
  1351. }
  1352. sp_cfg_shell_module_t *sp_cfg_get_module_by_name(sp_cfg_t *cfg, const char *name)
  1353. {
  1354. return find_module(cfg->shell_ini, name);
  1355. }
  1356. sp_cfg_shell_module_t *sp_cfg_get_module_by_idx(sp_cfg_t *cfg, int idx)
  1357. {
  1358. if (idx >= 0 && idx < cfg->shell_ini->arr_module->nelts) {
  1359. return ARRAY_IDX(cfg->shell_ini->arr_module, idx, sp_cfg_shell_module_t*);
  1360. } else {
  1361. return NULL;
  1362. }
  1363. }
  1364. sp_cfg_shell_module_t *sp_cfg_get_module_shell(sp_cfg_t *cfg)
  1365. {
  1366. return ARRAY_IDX(cfg->shell_ini->arr_module, 0, sp_cfg_shell_module_t*);
  1367. }
  1368. sp_cfg_shell_sysevent_t*sp_cfg_get_sysevent(sp_cfg_t *cfg, const char *name)
  1369. {
  1370. array_header_t *arr_sysevent = cfg->shell_ini->arr_sysevent;
  1371. int i;
  1372. for (i = 0; i < arr_sysevent->nelts; ++i) {
  1373. sp_cfg_shell_sysevent_t *tmp = ARRAY_IDX(arr_sysevent, i, sp_cfg_shell_sysevent_t *);
  1374. if (_stricmp(tmp->name, name) == 0)
  1375. return tmp;
  1376. }
  1377. return NULL;
  1378. }
  1379. char *sp_cfg_get_path(sp_cfg_t *cfg, const char *path_prefix)
  1380. {
  1381. sp_cfg_path_t *path = find_path(cfg, path_prefix);
  1382. if (path) {
  1383. return path->path;
  1384. }
  1385. return NULL;
  1386. }
  1387. int sp_cfg_refresh_debug_level(sp_cfg_t *cfg, sp_cfg_shell_entity_t *cfg_ent)
  1388. {
  1389. //TODO: shell.ini cannot be written!!
  1390. char tmp[32];
  1391. _itoa(cfg_ent->debug_level, tmp, 10);
  1392. return WritePrivateProfileStringA("Debug", cfg_ent->name, tmp, cfg->shell_ini_path) ? 0 : Error_IO;
  1393. }
  1394. int sp_cfg_util_read_root_ini_version(sp_cfg_root_ini_t *ini, int major, int minor, int revision, int build)
  1395. {
  1396. char tmp[MAX_PATH];
  1397. sp_env_t *env = sp_get_env();
  1398. sp_dir_get_path_version(env->dir, major, minor, revision, build, SP_DIR_ROOT_INI, NULL, tmp, MAX_PATH);
  1399. return load_root_ini(env->dir, ini, tmp, 0);
  1400. }
  1401. int sp_cfg_util_free_root_ini(sp_cfg_root_ini_t *ini)
  1402. {
  1403. unload_root_ini(ini, 0);
  1404. return 0;
  1405. }
  1406. int sp_cfg_get_devel_id(sp_cfg_t *cfg, int idx)
  1407. {
  1408. sp_env_t *env = sp_get_env();
  1409. sp_cfg_shell_entity_t *cfg_ent = sp_cfg_get_entity_by_idx(env->cfg, idx);
  1410. return cfg_ent->devel_id;
  1411. }
  1412. sp_cfg_version_info_t* sp_cfg_find_previous_version_info(sp_cfg_t *cfg, const sp_version_t *version)
  1413. {
  1414. sp_cfg_version_info_t* ver_info = sp_cfg_find_version_info(cfg, version);
  1415. if (ver_info) {
  1416. sp_version_t *previous_version = &ver_info->previous_version;
  1417. return sp_cfg_find_version_info(cfg, previous_version);
  1418. }
  1419. return NULL;
  1420. }
  1421. sp_cfg_version_info_t* sp_cfg_find_version_info(sp_cfg_t *cfg, const sp_version_t *version)
  1422. {
  1423. int i;
  1424. for (i = 0; i < cfg->install_ini->arr_version->nelts; ++i) {
  1425. sp_cfg_version_info_t *ver_info = ARRAY_IDX(cfg->install_ini->arr_version, i, sp_cfg_version_info_t*);
  1426. //if (sp_version_equal_3(&ver_info->version, version))
  1427. if (sp_version_equal(&ver_info->version, version))
  1428. return ver_info;
  1429. }
  1430. return NULL;
  1431. }
  1432. int sp_cfg_is_pack_installed(sp_cfg_t *cfg, const char*pack)
  1433. {
  1434. // 先查找轻量表历史
  1435. int i;
  1436. for(i =0; i<cfg->install_ini->arr_light_pack->nelts; i++)
  1437. {
  1438. sp_cfg_pack_info_t *pack_info = ARRAY_IDX(cfg->install_ini->arr_light_pack, i, sp_cfg_pack_info_t *);
  1439. if (stricmp(pack_info->name, pack) == 0)
  1440. return 0;
  1441. }
  1442. // 再查找版本安装包
  1443. for (i = 0; i < cfg->install_ini->arr_version->nelts; ++i)
  1444. {
  1445. sp_cfg_version_info_t *ver_info = ARRAY_IDX(cfg->install_ini->arr_version, i, sp_cfg_version_info_t*);
  1446. if (stricmp(ver_info->install_pack, pack) ==0)
  1447. return 0;
  1448. }
  1449. return 1;
  1450. }