void PptvLive2::async_open( response_type const & resp) { assert(StepType::closed == open_step_); set_response(resp); boost::system::error_code ec; if (url_.path().find('-') != std::string::npos) { // "[StreamID]-[Interval]-[datareate] std::vector<std::string> strs; slice<std::string>(url_.path(), std::inserter(strs, strs.end()), "-"); if (strs.size() >= 3) { jump_info_.video.name = strs[0].substr(1); jump_info_.video.rid = jump_info_.video.name; parse2(strs[2], jump_info_.video.bitrate); parse2(strs[1], seg_.interval); } else { ec = error::bad_url_format; } } else { ec = error::bad_url_format; } handle_async_open(ec); }
void RequestHandler::handle_retry_decision(ResponseMessage* response, const RetryPolicy::RetryDecision& decision) { ErrorResponse* error = static_cast<ErrorResponse*>(response->response_body().get()); switch(decision.type()) { case RetryPolicy::RetryDecision::RETURN_ERROR: set_error_with_error_response(response->response_body(), static_cast<CassError>(CASS_ERROR( CASS_ERROR_SOURCE_SERVER, error->code())), error->message().to_string()); break; case RetryPolicy::RetryDecision::RETRY: set_consistency(decision.retry_consistency()); if (!decision.retry_current_host()) { next_host(); } if (state() == REQUEST_STATE_DONE) { retry(); } else { set_state(REQUEST_STATE_RETRY_WRITE_OUTSTANDING); } break; case RetryPolicy::RetryDecision::IGNORE: set_response(SharedRefPtr<Response>(new ResultResponse())); break; } num_retries_++; }
void RoleCollection::get(const server::Request& req, server::Response& res) { auto r = make_prototype(); r[Common::ODATA_ID] = PathBuilder(req).build(); RoleManager::get_instance()->for_each([&r, &req](const auto& role) { json::Json link_elem(json::Json::value_t::object); link_elem[Common::ODATA_ID] = PathBuilder(req).append(role.get_id()).build(); r[Collection::MEMBERS].push_back(std::move(link_elem)); }); r[Collection::ODATA_COUNT] = r[Collection::MEMBERS].size(); set_response(res, r); }
void Role::get(const server::Request& req, server::Response& res) { auto role_id = req.params[PathParam::ROLE_ID]; auto role = RoleManager::get_instance()->get(role_id); auto r = make_prototype(); r[constants::Role::ASSIGNED_PRIVILEGES] = role.get_privileges(); r[Common::ODATA_ID] = PathBuilder(req).build(); r[Common::ID] = req.params[PathParam::ROLE_ID]; r[constants::Role::ROLE_ID] = role.get_role_id(); r[constants::Role::IS_PREDEFINED] = role.is_predefined(); set_response(res, r); }
void RequestHandler::on_result_response(ResponseMessage* response) { ResultResponse* result = static_cast<ResultResponse*>(response->response_body().get()); switch (result->kind()) { case CASS_RESULT_KIND_ROWS: // Execute statements with no metadata get their metadata from // result_metadata() returned when the statement was prepared. if (request_->opcode() == CQL_OPCODE_EXECUTE && result->no_metadata()) { const ExecuteRequest* execute = static_cast<const ExecuteRequest*>(request_.get()); if (!execute->skip_metadata()) { // Caused by a race condition in C* 2.1.0 on_error(CASS_ERROR_LIB_UNEXPECTED_RESPONSE, "Expected metadata but no metadata in response (see CASSANDRA-8054)"); return; } result->set_metadata(execute->prepared()->result()->result_metadata().get()); } set_response(response->response_body()); break; case CASS_RESULT_KIND_SCHEMA_CHANGE: { SharedRefPtr<SchemaChangeHandler> schema_change_handler( new SchemaChangeHandler(connection_, this, response->response_body())); schema_change_handler->execute(); break; } case CASS_RESULT_KIND_SET_KEYSPACE: io_worker_->broadcast_keyspace_change(result->keyspace().to_string()); set_response(response->response_body()); break; default: set_response(response->response_body()); break; } }
void RESTRequestState::set_callback_response(RESTContentReaderCallback rsp_writer, const char* content_type) { const char* accept_enc = MHD_lookup_connection_value(get_conn(), MHD_HEADER_KIND, "Accept-Encoding"); bool use_gzip = accept_enc && strstr(accept_enc, "gzip"); set_response(MHD_create_response_from_callback( -1, RESPONSE_BLOCK_SIZE, callback_write, new ContentReaderState(rsp_writer, get_free_callback(), get_callback_data(), use_gzip), callback_free)); MHD_add_response_header(get_response(), "Content-Type", content_type); if (use_gzip) MHD_add_response_header(get_response(), "Content-Encoding", "gzip"); /* libmicrohttpd will call the appropriate callback to free the data instead of us */ set_free_callback(NULL); }
bool emulate_tag(const unsigned int tgInitAsTargetTimeout) { unsigned char command[] = { PN532_COMMAND_TGINITASTARGET, 2, // MODE 0x00, 0x08, // SENS_RES 0x00, 0x00, 0x00, // NFCID1 0x40, // SEL_RES 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, // FeliCaParams 0,0, 0,0,0,0,0,0,0,0,0,0, // NFCID3t 14, // length of general bytes 0x01,0x01,0x0a,0x54,0x02,0x65,0x6E,0x58,0x61,0x64,0x6F,0x77,0x20,0x36, 14, // length of historical bytes 0x01,0x01,0x0a,0x54,0x02,0x65,0x6E,0x58,0x61,0x64,0x6F,0x77,0x20,0x36 }; if(emulateTag.uidPtr != 0) { // if uid is set copy 3 bytes to nfcid1 memcpy(command + 4, emulateTag.uidPtr, 3); } if(1 != tgInitAsTargetP(command,sizeof(command), tgInitAsTargetTimeout)) { return false; } unsigned char compatibility_container[] = { 0, 0x0F, 0x20, 0, 0x54, 0, 0xFF, 0x04, // T 0x06, // L 0xE1, 0x04, // File identifier ((NDEF_MAX_LENGTH & 0xFF00) >> 8), (NDEF_MAX_LENGTH & 0xFF), // maximum NDEF file size 0x00, // read access 0x0 = granted 0x00 // write access 0x0 = granted | 0xFF = deny }; if(emulateTag.tagWriteable == false) { compatibility_container[14] = 0xFF; } emulateTag.tagWrittenByInitiator = false; unsigned char rwbuf[128]; unsigned char sendlen; int status; tag_file currentFile = NONE; unsigned int cc_size = sizeof(compatibility_container); bool runLoop = true; while(runLoop) { status = tgGetData(rwbuf, sizeof(rwbuf)); if(status < 0) { inRelease(0); return true; } unsigned char p1 = rwbuf[C_APDU_P1]; unsigned char p2 = rwbuf[C_APDU_P2]; unsigned char lc = rwbuf[C_APDU_LC]; unsigned int p1p2_length = ((int) p1 << 8) + p2; const unsigned char ndef_tag_application_name_v2[] = {0, 0x7, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 }; switch(rwbuf[C_APDU_INS]) { case ISO7816_SELECT_FILE: switch(p1) { case C_APDU_P1_SELECT_BY_ID: if(p2 != 0x0c) { set_response(COMMAND_COMPLETE, rwbuf, &sendlen, 0); } else if(lc == 2 && rwbuf[C_APDU_DATA] == 0xE1 && (rwbuf[C_APDU_DATA+1] == 0x03 || rwbuf[C_APDU_DATA+1] == 0x04)) { set_response(COMMAND_COMPLETE, rwbuf, &sendlen, 0); if(rwbuf[C_APDU_DATA+1] == 0x03) { currentFile = CC; } else if(rwbuf[C_APDU_DATA+1] == 0x04) { currentFile = NDEF; } } else { set_response(TAG_NOT_FOUND, rwbuf, &sendlen, 0); } break; case C_APDU_P1_SELECT_BY_NAME: if(0 == memcmp(ndef_tag_application_name_v2, rwbuf + C_APDU_P2, sizeof(ndef_tag_application_name_v2))) { set_response(COMMAND_COMPLETE, rwbuf, &sendlen, 0); } else { set_response(FUNCTION_NOT_SUPPORTED, rwbuf, &sendlen, 0); } break; } break; case ISO7816_READ_BINARY: switch(currentFile) { case NONE: set_response(TAG_NOT_FOUND, rwbuf, &sendlen, 0); break; case CC: if( p1p2_length > NDEF_MAX_LENGTH) { set_response(END_OF_FILE_BEFORE_REACHED_LE_BYTES, rwbuf, &sendlen, 0); } else { memcpy(rwbuf,compatibility_container + p1p2_length, lc); set_response(COMMAND_COMPLETE, rwbuf + lc, &sendlen, lc); } break; case NDEF: if( p1p2_length > NDEF_MAX_LENGTH) { set_response(END_OF_FILE_BEFORE_REACHED_LE_BYTES, rwbuf, &sendlen, 0); } else { memcpy(rwbuf, emulateTag.ndef_file + p1p2_length, lc); set_response(COMMAND_COMPLETE, rwbuf + lc, &sendlen, lc); } break; } break; case ISO7816_UPDATE_BINARY: if(!emulateTag.tagWriteable) { set_response(FUNCTION_NOT_SUPPORTED, rwbuf, &sendlen, 0); } else { if(p1p2_length > NDEF_MAX_LENGTH) { set_response(MEMORY_FAILURE, rwbuf, &sendlen, 0); } else { memcpy(emulateTag.ndef_file + p1p2_length, rwbuf + C_APDU_DATA, lc); set_response(COMMAND_COMPLETE, rwbuf, &sendlen, 0); emulateTag.tagWrittenByInitiator = true; unsigned int ndef_length = (emulateTag.ndef_file[0] << 8) + emulateTag.ndef_file[1]; if((ndef_length > 0) && (emulateTag.updateNdefCallback != 0)) { emulateTag.updateNdefCallback(emulateTag.ndef_file + 2, ndef_length); } } } break; default: set_response(FUNCTION_NOT_SUPPORTED, rwbuf, &sendlen, 0); } status = tgSetData(rwbuf, sendlen, 0, 0); if(status < 0) { inRelease(0); return true; } } inRelease(0); return true; }
/***********************************************************************//** * @brief Get observation container * * Get an observation container according to the user parameters. The method * supports loading of a individual FITS file or an observation definition * file in XML format. * * If the input filename is empty, the method checks for the existence of the * "expcube", "psfcube" and "bkgcube" parameters. If file names have been * specified, the method loads the files and creates a dummy events cube that * is appended to the observation container. * * If no file names are specified for the "expcube", "psfcube" or "bkgcube" * parameters, the method reads the necessary parameters to build a CTA * observation from scratch. * * The method sets m_append_cube = true and m_binned = true in case that * a stacked observation is requested (as detected by the presence of the * "expcube", "psfcube", and "bkgcube" parameters). In that case, it appended * a dummy event cube to the observation. ***************************************************************************/ void ctmodel::get_obs(void) { // Get the filename from the input parameters std::string filename = (*this)["inobs"].filename(); // If no observation definition file has been specified then read all // parameters that are necessary to create an observation from scratch if ((filename == "NONE") || (gammalib::strip_whitespace(filename) == "")) { // Get response cube filenames std::string expcube = (*this)["expcube"].filename(); std::string psfcube = (*this)["psfcube"].filename(); std::string bkgcube = (*this)["bkgcube"].filename(); // If the filenames are valid then build an observation from cube // response information if ((expcube != "NONE") && (psfcube != "NONE") && (bkgcube != "NONE") && (gammalib::strip_whitespace(expcube) != "") && (gammalib::strip_whitespace(psfcube) != "") && (gammalib::strip_whitespace(bkgcube) != "")) { // Get exposure, PSF and background cubes GCTACubeExposure exposure(expcube); GCTACubePsf psf(psfcube); GCTACubeBackground background(bkgcube); // Create energy boundaries GEbounds ebounds = create_ebounds(); // Create dummy sky map cube GSkyMap map("CAR","GAL",0.0,0.0,1.0,1.0,1,1,ebounds.size()); // Create event cube GCTAEventCube cube(map, ebounds, exposure.gti()); // Create CTA observation GCTAObservation cta; cta.events(cube); cta.response(exposure, psf, background); // Append observation to container m_obs.append(cta); // Signal that we are in binned mode m_binned = true; // Signal that we appended a cube m_append_cube = true; } // endif: cube response information was available // ... otherwise build an observation from IRF response information else { // Create CTA observation GCTAObservation cta = create_cta_obs(); // Set response set_obs_response(&cta); // Append observation to container m_obs.append(cta); } } // endif: filename was "NONE" or "" // ... otherwise we have a file name else { // If file is a FITS file then create an empty CTA observation // and load file into observation if (gammalib::is_fits(filename)) { // Allocate empty CTA observation GCTAObservation cta; // Load data cta.load(filename); // Set response set_obs_response(&cta); // Append observation to container m_obs.append(cta); // Signal that no XML file should be used for storage m_use_xml = false; } // ... otherwise load file into observation container else { // Load observations from XML file m_obs.load(filename); // For all observations that have no response, set the response // from the task parameters set_response(m_obs); // Set observation boundary parameters (emin, emax, rad) set_obs_bounds(m_obs); // Signal that XML file should be used for storage m_use_xml = true; } // endelse: file was an XML file } // Return return; }
void RESTRequestState::set_text_response(unsigned int status, const std::string& text, const char* content_type) { set_response(MHD_create_response_from_data(text.size(), (void*)text.c_str(), MHD_NO, MHD_YES)); MHD_add_response_header(get_response(), "Content-Type", content_type); set_status(status); }
void RESTRequestState::set_empty_response(unsigned int status) { set_response(MHD_create_response_from_data(0, (void*)"", MHD_NO, MHD_NO)); set_status(status); }