http_server.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. #include "lwip/opt.h"
  2. #include "lwip/arch.h"
  3. #include "lwip/api.h"
  4. #include "lwip/tcp.h"
  5. #include "http_server.h"
  6. #include "web_params_api.h"
  7. #include "parameters.h"
  8. #include "trap_params.h"
  9. #include "fsdata.c"
  10. #include "settings_api.h"
  11. #include "netconf.h"
  12. #include "common_config.h"
  13. //#include "testing.h"
  14. #include "rtc.h"
  15. #ifdef PRINTF_STDLIB
  16. #include <stdio.h>
  17. #endif
  18. #ifdef PRINTF_CUSTOM
  19. #include "tinystdio.h"
  20. #endif
  21. #include <string.h>
  22. #include <stdlib.h>
  23. static int fs_open(char *name, struct fs_file *file);
  24. static err_t http_sent(void *arg, struct tcp_pcb *pcb, u16_t len);
  25. static void send_data(struct tcp_pcb *pcb, struct http_state *hs);
  26. SET_PAGE_t SET_PAGE = SET_PAGE_IDLE;
  27. #define SEND_BUF_MAX_LEN 2000
  28. #define RECIVE_BUF_MAX_LEN 1500
  29. char sendBuf[SEND_BUF_MAX_LEN];
  30. uint16_t sendBufLoadLen = 0;
  31. uint16_t printLen = 0;
  32. //char printBuf[1000];
  33. char receiveBuf[RECIVE_BUF_MAX_LEN];
  34. uint16_t receivedBufLen = 0;
  35. /**
  36. * @brief closes tcp connection
  37. * @param pcb: pointer to a tcp_pcb struct
  38. * @param hs: pointer to a http_state struct
  39. * @retval
  40. */
  41. static void close_conn(struct tcp_pcb *pcb, struct http_state *hs)
  42. {
  43. tcp_arg(pcb, NULL);
  44. tcp_sent(pcb, NULL);
  45. tcp_recv(pcb, NULL);
  46. mem_free(hs);
  47. tcp_close(pcb);
  48. }
  49. /**
  50. * @brief callback function for handling TCP HTTP traffic
  51. * @param arg: pointer to an argument structure to be passed to callback function
  52. * @param pcb: pointer to a tcp_pcb structure
  53. * @param p: pointer to a packet buffer
  54. * @param err: LwIP error code
  55. * @retval err
  56. */
  57. static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
  58. {
  59. char *data;
  60. struct http_state *hs;
  61. struct fs_file file = {0, 0};
  62. hs = arg;
  63. if (err == ERR_OK && p != NULL)
  64. {
  65. tcp_recved(pcb, p->tot_len);
  66. if (hs->file == NULL)
  67. {
  68. data = p->payload;
  69. /*
  70. printLen = p->tot_len;
  71. memcpy(printBuf, p->payload , printLen);
  72. printf(printBuf);
  73. */
  74. receivedBufLen = p->tot_len;
  75. memcpy(receiveBuf, p->payload , receivedBufLen);
  76. if (strncmp(data, "GET /main.css", 13) == 0) // +
  77. {
  78. fs_open("/main.css", &file);
  79. hs->file = file.data;
  80. hs->left = file.len;
  81. send_data(pcb, hs);
  82. tcp_sent(pcb, http_sent);
  83. }
  84. else if (strncmp(data, "GET /rotek.png", 14) == 0) // +
  85. {
  86. fs_open("/rotek.png", &file);
  87. hs->file = file.data;
  88. hs->left = file.len;
  89. send_data(pcb, hs);
  90. tcp_sent(pcb, http_sent);
  91. }
  92. else if (strncmp(data, "GET /favicon.ico", 16) == 0) // ?
  93. {
  94. fs_open("/favicon.ico", &file);
  95. hs->file = file.data;
  96. hs->left = file.len;
  97. send_data(pcb, hs);
  98. tcp_sent(pcb, http_sent);
  99. }
  100. else if (strncmp(data, "GET /main.js", 12) == 0) // +
  101. {
  102. fs_open("/main.js", &file);
  103. hs->file = file.data;
  104. hs->left = file.len;
  105. send_data(pcb, hs);
  106. tcp_sent(pcb, http_sent);
  107. }
  108. else if (strncmp(data, "GET /settings.html", 18) == 0) // +
  109. {
  110. fs_open("/settings.html", &file);
  111. hs->file = file.data;
  112. hs->left = file.len;
  113. send_data(pcb, hs);
  114. tcp_sent(pcb, http_sent);
  115. }
  116. else if (strncmp(data, "GET /info.html", 14) == 0) // +
  117. {
  118. fs_open("/info.html", &file);
  119. hs->file = file.data;
  120. hs->left = file.len;
  121. send_data(pcb, hs);
  122. tcp_sent(pcb, http_sent);
  123. }
  124. else if (strncmp(data, "GET /getJson.cgi", 16) == 0) // +
  125. {
  126. HTTP_GetParamsPage1(sendBuf);
  127. hs->file = sendBuf;
  128. hs->left = strlen(sendBuf);
  129. send_data(pcb, hs);
  130. tcp_sent(pcb, http_sent);
  131. }
  132. else if (strncmp(data, "GET /settings.cgi", 17) == 0) // +
  133. {
  134. SET_PAGE = SET_PAGE_PAGE2;
  135. if (HTTP_SettingsPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen) == SEND_REQUIRED_YES)
  136. {
  137. hs->file = sendBuf;
  138. hs->left = sendBufLoadLen;
  139. send_data(pcb, hs);
  140. tcp_sent(pcb, http_sent);
  141. }
  142. else
  143. {
  144. fs_open("/settings.html", &file);
  145. hs->file = file.data;
  146. hs->left = file.len;
  147. send_data(pcb, hs);
  148. tcp_sent(pcb, http_sent);
  149. }
  150. }
  151. else if (strncmp(data, "GET /info.cgi", 13) == 0) // +
  152. {
  153. if (HTTP_InfoPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen) == SEND_REQUIRED_YES)
  154. {
  155. hs->file = sendBuf;
  156. hs->left = sendBufLoadLen;
  157. send_data(pcb, hs);
  158. tcp_sent(pcb, http_sent);
  159. }
  160. else
  161. {
  162. fs_open("/info.html", &file);
  163. hs->file = file.data;
  164. hs->left = file.len;
  165. send_data(pcb, hs);
  166. tcp_sent(pcb, http_sent);
  167. }
  168. }
  169. /* Сброс настроек и сохранине */
  170. else if (strncmp(data, "GET /reset.cgi", 14) == 0)
  171. {
  172. HTTP_ResetSettings();
  173. HTTP_SaveSettings();
  174. fs_open("/settings.html", &file);
  175. hs->file = file.data;
  176. hs->left = file.len;
  177. send_data(pcb, hs);
  178. tcp_sent(pcb, http_sent);
  179. }
  180. /* Перезагрузка контроллера */
  181. else if (strncmp(data, "GET /reboot.cgi", 15) == 0)
  182. {
  183. HTTP_Reboot();
  184. }
  185. /* Подтверждение новых сетевых настроек */
  186. else if (strncmp(data, "GET /confirm.cgi", 16) == 0)
  187. {
  188. SetWebReinitFlag(false);
  189. SetConfirmWebParamsFlag();
  190. fs_open("/index.html", &file);
  191. hs->file = file.data;
  192. hs->left = file.len;
  193. send_data(pcb, hs);
  194. tcp_sent(pcb, http_sent);
  195. }
  196. /* Проверка пароля, переход в bootloader */
  197. else if (strncmp(data, "POST /checkpwd.cgi", 18) == 0)
  198. {
  199. HTTP_ConfirmBootPwd(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
  200. hs->file = sendBuf;
  201. hs->left = sendBufLoadLen;
  202. send_data(pcb, hs);
  203. tcp_sent(pcb, http_sent);
  204. }
  205. // На производстве
  206. else if (strncmp(data, "GET /setProdate.cgi", 19) == 0)
  207. {
  208. HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
  209. hs->file = sendBuf;
  210. hs->left = sendBufLoadLen;
  211. send_data(pcb, hs);
  212. tcp_sent(pcb, http_sent);
  213. }
  214. // На производстве
  215. else if (strncmp(data, "GET /progon.cgi", 15) == 0)
  216. {
  217. HTTP_Progon(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
  218. hs->file = sendBuf;
  219. hs->left = sendBufLoadLen;
  220. send_data(pcb, hs);
  221. tcp_sent(pcb, http_sent);
  222. }
  223. else
  224. {
  225. fs_open("/index.html", &file); // +
  226. hs->file = file.data;
  227. hs->left = file.len;
  228. send_data(pcb, hs);
  229. tcp_sent(pcb, http_sent);
  230. }
  231. }
  232. pbuf_free(p);
  233. close_conn(pcb,hs);
  234. }
  235. if (err == ERR_OK && p == NULL)
  236. {
  237. close_conn(pcb, hs);
  238. }
  239. return ERR_OK;
  240. }
  241. /**
  242. * @brief callback function for handling connection errors
  243. * @param arg: pointer to an argument to be passed to callback function
  244. * @param err: LwIP error code
  245. * @retval none
  246. */
  247. static void conn_err(void *arg, err_t err)
  248. {
  249. struct http_state *hs;
  250. hs = arg;
  251. mem_free(hs);
  252. }
  253. /**
  254. * @brief callback function called after a successfull TCP data packet transmission
  255. * @param arg: pointer to an argument to be passed to callback function
  256. * @param pcb: pointer on tcp_pcb structure
  257. * @param len
  258. * @retval err : LwIP error code
  259. */
  260. static err_t http_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
  261. {
  262. struct http_state *hs;
  263. hs = arg;
  264. if (hs->left > 0)
  265. {
  266. send_data(pcb, hs);
  267. }
  268. else
  269. {
  270. close_conn(pcb, hs);
  271. }
  272. return ERR_OK;
  273. }
  274. /**
  275. * @brief sends data found in member "file" of a http_state struct
  276. * @param pcb: pointer to a tcp_pcb struct
  277. * @param hs: pointer to a http_state struct
  278. * @retval none
  279. */
  280. static void send_data(struct tcp_pcb *pcb, struct http_state *hs)
  281. {
  282. err_t err;
  283. u16_t len;
  284. /* We cannot send more data than space available in the send
  285. buffer */
  286. if (tcp_sndbuf(pcb) < hs->left)
  287. {
  288. len = tcp_sndbuf(pcb);
  289. }
  290. else
  291. {
  292. len = hs->left;
  293. }
  294. err = tcp_write(pcb, hs->file, len, 0);
  295. if (err == ERR_OK)
  296. {
  297. hs->file += len;
  298. hs->left -= len;
  299. }
  300. }
  301. /**
  302. * @brief tcp poll callback function
  303. * @param arg: pointer to an argument to be passed to callback function
  304. * @param pcb: pointer on tcp_pcb structure
  305. * @retval err_t
  306. */
  307. static err_t http_poll(void *arg, struct tcp_pcb *pcb)
  308. {
  309. if (arg == NULL)
  310. {
  311. tcp_close(pcb);
  312. }
  313. else
  314. {
  315. send_data(pcb, (struct http_state *)arg);
  316. }
  317. return ERR_OK;
  318. }
  319. /**
  320. * @brief callback function on TCP connection setup ( on port 80)
  321. * @param arg: pointer to an argument structure to be passed to callback function
  322. * @param pcb: pointer to a tcp_pcb structure
  323. * &param err: Lwip stack error code
  324. * @retval err
  325. */
  326. static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
  327. {
  328. struct http_state *hs;
  329. /* Allocate memory for the structure that holds the state of the connection */
  330. hs = mem_malloc(sizeof(struct http_state));
  331. if (hs == NULL)
  332. {
  333. return ERR_MEM;
  334. }
  335. /* Initialize the structure. */
  336. hs->file = NULL;
  337. hs->left = 0;
  338. /* Tell TCP that this is the structure we wish to be passed for our
  339. callbacks. */
  340. tcp_arg(pcb, hs);
  341. /* Tell TCP that we wish to be informed of incoming data by a call
  342. to the http_recv() function. */
  343. tcp_recv(pcb, http_recv);
  344. tcp_err(pcb, conn_err);
  345. tcp_poll(pcb, http_poll, 10);
  346. return ERR_OK;
  347. }
  348. /**
  349. * @brief Opens a file defined in fsdata.c ROM filesystem
  350. * @param name : pointer to a file name
  351. * @param file : pointer to a fs_file structure
  352. * @retval 1 if success, 0 if fail
  353. */
  354. static int fs_open(char *name, struct fs_file *file)
  355. {
  356. struct fsdata_file_noconst *f;
  357. for (f = (struct fsdata_file_noconst *)FS_ROOT; f != NULL; f = (struct fsdata_file_noconst *)f->next)
  358. {
  359. if (!strcmp(name, f->name))
  360. {
  361. file->data = f->data;
  362. file->len = f->len;
  363. return 1;
  364. }
  365. }
  366. return 0;
  367. }
  368. /**
  369. * @brief Initialize the HTTP server (start its thread)
  370. * @param none
  371. * @retval None
  372. */
  373. void HTTP_Init()
  374. {
  375. //sys_thread_new("HTTP", http_server_netconn_thread, NULL, 3000, 2);
  376. struct tcp_pcb *pcb;
  377. /*create new pcb*/
  378. pcb = tcp_new();
  379. /* bind HTTP traffic to pcb */
  380. tcp_bind(pcb, IP_ADDR_ANY, 80);
  381. /* start listening on port 80 */
  382. pcb = tcp_listen(pcb);
  383. /* define callback function for TCP connection setup */
  384. tcp_accept(pcb, http_accept);
  385. }
  386. /**
  387. * @brief
  388. * @retval None
  389. */
  390. int HTTP_SettingsPage(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
  391. {
  392. char tempStr[30];
  393. strncpy(tempStr, bufIn, 30);
  394. /* В запросе нет параметров, нужно формировать JSON ответ */
  395. if (strpbrk(tempStr,"?") == 0)
  396. {
  397. memset(bufOut, 0, SEND_BUF_MAX_LEN);
  398. HTTP_GetSettings(bufOut);
  399. //printf(bufOut);
  400. *lenBufOut = strlen(bufOut);
  401. return SEND_REQUIRED_YES;
  402. }
  403. /* В запросе есть параметры, нужно парсить и сохранять настройки */
  404. else
  405. {
  406. HTTP_SetSettings(bufIn, lenBufIn);
  407. return SEND_REQUIRED_NO;
  408. }
  409. }
  410. /**
  411. * @brief
  412. * @retval None
  413. */
  414. int HTTP_InfoPage(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
  415. {
  416. char tempStr[30];
  417. strncpy(tempStr, bufIn, 30);
  418. /* В запросе нет параметров, нужно формировать JSON ответ */
  419. if (strpbrk(tempStr,"?") == 0)
  420. {
  421. memset(bufOut, 0, SEND_BUF_MAX_LEN);
  422. HTTP_GetInfo(bufOut);
  423. *lenBufOut = strlen(bufOut);
  424. return SEND_REQUIRED_YES;
  425. }
  426. /* В запросе есть параметры, нужно парсить и сохранять настройки */
  427. else
  428. {
  429. HTTP_SetInfo(bufIn, lenBufIn);
  430. return SEND_REQUIRED_NO;
  431. /*
  432. HTTP_SetSettings(bufIn, lenBufIn);
  433. return SEND_REQUIRED_NO;
  434. */
  435. }
  436. }
  437. /**
  438. * @brief Установка даты производства
  439. */
  440. // TODO Убрать заглушку!
  441. void HTTP_Prodate(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
  442. {
  443. uint8_t valueLen = 0;
  444. char value[20];
  445. memset(bufOut, 0, SEND_BUF_MAX_LEN);
  446. ClearParamString(bufIn);
  447. memset(value, 0, 20);
  448. GetParamValue(bufIn, "prodate=", value, &valueLen);
  449. /*
  450. printf("Prodate: ");
  451. printf(value);
  452. printf("\r\n");
  453. */
  454. /* Устанавливаем дату производства */
  455. SETTINGS_SetProDate(value, valueLen);
  456. /* Устанавливаем дату следующей профилактики +1 год */
  457. RTC_SetProfTime(value);
  458. /* Пока отправляем true */
  459. strcpy(bufOut, "HTTP/1.0 200 OK\r\nContent-Type:text/html\r\n\r\nTrue");
  460. *lenBufOut = strlen(bufOut);
  461. // TEST_SetServerFlag();
  462. }
  463. /**
  464. * @brief Возвращает uptime, freq, dutycicle
  465. */
  466. void HTTP_Progon(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
  467. {
  468. memset(bufOut, 0, SEND_BUF_MAX_LEN);
  469. HTTP_GetProgonParams(bufOut);
  470. *lenBufOut = strlen(bufOut);
  471. }
  472. /**
  473. * @brief
  474. * @retval None
  475. */
  476. void HTTP_SetSettings(char *buf, uint16_t lenBuf)
  477. {
  478. uint8_t valueLen = 0;
  479. const uint8_t len = 20;
  480. char value[20];
  481. //printf(buf);
  482. ClearParamString(buf);
  483. memset(value, 0, len);
  484. /* SNMP */
  485. GetParamValue(buf, "read_community=", value, &valueLen);
  486. SetReadCommunity(value);
  487. memset(value, 0, len);
  488. GetParamValue(buf, "write_community=", value, &valueLen);
  489. SetWriteCommunity(value);
  490. memset(value, 0, len);
  491. GetParamValue(buf, "managerIP=", value, &valueLen);
  492. SetManagerIp(value);
  493. memset(value, 0, len);
  494. GetParamValue(buf, "managerIP2=", value, &valueLen);
  495. SetManagerIp2(value);
  496. memset(value, 0, len);
  497. GetParamValue(buf, "managerIP3=", value, &valueLen);
  498. SetManagerIp3(value);
  499. memset(value, 0, len);
  500. /* Сетевые параметры */
  501. GetParamValue(buf, "dhcp=", value, &valueLen);
  502. SetDhcpStateStr(value);
  503. if (strncmp(value, "on", 2) != 0) // Если dhcp off устанавливаем параметры
  504. {
  505. memset(value, 0, len);
  506. GetParamValue(buf, "ipaddr=", value, &valueLen);
  507. SetIPStr(value);
  508. memset(value, 0, len);
  509. GetParamValue(buf, "gw=", value, &valueLen);
  510. SetGatewayStr(value);
  511. memset(value, 0, len);
  512. GetParamValue(buf, "mask=", value, &valueLen);
  513. SetMaskStr(value);
  514. memset(value, 0, len);
  515. }
  516. memset(value, 0, len);
  517. /* Если параметры WEB изменились выставляем флаг, сохраняем настройки и перезагружаемся */
  518. if (GetStateWebReinit() == true)
  519. {
  520. SetWebReinitFlag(true);
  521. HTTP_SaveSettings();
  522. /* Блокируем управление ключем на тау секунд*/
  523. //IO_KeyBlockOn();
  524. vTaskDelay(1010);
  525. NVIC_SystemReset();
  526. }
  527. HTTP_SaveSettings();
  528. }
  529. /**
  530. * @brief
  531. * @retval None
  532. */
  533. void HTTP_SetInfo(char *buf, uint16_t lenBuf)
  534. {
  535. uint8_t valueLen = 0;
  536. const uint8_t len = 110;
  537. char value[110];
  538. ClearParamString(buf);
  539. memset(value, 0, len);
  540. /* Владелец */
  541. GetParamValue(buf, "owner=", value, &valueLen);
  542. HTTP_ReplaceSimbol(value, '+', ' ');
  543. SetOwner(value);
  544. memset(value, 0, len);
  545. /* Владелец */
  546. GetParamValue(buf, "sysLocation=", value, &valueLen);
  547. HTTP_ReplaceSimbol(value, '+', ' ');
  548. SetLocation(value);
  549. memset(value, 0, len);
  550. /* Комментарий */
  551. GetParamValue(buf, "comment=", value, &valueLen);
  552. HTTP_ReplaceSimbol(value, '+', ' ');
  553. SetComment(value);
  554. memset(value, 0, len);
  555. HTTP_SaveSettings();
  556. }
  557. /**
  558. * @brief Проверка пароля для перехода в режим bootloader
  559. * @retval None
  560. */
  561. void HTTP_ConfirmBootPwd(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut)
  562. {
  563. char tempStr[50];
  564. strncpy(tempStr, bufIn, 50);
  565. char value[20];
  566. uint8_t valueLen;
  567. memset(value, 0, 20);
  568. if (GetParamValue(tempStr, "password=", value, &valueLen))
  569. {
  570. if (strcmp(BOOTLOADER_PASWORD, value) == 0)
  571. {
  572. *bufOut = '1';
  573. /* Запускаем задачу отложенной перезагрузки. Контроллер должен успеть
  574. отправить ответ серверу о статусе пароля */
  575. HTTP_StartResetTask(true);
  576. }
  577. else
  578. *bufOut = '0';
  579. *lenBufOut = 1;
  580. }
  581. }
  582. /**
  583. * @brief
  584. * @retval None
  585. */
  586. uint8_t GetParamValue(char *inStr, char *paramName, char *paramValue, uint8_t *paramLen)
  587. {
  588. char *beginValue = 0;
  589. char *endValue = 0;
  590. int len = 0;
  591. char *strPtr = 0;
  592. strPtr = strstr(inStr, paramName);
  593. if (strPtr != 0)
  594. {
  595. beginValue = strpbrk(strPtr,"=");
  596. endValue = strpbrk(strPtr,"&");
  597. if (endValue == 0)
  598. endValue = strpbrk(strPtr," ");
  599. len = endValue - beginValue - 1;
  600. strncpy(paramValue, beginValue + 1, len);
  601. *endValue = '0';
  602. *beginValue = '0';
  603. *paramLen = len;
  604. return 1;
  605. }
  606. else
  607. {
  608. *paramLen = 0;
  609. return 0;
  610. }
  611. }
  612. /**
  613. * @brief
  614. * @retval None
  615. */
  616. /*
  617. uint8_t GetParamValueInEnd(char *inStr, char *paramName, char *paramValue, uint8_t *paramLen)
  618. {
  619. char *beginValue = 0;
  620. char *endValue = 0;
  621. int len = 0;
  622. char *strPtr = 0;
  623. strPtr = strstr(inStr, paramName);
  624. if (strPtr != 0)
  625. {
  626. beginValue = strpbrk(strPtr,"=");
  627. endValue = strpbrk(strPtr," ");
  628. len = endValue - beginValue - 1;
  629. strncpy(paramValue, beginValue + 1, len);
  630. *endValue = '0';
  631. *beginValue = '0';
  632. *paramLen = len;
  633. return 1;
  634. }
  635. else
  636. {
  637. *paramLen = 0;
  638. return 0;
  639. }
  640. }
  641. */
  642. void ClearParamString(char *inBuf)
  643. {
  644. uint16_t len;
  645. char *str;
  646. str = strstr(inBuf, "HTTP");
  647. if (str != 0)
  648. {
  649. len = str - inBuf;
  650. memset(str, 0, RECIVE_BUF_MAX_LEN - len - 1);
  651. }
  652. }
  653. /**
  654. * @brief Замена символа в строке
  655. * @param *str - входная строка
  656. * @param sim1 - символ который надо заменить
  657. * @param sim2 - символ на который надо заменить
  658. */
  659. void HTTP_ReplaceSimbol(char *str, char sim1, char sim2)
  660. {
  661. uint16_t len = strlen(str);
  662. for (uint16_t i = 0; i < len; i++)
  663. {
  664. if (*str == sim1)
  665. *str = sim2;
  666. str++;
  667. }
  668. }