static int cmdreq(Dev *d, int type, int req, int value, int index, uchar *data, int count) { int ndata, n; uchar *wp; uchar buf[8]; char *hd, *rs; assert(d != nil); if(data == nil){ wp = buf; ndata = 0; }else{ ndata = count; wp = emallocz(8+ndata, 0); } wp[0] = type; wp[1] = req; PUT2(wp+2, value); PUT2(wp+4, index); PUT2(wp+6, count); if(data != nil) memmove(wp+8, data, ndata); if(usbdebug>2){ hd = hexstr(wp, ndata+8); rs = reqstr(type, req); fprint(2, "%s: %s val %d|%d idx %d cnt %d out[%d] %s\n", d->dir, rs, value>>8, value&0xFF, index, count, ndata+8, hd); free(hd); }
int main( int argc, char** argv ) { wawo::app::App application ; wawo::net::SocketAddr remote_addr( "192.168.2.7", 12121 ); WAWO_REF_PTR<wawo::net::Socket> socket ( new wawo::net::Socket( remote_addr,wawo::net::F_AF_INET , wawo::net::ST_STREAM, wawo::net::P_TCP ) ); int rt = socket->Open(); WAWO_RETURN_V_IF_NOT_MATCH(rt, rt == wawo::OK); rt = socket->Connect(); WAWO_RETURN_V_IF_NOT_MATCH(rt, rt == wawo::OK); WWRP<wawo::net::core::TLP_Abstract> tlp(new typename PeerT::TLPT()); socket->SetTLP(tlp); rt = socket->TLP_Handshake(); WAWO_RETURN_V_IF_NOT_MATCH(rt, rt == wawo::OK); WAWO_REF_PTR<PeerT> peer(new PeerT()); peer->AttachSocket(socket); int sndhellort; PEER_SND_HELLO(peer, sndhellort); WAWO_ASSERT(sndhellort==wawo::OK); int ec; do { WWSP<MessageT> arrives[5]; wawo::u32_t count = peer->DoReceiveMessages(arrives, 5, ec); WAWO_ASSERT(count == 1); WAWO_ASSERT(ec == wawo::OK); WAWO_ASSERT(arrives[0]->GetType() == wawo::net::peer::message::Wawo::T_RESPONSE ); wawo::Len_CStr reqstr("this is request from client"); WWSP<wawo::algorithm::Packet> reqpack( new wawo::algorithm::Packet() ); reqpack->Write<wawo::u32_t>(services::C_ECHO_STRING_REQUEST_TEST); reqpack->Write<wawo::u32_t>(reqstr.Len()); reqpack->Write((wawo::byte_t*)reqstr.CStr(),reqstr.Len()); reqpack->WriteLeft < wawo::net::ServiceIdT >(services::S_ECHO); WWSP< MessageT> message_to_req(new MessageT(reqpack)); int sndrt = peer->Request(message_to_req); WAWO_ASSERT(sndrt == wawo::OK); } while (ec == wawo::OK); WAWO_LOG_WARN( "main", "socket server exit ..." ) ; return wawo::OK; }
const char* WebModelUnified::website_search(const char* req){ JSONObject root; JSONArray jsarray; Connection* conn = connect(); Query query = conn->query(); string reqstr(req); string reqstr_spaced = replaceChar(reqstr, '+', ' '); vector<string> splittedstr; split(splittedstr, reqstr_spaced, boost::algorithm::is_any_of(" ")); int titleForce = 10; int descriptionForce = 1; int urlForce = 3; query << "SELECT * , "; //Occurences total for(size_t i1 = 0; i1 < splittedstr.size(); i1++) { string s = splittedstr[i1]; if(i1 != 0){ query << " + "; } query << "((" << titleForce << " * (char_length(title) - char_length(replace(title,'" << s << "',''))) + " << descriptionForce << " * (char_length(description) - char_length(replace(description,'" << s << "',''))) + " << urlForce << " * (char_length(url) - char_length(replace(url,'" << s << "','')))" << ") / char_length('" << s << "'))"; } query << " as Occurances " << " FROM website "; //Where clause for(size_t i1 = 0; i1 < splittedstr.size(); i1++) { string s = splittedstr[i1]; if(i1 == 0) { query << "WHERE "; } else { query << "OR "; } query << "(url LIKE '%" << s << "%' or title LIKE '%" << s << "%' or description LIKE '%" << s << "%') "; } query << " ORDER BY " << "Occurances desc, title ASC "; StoreQueryResult ares = query.store(); unsigned int numrow = ares.num_rows(); for(unsigned int i = 0; i < numrow; i++) { JSONObject result; result[L"title"] = new JSONValue(wchartFromChar(ares[i]["title"])); result[L"description"] = new JSONValue(wchartFromChar(ares[i]["description"])); result[L"url"] = new JSONValue(wchartFromChar(ares[i]["url"])); JSONValue* resultVal = new JSONValue(result); jsarray.push_back(resultVal); } root[L"results"] = new JSONValue(jsarray); JSONValue* jvalue = new JSONValue(root); const char* returnStr = fromWString(jvalue->Stringify()); delete jvalue; return returnStr; }