long long int fill_membuf(struct membuf *self, struct istream *istream) { unsigned long long int offset = self->off; long long int retval; for (;;) { if (self->off >= self->len) { unsigned char *tmp; self->len += 4096; tmp = b6_reallocate(self->allocator, self->buf, self->len); if (!tmp) { log_w("out of memory"); retval = -1; break; } self->buf = tmp; } if ((retval = read_istream(istream, self->buf + self->off, self->len - self->off)) <= 0) break; self->off += retval; } if (retval < 0) { log_w("error %d", retval); self->off = offset; } else retval = self->off - offset; return retval; }
const bool dummy_operator_t::save( const char* file_name, plugin::image_desc_t* source, plugin::option_t* options ){ log_i( op_name, "Dummy now will try to SAVE a file '%s'", file_name ); log_w( op_name, "And now dummy will sleep -__-" ); Sleep( 150 + ( rand() % 650 ) ); log_w( op_name, "Dummy wakes up and releases file '%s'", file_name ); return true; };
int8_t AsyncClient::_poll(tcp_pcb* pcb){ // Close requested if(_close_pcb){ _close_pcb = false; _close(); return ERR_OK; } uint32_t now = millis(); // ACK Timeout if(_pcb_busy && _ack_timeout && (now - _pcb_sent_at) >= _ack_timeout){ _pcb_busy = false; log_w("ack timeout %d", pcb->state); if(_timeout_cb) _timeout_cb(_timeout_cb_arg, this, (now - _pcb_sent_at)); return ERR_OK; } // RX Timeout if(_rx_since_timeout && (now - _rx_last_packet) >= (_rx_since_timeout * 1000)){ log_w("rx timeout %d", pcb->state); _close(); return ERR_OK; } // Everything is fine if(_poll_cb) _poll_cb(_poll_cb_arg, this); return ERR_OK; }
const bool dummy_operator_t::load( const char* file_name, plugin::image_desc_t* dest, plugin::option_t* options ){ log_i( op_name, "Dummy now will try to LOAD a file '%s'", file_name ); log_w( op_name, "And now dummy will sleep -__-" ); Sleep( 10 + ( rand() % 250 ) ); log_w( op_name, "Dummy wakes up and releases file '%s'", file_name ); return true; };
void BrucoSession::on_recv_proxy(const char *buf, int buf_size) { std::string target_str(buf, buf_size); if (dump_stream_) { log_d("dump_stream : session=%ld : [out_bound] %s", session_id_, escape(target_str).c_str()); } if (outbound_key_check_xor256_) { std::string key = read_key_(); if (check_contain_key_xor256_(key, target_str)) { log_w("break_session : type=outbound_contain_key_xor256, outbound_key_file=%s", outbound_key_file_.c_str()); break_session(); return; } } else if (outbound_key_check_) { std::string key = read_key_(); if (check_contain_key_(key, target_str)) { log_w("break_session : %s, type=outbound_contain_key, outbound_key_file=%s", outbound_key_file_.c_str()); break_session(); return; } } if (outbound_pass_re_ != NULL) { bool rv = RE2::PartialMatch(target_str, *outbound_pass_re_); if (rv) { BrucoPipe::on_recv_proxy(buf, buf_size); return; } } if (outbound_deny_re_ != NULL) { bool rv = RE2::PartialMatch(target_str, *outbound_deny_re_); if (rv) { log_w("break_session : type=outbound_deny_re, outbound_re=%s", outbound_deny_re_->pattern().c_str()); break_session(); return; } } // default policy if (outbound_default_pass_) { BrucoPipe::on_recv_proxy(buf, buf_size); } else { break_session(); } }
bool AsyncClient::connect(IPAddress ip, uint16_t port){ if (_pcb){ log_w("already connected, state %d", _pcb->state); return false; } if(!_start_async_task()){ log_e("failed to start task"); return false; } ip_addr_t addr; addr.type = IPADDR_TYPE_V4; addr.u_addr.ip4.addr = ip; tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_V4); if (!pcb){ log_e("pcb == NULL"); return false; } tcp_arg(pcb, this); tcp_err(pcb, &_tcp_error); if(_in_lwip_thread){ tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected); } else { _tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected); } return true; }
BOOL KFunction::IsScomRegistered(LPCTSTR szGUID, LPCTSTR szPath) { int nRetCode = 0; BOOL bReturn = FALSE; CString strValue; CString strSubKey; CKANRegisterKey key; strSubKey.Format(_T("SOFTWARE\\Kingsoft\\KISCommon\\KXEngine\\CLASSES_ROOT\\CLSID\\%s\\InprocServer32"), szGUID); nRetCode = key.Open(HKEY_LOCAL_MACHINE, strSubKey); if (!nRetCode) goto Exit0; DWORD dwLen = MAX_PATH; PTCHAR pBuf = strValue.GetBuffer(MAX_PATH + 1); nRetCode = key.Read(NULL, pBuf, dwLen); pBuf[MAX_PATH] = 0; strValue.ReleaseBuffer(); if (strValue.IsEmpty()) goto Exit0; strValue.Replace(_T('/'), _T('\\')); if (strValue.CompareNoCase(szPath) == 0) { bReturn = TRUE; } Exit0: log_w(L"IsScomRegistered return:%d, guid:%s, path:%s\n", bReturn, szGUID, szPath); return bReturn; }
int __open_level(struct level *self, struct layout *layout) { int i; struct place* places[2]; for (i = 0; i < b6_card_of(self->places); i += 1) { struct place *place = &self->places[i]; initialize_place(self, layout, place); self->nplaces += !!place->item; } places[0] = self->items->teleport[0].place; places[1] = self->items->teleport[1].place; if (places[0] && places[1]) { self->items->teleport[0].place = places[1]; self->items->teleport[1].place = places[0]; if (places[0]->item != &self->items->teleport[0].item) dispose_item(&self->items->teleport[0].item); if (places[1]->item != &self->items->teleport[1].item) dispose_item(&self->items->teleport[1].item); } else if (places[0]) { int x, y; place_location(self, places[0], &x, &y); log_w("ignored single teleport at (%d,%d).", x, y); dispose_item(places[0]->item); places[0]->item = clone_empty(self->items); } b6_assert(!places[1] || (places[1] && places[0])); recover_ghosts_den(self, layout); if (self->pacman_home) return 0; __close_level(self); return -1; }
static esp_err_t _network_event_cb(void *arg, system_event_t *event){ if (xQueueSend(_network_event_queue, &event, portMAX_DELAY) != pdPASS) { log_w("Network Event Queue Send Failed!"); return ESP_FAIL; } return ESP_OK; }
/** * control wifi tx power * @param power enum maximum wifi tx power * @return ok */ bool WiFiGenericClass::setTxPower(wifi_power_t power){ if((getStatusBits() & (STA_STARTED_BIT | AP_STARTED_BIT)) == 0){ log_w("Neither AP or STA has been started"); return false; } return esp_wifi_set_max_tx_power(power) == ESP_OK; }
static void remove_timer(char dir, fdja_value *node, fdja_value *msg) { fdja_value *trigger = fdja_l(msg, "trigger"); if (trigger == NULL) { return; } fdja_value *timers = fdja_l(node, "timers"); if (timers == NULL) { log_w(node, msg, "triggered node has no timers..."); return; } char type = fdja_lk(trigger, "type"); char *ts = fdja_ls(trigger, "ts"); //printf("--- remove_timer ---\n"); //printf("dir: %c\n", dir); //printf("node: "); //fdja_putdc(node); //printf("msg: "); //fdja_putdc(msg); for (fdja_value *t = timers->child; t; t = t->sibling) { fdja_putdc(t); if (*t->child->key != type || fdja_strcmp(t->child, ts) != 0) continue; fdja_set(t, "triggered", fdja_v("true")); break; } free(ts); }
/** * control modem sleep when only in STA mode * @param enable bool * @return ok */ bool WiFiGenericClass::setSleep(bool enable) { if((getMode() & WIFI_MODE_STA) == 0){ log_w("STA has not been started"); return false; } return esp_wifi_set_ps(enable?WIFI_PS_MIN_MODEM:WIFI_PS_NONE) == ESP_OK; }
/** * Elog demo */ static void test_elog(void) { log_a("Hello EasyLogger!"); log_e("Hello EasyLogger!"); log_w("Hello EasyLogger!"); log_i("Hello EasyLogger!"); log_d("Hello EasyLogger!"); log_v("Hello EasyLogger!"); //elog_raw("Hello EasyLogger!"); }
bool parse_ask(){ int i=0; do{ sock.recv(imsg[i],0); }while(imsg[i++].more()&&i<ASK_SIZE); if (i!=ASK_SIZE){ log_w("ask msg must has %d parts,but actually recv %d part(s)",ASK_SIZE,i); return false; } //check version uint32_t v=*(uint32_t*)imsg[ASK_VERSION].data(); if (v!=VERSION_NO){ log_w("APIs's version(%s) is not compatible with lib's(%s)", v2s(v).c_str(),v2s(VERSION_NO).c_str()); return false; } return true; }
/** * EasyLogger demo */ void test_elog(void) { /* test log output for all level */ log_a("Hello EasyLogger!"); log_e("Hello EasyLogger!"); log_w("Hello EasyLogger!"); log_i("Hello EasyLogger!"); log_d("Hello EasyLogger!"); log_v("Hello EasyLogger!"); // elog_raw("Hello EasyLogger!"); }
void BrucoSession::on_recv(const char *buf, int buf_size) { std::string target_str(buf, buf_size); if (dump_stream_) { log_d("dump_stream : session=%ld : [in_bound] %s", session_id_, escape(target_str).c_str()); } if (inbound_jmpcall_check_) { bool rv = check_jmpcall_(target_str); if (rv) { log_w("break_session : type=inbound_jmpcall"); break_session(); return; } } if (inbound_pass_re_ != NULL) { bool rv = RE2::PartialMatch(target_str, *inbound_pass_re_); if (rv) { BrucoPipe::on_recv(buf, buf_size); return; } } if (inbound_deny_re_ != NULL) { bool rv = RE2::PartialMatch(target_str, *inbound_deny_re_); if (rv) { log_w("break_session : type=inbound_deny_re, inbound_re=%s", inbound_deny_re_->pattern().c_str()); break_session(); return; } } // default policy if (inbound_default_pass_) { BrucoPipe::on_recv(buf, buf_size); } else { break_session(); } }
wifi_power_t WiFiGenericClass::getTxPower(){ int8_t power; if((getStatusBits() & (STA_STARTED_BIT | AP_STARTED_BIT)) == 0){ log_w("Neither AP or STA has been started"); return WIFI_POWER_19_5dBm; } if(esp_wifi_get_max_tx_power(&power)){ return WIFI_POWER_19_5dBm; } return (wifi_power_t)power; }
bool parse_ans(){ int i=0; do{ sock.recv(imsg[i],0); }while(imsg[i++].more()&&i<ANS_SIZE); if (i!=ANS_SIZE){ log_w("ans msg must has %d parts,but actually recv %d part(s)",ANS_SIZE,i); return false; } return true; }
/** * get modem sleep enabled * @return true if modem sleep is enabled */ bool WiFiGenericClass::getSleep() { wifi_ps_type_t ps; if((getMode() & WIFI_MODE_STA) == 0){ log_w("STA has not been started"); return false; } if(esp_wifi_get_ps(&ps) == ESP_OK){ return ps == WIFI_PS_MIN_MODEM; } return false; }
int8_t AsyncClient::abort(){ if(_pcb) { log_w("state %d", _pcb->state); if(_in_lwip_thread){ tcp_abort(_pcb); } else { _tcp_abort(_pcb); } _pcb = NULL; } return ERR_ABRT; }
/** * get WiFi mode * @return WiFiMode */ wifi_mode_t WiFiGenericClass::getMode() { if(!_esp_wifi_started){ return WIFI_MODE_NULL; } wifi_mode_t mode; if(esp_wifi_get_mode(&mode) == ESP_ERR_WIFI_NOT_INIT){ log_w("WiFi not started"); return WIFI_MODE_NULL; } return mode; }
int get_image_data(const char *skin_id, const char *data_id, void *param, struct data_entry **entry, struct image_data **data) { int retval; retval = get_image_data_no_fallback(skin_id, data_id, param, entry, data); if (retval && *fallback) { log_w("falling back to %s for %s", fallback, data_id); retval = get_image_data_no_fallback(fallback, data_id, param, entry, data); } return retval; }
void* construct(const char *name, interface::Server *server) { auto it = m_module_info.find(name); if(it == m_module_info.end()){ log_w(MODULE, "construct(%s): Module is not loaded", name); return NULL; } RCCPP_Info &info = it->second; RCCPP_Constructor constructor = info.constructor; return constructor(server); }
void guard_init() { if(buildat_guard_init() != 0){ log_w(MODULE, "The buildat_guard interface could not be accessed." " You should LD_PRELOAD it."); return; } // Guard is used only when Urho3D::ResourceCache is accessed by unsafe code buildat_guard_enable(false); //buildat_guard_add_valid_base_path("/usr/share/"); }
int get_image_data_no_fallback(const char *skin_id, const char *data_id, void *param, struct data_entry **entry, struct image_data **data) { if (!(*entry = lookup_data(skin_id, image_data_type, data_id))) { log_w("cannot find %s.%s.%s", skin_id, image_data_type, data_id); return -1; } struct istream *istream; int retval; if (!(istream = get_data(*entry))) { log_w("cannot get %s.%s.%s", skin_id, image_data_type, data_id); return -1; } *data = b6_cast_of(istream, struct image_data, up); if (!(*data)->ops->ctor || !(retval = (*data)->ops->ctor(*data, param))) return 0; put_data(*entry, istream); log_w("cannot read %s.%s.%s", skin_id, image_data_type, data_id); return -1; }
/** * Elog demo */ static void test_elog(void) { /* output all saved log from flash */ elog_flash_output_all(); /* test log output for all level */ log_a("Hello EasyLogger!"); log_e("Hello EasyLogger!"); log_w("Hello EasyLogger!"); log_i("Hello EasyLogger!"); log_d("Hello EasyLogger!"); log_v("Hello EasyLogger!"); elog_raw("Hello EasyLogger!"); /* trigger assert. Now will run elog_user_assert_hook. All log information will save to flash. */ ELOG_ASSERT(0); }
int initialize_menu_mixer(struct menu_mixer *self, struct menu *menu, const char *skin, struct mixer *mixer) { static struct menu_observer_ops ops = {}; struct istream *is; struct data_entry *data; self->menu = menu; self->mixer = mixer; self->music = 0; if ((data = lookup_data(skin, audio_data_type, "menu.music")) && (is = get_data(data))) { int retval = mixer->ops->load_music_from_stream(mixer, is); if (!retval) { play_music(mixer); self->music = 1; } else log_w(_s("could not load background music")); put_data(data, is); } else log_w(_s("cannot find background music")); add_menu_observer(self->menu, setup_menu_observer(&self->menu_observer, &ops)); return 0; }
BOOL KFunction::_IsEnableCopy(LPCTSTR szSrcPath, LPCTSTR szDstPath) { BOOL bReturn = FALSE; BOOL bRetCode = FALSE; WIN32_FIND_DATA find_data; HANDLE hFind = INVALID_HANDLE_VALUE; CString strSrcPath(szSrcPath); CString strDstPath(szDstPath); hFind = ::FindFirstFile(strSrcPath + _T("*"), &find_data); if (hFind == INVALID_HANDLE_VALUE) { bReturn = TRUE; goto Exit0; } do{ if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (lstrcmp(find_data.cFileName, _T(".")) != 0 && lstrcmp(find_data.cFileName, _T("..")) != 0) { bRetCode = KFunction::_IsEnableCopy(strSrcPath + find_data.cFileName + _T("\\"), strDstPath + find_data.cFileName + _T("\\")); if (!bRetCode) goto Exit0; } } else { if (KFunction::IsFileInUse(strDstPath + find_data.cFileName)) { log_w(L"KFunction::_IsEnableCopy IsFileInUse return:1, path:%s\n", (LPCTSTR)(strDstPath + find_data.cFileName)); goto Exit0; } } bRetCode = ::FindNextFile(hFind, &find_data); } while(bRetCode); bReturn = TRUE; Exit0: if (hFind) FindClose(hFind); return bReturn; }
std::string BrucoSession::read_key_() { std::ifstream ifs; std::stringstream ss; ifs.open(outbound_key_file_.c_str(), std::ios::in); if (!ifs) { log_w("outbound_key_file load failed...outbound_key_file=%s", outbound_key_file_.c_str()); return ""; } ss << ifs.rdbuf(); ifs.close(); return ss.str(); }
BOOL KFunction::RunApp(LPCTSTR szPath, LPCTSTR szFile, LPCTSTR szCmd, DWORD dwWaitTime /* = 0 */) { BOOL bReturn = FALSE; STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW; CString strExePath(szPath); KFunction::PathAddBackslash(strExePath); strExePath += szFile; strExePath += _T(" "); strExePath += szCmd; bReturn = CreateProcessW(NULL, // No module name (use command line). (LPWSTR)(LPCTSTR)strExePath, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to FALSE. 0, // No creation flags. NULL, // Use parent's environment block. szPath, // Use parent's starting directory. &si, // Pointer to STARTUPINFO structure. &pi // Pointer to PROCESS_INFORMATION structure. ); if (bReturn) { ::WaitForSingleObject(pi.hThread, dwWaitTime); } Exit0: if (pi.hProcess != NULL) { CloseHandle(pi.hProcess); pi.hProcess = NULL; } if (pi.hThread != NULL) { CloseHandle(pi.hThread); pi.hThread = NULL; } log_w(L"CreateProcess return:%d, path:%s, file:%s, cmd:%s\n", bReturn, szPath, szFile, szCmd); return bReturn; }