regex_mod.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * $Id$
  3. *
  4. * regex module - pcre operations
  5. *
  6. * Copyright (C) 2008 Iñaki Baz Castillo
  7. *
  8. * This file is part of Kamailio, a free SIP server.
  9. *
  10. * Kamailio is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * Kamailio is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * History:
  25. * --------
  26. * 2011-02-22 pcre_match_group() allows now pseudo-variable as group argument.
  27. * 2009-01-14 initial version (Iñaki Baz Castillo).
  28. */
  29. /*!
  30. * \file
  31. * \brief REGEX :: Perl-compatible regular expressions using PCRE library
  32. * Copyright (C) 2008 Iñaki Baz Castillo
  33. * \ingroup regex
  34. */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <sys/stat.h>
  39. #include <pcre.h>
  40. #include "../../sr_module.h"
  41. #include "../../dprint.h"
  42. #include "../../pt.h"
  43. #include "../../mem/shm_mem.h"
  44. #include "../../str.h"
  45. #include "../../locking.h"
  46. #include "../../mod_fix.h"
  47. #include "../../lib/kmi/mi.h"
  48. MODULE_VERSION
  49. #define START 0
  50. #define RELOAD 1
  51. #define FILE_MAX_LINE 500 /*!< Max line size in the file */
  52. #define MAX_GROUPS 20 /*!< Max number of groups */
  53. #define GROUP_MAX_SIZE 8192 /*!< Max size of a group */
  54. /*
  55. * Locking variables
  56. */
  57. gen_lock_t *reload_lock;
  58. /*
  59. * Module exported parameter variables
  60. */
  61. static char *file;
  62. static int max_groups = MAX_GROUPS;
  63. static int group_max_size = GROUP_MAX_SIZE;
  64. static int pcre_caseless = 0;
  65. static int pcre_multiline = 0;
  66. static int pcre_dotall = 0;
  67. static int pcre_extended = 0;
  68. /*
  69. * Module internal parameter variables
  70. */
  71. static pcre **pcres;
  72. static pcre ***pcres_addr;
  73. static int *num_pcres;
  74. static int pcre_options = 0x00000000;
  75. /*
  76. * Module core functions
  77. */
  78. static int mod_init(void);
  79. static void destroy(void);
  80. /*
  81. * Module internal functions
  82. */
  83. static int load_pcres(int);
  84. static void free_shared_memory(void);
  85. /*
  86. * Script functions
  87. */
  88. static int w_pcre_match(struct sip_msg* _msg, char* _s1, char* _s2);
  89. static int w_pcre_match_group(struct sip_msg* _msg, char* _s1, char* _s2);
  90. /*
  91. * MI functions
  92. */
  93. static struct mi_root* mi_pcres_reload(struct mi_root* cmd, void* param);
  94. /*
  95. * Exported functions
  96. */
  97. static cmd_export_t cmds[] =
  98. {
  99. { "pcre_match", (cmd_function)w_pcre_match, 2, fixup_spve_spve, 0,
  100. REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
  101. { "pcre_match_group", (cmd_function)w_pcre_match_group, 2, fixup_spve_spve, 0,
  102. REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
  103. { "pcre_match_group", (cmd_function)w_pcre_match_group, 1, fixup_spve_null, 0,
  104. REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
  105. { 0, 0, 0, 0, 0, 0 }
  106. };
  107. /*
  108. * Exported parameters
  109. */
  110. static param_export_t params[] = {
  111. {"file", PARAM_STRING, &file },
  112. {"max_groups", INT_PARAM, &max_groups },
  113. {"group_max_size", INT_PARAM, &group_max_size },
  114. {"pcre_caseless", INT_PARAM, &pcre_caseless },
  115. {"pcre_multiline", INT_PARAM, &pcre_multiline },
  116. {"pcre_dotall", INT_PARAM, &pcre_dotall },
  117. {"pcre_extended", INT_PARAM, &pcre_extended },
  118. {0, 0, 0}
  119. };
  120. /*
  121. * Exported MI functions
  122. */
  123. static mi_export_t mi_cmds[] = {
  124. { "regex_reload", mi_pcres_reload, MI_NO_INPUT_FLAG, 0, 0 },
  125. { 0, 0, 0, 0 ,0 }
  126. };
  127. /*
  128. * Module interface
  129. */
  130. struct module_exports exports = {
  131. "regex", /*!< module name */
  132. DEFAULT_DLFLAGS, /*!< dlopen flags */
  133. cmds, /*!< exported functions */
  134. params, /*!< exported parameters */
  135. 0, /*!< exported statistics */
  136. mi_cmds, /*!< exported MI functions */
  137. 0, /*!< exported pseudo-variables */
  138. 0, /*!< extra processes */
  139. mod_init, /*!< module initialization function */
  140. (response_function) 0, /*!< response handling function */
  141. destroy, /*!< destroy function */
  142. 0 /*!< per-child init function */
  143. };
  144. /*! \brief
  145. * Init module function
  146. */
  147. static int mod_init(void)
  148. {
  149. if(register_mi_mod(exports.name, mi_cmds)!=0)
  150. {
  151. LM_ERR("failed to register MI commands\n");
  152. return -1;
  153. }
  154. /* Group matching feature */
  155. if (file == NULL) {
  156. LM_NOTICE("'file' parameter is not set, group matching disabled\n");
  157. } else {
  158. /* Create and init the lock */
  159. reload_lock = lock_alloc();
  160. if (reload_lock == NULL) {
  161. LM_ERR("cannot allocate reload_lock\n");
  162. goto err;
  163. }
  164. if (lock_init(reload_lock) == NULL) {
  165. LM_ERR("cannot init the reload_lock\n");
  166. lock_dealloc(reload_lock);
  167. goto err;
  168. }
  169. /* PCRE options */
  170. if (pcre_caseless != 0) {
  171. LM_DBG("PCRE CASELESS enabled\n");
  172. pcre_options = pcre_options | PCRE_CASELESS;
  173. }
  174. if (pcre_multiline != 0) {
  175. LM_DBG("PCRE MULTILINE enabled\n");
  176. pcre_options = pcre_options | PCRE_MULTILINE;
  177. }
  178. if (pcre_dotall != 0) {
  179. LM_DBG("PCRE DOTALL enabled\n");
  180. pcre_options = pcre_options | PCRE_DOTALL;
  181. }
  182. if (pcre_extended != 0) {
  183. LM_DBG("PCRE EXTENDED enabled\n");
  184. pcre_options = pcre_options | PCRE_EXTENDED;
  185. }
  186. LM_DBG("PCRE options: %i\n", pcre_options);
  187. /* Pointer to pcres */
  188. if ((pcres_addr = shm_malloc(sizeof(pcre **))) == 0) {
  189. LM_ERR("no memory for pcres_addr\n");
  190. goto err;
  191. }
  192. /* Integer containing the number of pcres */
  193. if ((num_pcres = shm_malloc(sizeof(int))) == 0) {
  194. LM_ERR("no memory for num_pcres\n");
  195. goto err;
  196. }
  197. /* Load the pcres */
  198. LM_DBG("loading pcres...\n");
  199. if (load_pcres(START)) {
  200. LM_ERR("failed to load pcres\n");
  201. goto err;
  202. }
  203. }
  204. return 0;
  205. err:
  206. free_shared_memory();
  207. return -1;
  208. }
  209. static void destroy(void)
  210. {
  211. free_shared_memory();
  212. }
  213. /*! \brief Convert the file content into regular expresions and store them in pcres */
  214. static int load_pcres(int action)
  215. {
  216. int i, j;
  217. FILE *f;
  218. char line[FILE_MAX_LINE];
  219. char **patterns = NULL;
  220. pcre *pcre_tmp = NULL;
  221. size_t pcre_size;
  222. int pcre_rc;
  223. const char *pcre_error;
  224. int pcre_erroffset;
  225. int num_pcres_tmp = 0;
  226. pcre **pcres_tmp = NULL;
  227. /* Get the lock */
  228. lock_get(reload_lock);
  229. if (!(f = fopen(file, "r"))) {
  230. LM_ERR("could not open file '%s'\n", file);
  231. goto err;
  232. }
  233. /* Array containing each pattern in the file */
  234. if ((patterns = pkg_malloc(sizeof(char*) * max_groups)) == 0) {
  235. LM_ERR("no more memory for patterns\n");
  236. fclose(f);
  237. goto err;
  238. }
  239. memset(patterns, 0, sizeof(char*) * max_groups);
  240. for (i=0; i<max_groups; i++) {
  241. if ((patterns[i] = pkg_malloc(sizeof(char) * group_max_size)) == 0) {
  242. LM_ERR("no more memory for patterns[%d]\n", i);
  243. fclose(f);
  244. goto err;
  245. }
  246. memset(patterns[i], '\0', group_max_size);
  247. }
  248. /* Read the file and extract the patterns */
  249. memset(line, '\0', FILE_MAX_LINE);
  250. i = -1;
  251. while (fgets(line, FILE_MAX_LINE, f) != NULL) {
  252. /* Ignore comments and lines starting by space, tab, CR, LF */
  253. if(isspace(line[0]) || line[0]=='#') {
  254. memset(line, '\0', FILE_MAX_LINE);
  255. continue;
  256. }
  257. /* First group */
  258. if (i == -1 && line[0] != '[') {
  259. LM_ERR("first group must be initialized with [0] before any regular expression\n");
  260. fclose(f);
  261. goto err;
  262. }
  263. /* New group */
  264. if (line[0] == '[') {
  265. i++;
  266. /* Check if there are more patterns than the max value */
  267. if (i >= max_groups) {
  268. LM_ERR("max patterns exceeded\n");
  269. fclose(f);
  270. goto err;
  271. }
  272. /* Start the regular expression with '(' */
  273. patterns[i][0] = '(';
  274. memset(line, '\0', FILE_MAX_LINE);
  275. continue;
  276. }
  277. /* Check if the patter size is too big (aprox) */
  278. if (strlen(patterns[i]) + strlen(line) >= group_max_size - 2) {
  279. LM_ERR("pattern max file exceeded\n");
  280. fclose(f);
  281. goto err;
  282. }
  283. /* Append ')' at the end of the line */
  284. if (line[strlen(line) - 1] == '\n') {
  285. line[strlen(line)] = line[strlen(line) - 1];
  286. line[strlen(line) - 2] = ')';
  287. } else {
  288. /* This is the last char in the file and it's not \n */
  289. line[strlen(line)] = ')';
  290. }
  291. /* Append '(' at the beginning of the line */
  292. memcpy(patterns[i]+strlen(patterns[i]), "(", 1);
  293. /* Append the line to the current pattern */
  294. memcpy(patterns[i]+strlen(patterns[i]), line, strlen(line));
  295. memset(line, '\0', FILE_MAX_LINE);
  296. }
  297. num_pcres_tmp = i + 1;
  298. fclose(f);
  299. if(num_pcres_tmp==0) {
  300. LM_ERR("no expressions in the file\n");
  301. goto err;
  302. }
  303. /* Fix the patterns */
  304. for (i=0; i < num_pcres_tmp; i++) {
  305. /* Convert empty groups in unmatcheable regular expression ^$ */
  306. if (strlen(patterns[i]) == 1) {
  307. patterns[i][0] = '^';
  308. patterns[i][1] = '$';
  309. patterns[i][2] = '\0';
  310. continue;
  311. }
  312. /* Delete possible '\n' at the end of the pattern */
  313. if (patterns[i][strlen(patterns[i])-1] == '\n') {
  314. patterns[i][strlen(patterns[i])-1] = '\0';
  315. }
  316. /* Replace '\n' with '|' (except at the end of the pattern) */
  317. for (j=0; j < strlen(patterns[i]); j++) {
  318. if (patterns[i][j] == '\n' && j != strlen(patterns[i])-1) {
  319. patterns[i][j] = '|';
  320. }
  321. }
  322. /* Add ')' at the end of the pattern */
  323. patterns[i][strlen(patterns[i])] = ')';
  324. }
  325. /* Log the group patterns */
  326. LM_INFO("num groups = %d\n", num_pcres_tmp);
  327. for (i=0; i < num_pcres_tmp; i++) {
  328. LM_INFO("<group[%d]>%s</group[%d]> (size = %i)\n", i, patterns[i], i, (int)strlen(patterns[i]));
  329. }
  330. /* Temporal pointer of pcres */
  331. if ((pcres_tmp = pkg_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
  332. LM_ERR("no more memory for pcres_tmp\n");
  333. goto err;
  334. }
  335. for (i=0; i<num_pcres_tmp; i++) {
  336. pcres_tmp[i] = NULL;
  337. }
  338. /* Compile the patters */
  339. for (i=0; i<num_pcres_tmp; i++) {
  340. pcre_tmp = pcre_compile(patterns[i], pcre_options, &pcre_error, &pcre_erroffset, NULL);
  341. if (pcre_tmp == NULL) {
  342. LM_ERR("pcre_tmp compilation of '%s' failed at offset %d: %s\n", patterns[i], pcre_erroffset, pcre_error);
  343. goto err;
  344. }
  345. pcre_rc = pcre_fullinfo(pcre_tmp, NULL, PCRE_INFO_SIZE, &pcre_size);
  346. if (pcre_rc) {
  347. printf("pcre_fullinfo on compiled pattern[%i] yielded error: %d\n", i, pcre_rc);
  348. goto err;
  349. }
  350. if ((pcres_tmp[i] = pkg_malloc(pcre_size)) == 0) {
  351. LM_ERR("no more memory for pcres_tmp[%i]\n", i);
  352. goto err;
  353. }
  354. memcpy(pcres_tmp[i], pcre_tmp, pcre_size);
  355. pcre_free(pcre_tmp);
  356. pkg_free(patterns[i]);
  357. patterns[i] = NULL;
  358. }
  359. /* Copy to shared memory */
  360. if (action == RELOAD) {
  361. for(i=0; i<*num_pcres; i++) { /* Use the previous num_pcres value */
  362. if (pcres[i]) {
  363. shm_free(pcres[i]);
  364. }
  365. }
  366. shm_free(pcres);
  367. }
  368. if ((pcres = shm_malloc(sizeof(pcre *) * num_pcres_tmp)) == 0) {
  369. LM_ERR("no more memory for pcres\n");
  370. goto err;
  371. }
  372. for (i=0; i<num_pcres_tmp; i++) {
  373. pcres[i] = NULL;
  374. }
  375. for (i=0; i<num_pcres_tmp; i++) {
  376. pcre_rc = pcre_fullinfo(pcres_tmp[i], NULL, PCRE_INFO_SIZE, &pcre_size);
  377. if ((pcres[i] = shm_malloc(pcre_size)) == 0) {
  378. LM_ERR("no more memory for pcres[%i]\n", i);
  379. goto err;
  380. }
  381. memcpy(pcres[i], pcres_tmp[i], pcre_size);
  382. }
  383. *num_pcres = num_pcres_tmp;
  384. *pcres_addr = pcres;
  385. /* Free used memory */
  386. for (i=0; i<num_pcres_tmp; i++) {
  387. pkg_free(pcres_tmp[i]);
  388. }
  389. pkg_free(pcres_tmp);
  390. pkg_free(patterns);
  391. lock_release(reload_lock);
  392. return 0;
  393. err:
  394. if (patterns) {
  395. for(i=0; i<max_groups; i++) {
  396. if (patterns[i]) {
  397. pkg_free(patterns[i]);
  398. }
  399. }
  400. pkg_free(patterns);
  401. }
  402. if (pcres_tmp) {
  403. for (i=0; i<num_pcres_tmp; i++) {
  404. if (pcres_tmp[i]) {
  405. pkg_free(pcres_tmp[i]);
  406. }
  407. }
  408. pkg_free(pcres_tmp);
  409. }
  410. if (reload_lock) {
  411. lock_release(reload_lock);
  412. }
  413. if (action == START) {
  414. free_shared_memory();
  415. }
  416. return -1;
  417. }
  418. static void free_shared_memory(void)
  419. {
  420. int i;
  421. if (pcres) {
  422. for(i=0; i<*num_pcres; i++) {
  423. if (pcres[i]) {
  424. shm_free(pcres[i]);
  425. }
  426. }
  427. shm_free(pcres);
  428. pcres = NULL;
  429. }
  430. if (num_pcres) {
  431. shm_free(num_pcres);
  432. num_pcres = NULL;
  433. }
  434. if (pcres_addr) {
  435. shm_free(pcres_addr);
  436. pcres_addr = NULL;
  437. }
  438. if (reload_lock) {
  439. lock_destroy(reload_lock);
  440. lock_dealloc(reload_lock);
  441. reload_lock = NULL;
  442. }
  443. }
  444. /*
  445. * Script functions
  446. */
  447. /*! \brief Return true if the argument matches the regular expression parameter */
  448. static int w_pcre_match(struct sip_msg* _msg, char* _s1, char* _s2)
  449. {
  450. str string;
  451. str regex;
  452. pcre *pcre_re = NULL;
  453. int pcre_rc;
  454. const char *pcre_error;
  455. int pcre_erroffset;
  456. if (_s1 == NULL) {
  457. LM_ERR("bad parameters\n");
  458. return -2;
  459. }
  460. if (_s2 == NULL) {
  461. LM_ERR("bad parameters\n");
  462. return -2;
  463. }
  464. if (fixup_get_svalue(_msg, (gparam_p)_s1, &string))
  465. {
  466. LM_ERR("cannot print the format for string\n");
  467. return -3;
  468. }
  469. if (fixup_get_svalue(_msg, (gparam_p)_s2, &regex))
  470. {
  471. LM_ERR("cannot print the format for regex\n");
  472. return -3;
  473. }
  474. pcre_re = pcre_compile(regex.s, pcre_options, &pcre_error, &pcre_erroffset, NULL);
  475. if (pcre_re == NULL) {
  476. LM_ERR("pcre_re compilation of '%s' failed at offset %d: %s\n", regex.s, pcre_erroffset, pcre_error);
  477. return -4;
  478. }
  479. pcre_rc = pcre_exec(
  480. pcre_re, /* the compiled pattern */
  481. NULL, /* no extra data - we didn't study the pattern */
  482. string.s, /* the matching string */
  483. (int)(string.len), /* the length of the subject */
  484. 0, /* start at offset 0 in the string */
  485. 0, /* default options */
  486. NULL, /* output vector for substring information */
  487. 0); /* number of elements in the output vector */
  488. /* Matching failed: handle error cases */
  489. if (pcre_rc < 0) {
  490. switch(pcre_rc) {
  491. case PCRE_ERROR_NOMATCH:
  492. LM_DBG("'%s' doesn't match '%s'\n", string.s, regex.s);
  493. break;
  494. default:
  495. LM_DBG("matching error '%d'\n", pcre_rc);
  496. break;
  497. }
  498. pcre_free(pcre_re);
  499. return -1;
  500. }
  501. pcre_free(pcre_re);
  502. LM_DBG("'%s' matches '%s'\n", string.s, regex.s);
  503. return 1;
  504. }
  505. /*! \brief Return true if the string argument matches the pattern group parameter */
  506. static int w_pcre_match_group(struct sip_msg* _msg, char* _s1, char* _s2)
  507. {
  508. str string, group;
  509. unsigned int num_pcre;
  510. int pcre_rc;
  511. /* Check if group matching feature is enabled */
  512. if (file == NULL) {
  513. LM_ERR("group matching is disabled\n");
  514. return -2;
  515. }
  516. if (_s1 == NULL) {
  517. LM_ERR("bad parameters\n");
  518. return -3;
  519. }
  520. if (_s2 == NULL) {
  521. num_pcre = 0;
  522. } else {
  523. if (fixup_get_svalue(_msg, (gparam_p)_s2, &group))
  524. {
  525. LM_ERR("cannot print the format for second param\n");
  526. return -5;
  527. }
  528. str2int(&group, &num_pcre);
  529. }
  530. if (num_pcre >= *num_pcres) {
  531. LM_ERR("invalid pcre index '%i', there are %i pcres\n", num_pcre, *num_pcres);
  532. return -4;
  533. }
  534. if (fixup_get_svalue(_msg, (gparam_p)_s1, &string))
  535. {
  536. LM_ERR("cannot print the format for first param\n");
  537. return -5;
  538. }
  539. lock_get(reload_lock);
  540. pcre_rc = pcre_exec(
  541. (*pcres_addr)[num_pcre], /* the compiled pattern */
  542. NULL, /* no extra data - we didn't study the pattern */
  543. string.s, /* the matching string */
  544. (int)(string.len), /* the length of the subject */
  545. 0, /* start at offset 0 in the string */
  546. 0, /* default options */
  547. NULL, /* output vector for substring information */
  548. 0); /* number of elements in the output vector */
  549. lock_release(reload_lock);
  550. /* Matching failed: handle error cases */
  551. if (pcre_rc < 0) {
  552. switch(pcre_rc) {
  553. case PCRE_ERROR_NOMATCH:
  554. LM_DBG("'%s' doesn't match pcres[%i]\n", string.s, num_pcre);
  555. break;
  556. default:
  557. LM_DBG("matching error '%d'\n", pcre_rc);
  558. break;
  559. }
  560. return -1;
  561. }
  562. else {
  563. LM_DBG("'%s' matches pcres[%i]\n", string.s, num_pcre);
  564. return 1;
  565. }
  566. }
  567. /*
  568. * MI functions
  569. */
  570. /*! \brief Reload pcres by reading the file again */
  571. static struct mi_root* mi_pcres_reload(struct mi_root* cmd, void* param)
  572. {
  573. /* Check if group matching feature is enabled */
  574. if (file == NULL) {
  575. LM_NOTICE("'file' parameter is not set, group matching disabled\n");
  576. return init_mi_tree(403, MI_SSTR("Group matching not enabled"));
  577. }
  578. LM_INFO("reloading pcres...\n");
  579. if (load_pcres(RELOAD)) {
  580. LM_ERR("failed to reload pcres\n");
  581. return init_mi_tree(500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
  582. }
  583. LM_INFO("reload success\n");
  584. return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
  585. }