void process_request(int fd) { if (server.clients[fd] == NULL) { return; } buffer* in_buf = server.clients[fd] -> in_buf; buffer* out_buf = server.clients[fd] -> out_buf; int i, len = buflen(in_buf); int req_len_end_pos = -1; for (i = 0; i < len; i++) { if (in_buf -> buf[i] == SEPARATOR) { req_len_end_pos = i; break; } } if (req_len_end_pos == -1) { return; } int req_len = -1; char tmp; sscanf(in_buf -> buf, "%d%c", &req_len, &tmp); if (len - req_len_end_pos - 1 < req_len) { return; } char op[100], *rest, tmp_buf[1024]; memcpy(tmp_buf, in_buf -> buf + req_len_end_pos + 1, req_len * sizeof(char)); tmp_buf[req_len] = '\0'; sscanf(tmp_buf, "%s", op); rest = tmp_buf + strlen(op) + 1; if (strcmp(op, "GET") == 0) { void* res = get_from_map(server.db, rest); if (res) { append_to_buffer(out_buf, (char*) res); } else { append_to_buffer(out_buf, ""); } } else if (strcmp(op, "SET") == 0) { char key[100], value[100]; sscanf(rest, "%s %s", key, value); free(remove_from_map(server.db, key)); char* kivi_obj = malloc((strlen(value) + 1) * sizeof(char)); memcpy(kivi_obj, value, (strlen(value) + 1) * sizeof(char)); put_in_map(server.db, key, kivi_obj); append_to_buffer(out_buf, "OK"); } else if (strcmp(op, "DEL") == 0) { free(remove_from_map(server.db, rest)); append_to_buffer(out_buf, "OK"); } memcpy(in_buf -> buf, in_buf -> buf + req_len_end_pos + 1 + req_len, (len - req_len_end_pos - 1 - req_len) * sizeof(char)); in_buf -> end_pos -= req_len_end_pos + 1 + req_len; in_buf -> buf[in_buf -> end_pos] = '\0'; }
INT_PTR MRPWindow::dlgproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { if (msg == WM_INITDIALOG) { MRPWindow* mrpw = (MRPWindow*)lp; if (mrpw != nullptr) { mrpw->m_hwnd = hwnd; g_mrpwindowsmap[hwnd] = mrpw; if (mrpw->m_is_modal == true) { mrpw->init_modal_dialog(); SetWindowText(hwnd, mrpw->m_modal_title.c_str()); } mrpw->m_helper_timer = SetTimer(hwnd, 25000, 1000, nullptr); } return TRUE; } MRPWindow* mptr = get_from_map(g_mrpwindowsmap, hwnd); if (msg == WM_COMMAND || msg == WM_HSCROLL || msg == WM_VSCROLL) { if (mptr != nullptr) { for (auto& e : mptr->m_controls) if (e!=nullptr && e->handleMessage(hwnd, msg, wp, lp) == true) { if (mptr->m_is_modal == true && mptr->m_modal_result != MRPWindow::Undefined) { EndDialog(hwnd, 0); } return TRUE; } } } if (msg == WM_SIZE) { if (mptr != nullptr) { mptr->resized(); InvalidateRect(hwnd, NULL, TRUE); return TRUE; } } if (msg == WM_CLOSE) { if (mptr != nullptr) { if (mptr->m_is_modal == false) { mptr->closeRequested(); } else { mptr->m_modal_result = MRPWindow::Rejected; EndDialog(hwnd, 2); } return TRUE; } } if (msg == WM_TIMER && wp==25000) { if (mptr != nullptr) mptr->onTimer(); return TRUE; } if (msg == WM_DESTROY) { if (mptr != nullptr) KillTimer(hwnd, mptr->m_helper_timer); } return FALSE; }