Results List::filter(Query q) const { verify_attached(); if (m_link_view) return Results(m_realm, m_link_view, get_query().and_query(std::move(q))); return Results(m_realm, get_query().and_query(std::move(q))); }
void fetch_cover_image_from_name (GooWindow *window, const char *album, const char *artist, GCancellable *cancellable) { FetchData *data; char *url; GFile *file; data = g_new0 (FetchData, 1); data->window = window; data->cancellable = _g_object_ref (cancellable); url = get_query (album, artist); file = g_file_new_for_uri (url); g_load_file_async (file, G_PRIORITY_DEFAULT, data->cancellable, query_ready_cb, data); g_object_unref (file); g_free (url); }
inline bool handle_write(mg_connection* connection,const bool authenticated,const std::string& request, const std::string& query,const std::string& post_data) { std::string comma_list=get_query(connection,"write"); if(comma_list.size()>0) { auto& database=get_database(connection); std::cout<<"\tWriting \""<<comma_list<<"\"..."<<std::flush; if((database.permissions&P_WRITE)!=0||(authenticated&&database.allow_authentication())) { if(!database.write(comma_list,post_data)) { mg_send_status(connection,"400 BAD REQUEST"); std::cout<<"malformed."<<std::endl; } else { std::cout<<"done."<<std::endl; } } else { mg_send_status(connection,"401 UNAUTHORIZED"); std::cout<<"denied."<<std::endl; } return true; } return false; }
inline bool handle_read(mg_connection* connection,const bool authenticated,const std::string& request, const std::string& query) { std::string comma_list=get_query(connection,"read"); if(comma_list.size()>0) { auto& database=get_database(connection); std::cout<<"\tReading \""<<comma_list<<"\"..."<<std::flush; if((database.permissions&P_READ)!=0||(authenticated&&database.allow_authentication())) { mg_send(connection,database.read(comma_list),"application/json"); std::cout<<"done."<<std::endl; } else { mg_send_status(connection,"401 UNAUTHORIZED"); std::cout<<"denied."<<std::endl; } return true; } return false; }
void flash_dump_info(flash_t * flash) { int i; printf("flash at 0x%p of %d bytes with %d regions\n", flash->f_base, flash->f_size, flash->f_nregions); uint16_t m_id, d_id; if (get_id(flash->f_base, &m_id, &d_id)) { puts(" failed to get id\n"); } else { printf(" manufacturer 0x%4.4x device 0x%4.4x\n", m_id, d_id); } uint16_t plock; uint8_t pdata[8]; if (get_intel_protection(flash->f_base, &plock, pdata)) { puts(" failed to get protection data\n"); } else { dump_intel_protection(plock, pdata); } struct cfi_query qry; if (get_query(flash->f_base, &qry)) { puts(" failed to get cfi query response\n"); } else { dump_query_algorithms(&qry); dump_query_timing(&qry); } for (i = 0; i < flash->f_nregions; i++) { flash_region_t *fr = &flash->f_regions[i]; printf(" region %d: %d blocks of %d bytes at 0x%p\n", i, fr->fr_bnum, fr->fr_bsize, fr->fr_base); } }
/** * Setup everything needed to retrieve shadow entries. */ enum nss_status _nss_sqlite_setspent(void) { char* sql; pthread_mutex_lock(&spent_mutex); if(spent_data.pDb == NULL) { NSS_DEBUG("setspent: opening DB connection\n"); if(sqlite3_open(NSS_SQLITE_SHADOW_DB, &spent_data.pDb) != SQLITE_OK) { NSS_ERROR(sqlite3_errmsg(spent_data.pDb)); return NSS_STATUS_UNAVAIL; } if(!(sql = get_query(spent_data.pDb, "setspent")) ) { NSS_ERROR(sqlite3_errmsg(spent_data.pDb)); sqlite3_close(spent_data.pDb); return NSS_STATUS_UNAVAIL; } if(sqlite3_prepare(spent_data.pDb, sql, -1, &spent_data.pSt, NULL) != SQLITE_OK) { NSS_ERROR(sqlite3_errmsg(spent_data.pDb)); sqlite3_finalize(spent_data.pSt); sqlite3_close(spent_data.pDb); free(sql); return NSS_STATUS_UNAVAIL; } } free(sql); pthread_mutex_unlock(&spent_mutex); return NSS_STATUS_SUCCESS; }
// Construct a URL object from the string representation URL::URL(const std::string& url_str) { if (url_str.empty()) throw std::invalid_argument("empty url string"); const std::string sr = boost::trim_copy(url_str); try { token_rest scheme_rest = get_scheme(sr); scheme = scheme_rest.first; std::cout << scheme_rest.first << " : " << scheme_rest.second << std::endl; token_rest host_port_rest = get_host_port(scheme_rest.second); std::cout << host_port_rest.first << " : " << host_port_rest.second << std::endl; std::pair<std::string,uint16_t> host_port = split_host_port(host_port_rest.first); std::cout << host_port.first << " : " << host_port.second << std::endl; host = host_port.first; port = host_port.second; token_rest path_rest = get_path(host_port_rest.second); std::cout << path_rest.first << std::endl; path = path_rest.first; if (path_rest.second.empty()) return; token_rest query_rest = get_query(path_rest.second); std::cout << query_rest.first << " : " << query_rest.second << std::endl; if (!query_rest.first.empty()) { query_key_vals = make_query_map(query_rest.first); } std::string fragment = get_fragment(query_rest.second); std::cout << fragment << std::endl; } catch(const std::exception &e) { std::cerr << e.what() << std::endl; throw e; } // parsed successfully, we can copy over the original arg string_rep = url_str; }
static gboolean execute_find (MuStore *store, MuConfig *opts, GError **err) { char *query_str; MuQuery *oracle; gboolean rv; oracle = get_query_obj(store, err); if (!oracle) return FALSE; query_str = get_query (opts, err); if (!query_str) { mu_query_destroy (oracle); return FALSE; } if (opts->format == MU_CONFIG_FORMAT_XQUERY) rv = print_xapian_query (oracle, query_str, err); else rv = process_query (oracle, query_str, opts, err); mu_query_destroy (oracle); g_free (query_str); return rv; }
//============================================================================= bool Uri::operator!=(const Uri& v) const { return get_scheme() != v.get_scheme() || get_host() != v.get_host() || get_port() != v.get_port() || get_path() != v.get_path() || get_query() != v.get_query(); }
//============================================================================= bool Uri::operator==(const Uri& v) const { return get_scheme() == v.get_scheme() && get_host() == v.get_host() && get_port() == v.get_port() && get_path() == v.get_path() && get_query() == v.get_query(); }
size_t List::find(Query&& q) const { verify_attached(); if (m_link_view) { size_t index = get_query().and_query(std::move(q)).find(); return index == not_found ? index : m_link_view->find(index); } return q.find(); }
JNIEXPORT void JNICALL Java_jp_marisa_QueryNative_text__Ljava_nio_ByteBuffer_2(JNIEnv *env, jobject pthis, jobject buff) { marisa::Query *query = get_query(env, pthis); void* native_buff = env->GetDirectBufferAddress(buff); const char* ptr = query->ptr(); const std::size_t length = query->length(); memcpy(native_buff, ptr, length); }
void ConstellationArtComponent::loadData(){ if(m_ConstList.isEmpty()) { QSqlDatabase skydb = QSqlDatabase::addDatabase("QSQLITE", "skycultures"); #ifdef Q_OS_OSX QString dbfile = KSPaths::locate(QStandardPaths::GenericDataLocation, "/skycultures/skycultures.sqlite"); #else QString dbfile = KSPaths::locate(QStandardPaths::GenericDataLocation, "skycultures.sqlite"); #endif skydb.setDatabaseName(dbfile); if (skydb.open() == false) { qWarning() << "Unable to open sky cultures database file " << dbfile << endl; return; } QSqlQuery get_query(skydb); if(cultureName=="Western") { if (!get_query.exec("SELECT * FROM western")) { qDebug() << get_query.lastError(); return; } } if(cultureName=="Inuit") { if (!get_query.exec("SELECT * FROM inuit")) { qDebug() << get_query.lastError(); return; } } while (get_query.next()) { QString abbreviation = get_query.value("Abbreviation").toString(); QString filename = get_query.value("Filename").toString(); QString midpointRA = get_query.value("MidpointRA").toString(); QString midpointDEC = get_query.value("MidpointDEC").toString(); double pa = get_query.value("Position Angle").toDouble(); double w = get_query.value("Width").toDouble(); double h = get_query.value("Height").toDouble(); dms midpointra = dms::fromString(midpointRA,false); dms midpointdec = dms::fromString(midpointDEC,true); // appends constellation info ConstellationsArt *ca = new ConstellationsArt(midpointra, midpointdec, pa, w,h, abbreviation, filename); m_ConstList.append(ca); //qDebug()<<"Successsfully read skyculture.sqlite"<<abbreviation<<filename<<midpointRA<<midpointDEC<<pa<<w<<h; records++; } //qDebug()<<"Successfully processed"<<records<<"records for"<<cultureName<<"sky culture"; skydb.close(); } }
Results List::sort(SortDescriptor order) const { verify_attached(); if (m_link_view) return Results(m_realm, m_link_view, util::none, std::move(order)); DescriptorOrdering new_order; new_order.append_sort(std::move(order)); return Results(m_realm, get_query(), std::move(new_order)); }
enum nss_status _nss_sqlite_getspnam_r(const char* name, struct spwd *spbuf, char *buf, size_t buflen, int *errnop) { sqlite3 *pDb; struct sqlite3_stmt* pSquery; int res; struct spwd entry; char* query; NSS_DEBUG("getspnam_r: looking for user %s (shadow)\n", name); if(sqlite3_open(NSS_SQLITE_SHADOW_DB, &pDb) != SQLITE_OK) { NSS_ERROR(sqlite3_errmsg(pDb)); sqlite3_close(pDb); return NSS_STATUS_UNAVAIL; } if(!(query = get_query(pDb, "getspnam_r")) ) { NSS_ERROR(sqlite3_errmsg(pDb)); sqlite3_close(pDb); return NSS_STATUS_UNAVAIL; } if(sqlite3_prepare(pDb, query, strlen(query), &pSquery, NULL) != SQLITE_OK) { NSS_ERROR(sqlite3_errmsg(pDb)); free(query); sqlite3_finalize(pSquery); sqlite3_close(pDb); return FALSE; } if(sqlite3_bind_text(pSquery, 1, name, -1, SQLITE_STATIC) != SQLITE_OK) { NSS_DEBUG(sqlite3_errmsg(pDb)); free(query); sqlite3_finalize(pSquery); sqlite3_close(pDb); return NSS_STATUS_UNAVAIL; } res = res2nss_status(sqlite3_step(pSquery), pDb, pSquery); if(res != NSS_STATUS_SUCCESS) { free(query); return res; } fill_shadow_sql(&entry, pSquery); res = fill_shadow(spbuf, buf, buflen, entry, errnop); free(query); sqlite3_finalize(pSquery); sqlite3_close(pDb); return res; }
/** * @brief redirect_to_splashpage * @param connection * @param client * @param host * @param url * @return */ static int redirect_to_splashpage(struct MHD_Connection *connection, t_client *client, const char *host, const char *url) { char *originurl = NULL; char *query = ""; get_query(connection, &query); safe_asprintf(&originurl, "http://%s%s%s%s", host, url, strlen(query) ? "?" : "" , query); return encode_and_redirect_to_splashpage(connection, originurl); }
__ramtext int flash_init(flash_t * flash, void *base_addr) { int res; unsigned u; uint16_t m_id, d_id; uint32_t base; struct cfi_query qry; /* retrieve and check manufacturer and device id */ res = get_id(base_addr, &m_id, &d_id); if (res) { return res; } if (m_id != CFI_MANUF_INTEL && m_id != CFI_MANUF_ST) { return -ENOTSUP; } /* retrieve and check query response */ res = get_query(base_addr, &qry); if (res) { return res; } if (qry.p_id != CFI_ALGO_INTEL_3) { /* we only support algo 3 */ return -ENOTSUP; } if (qry.num_erase_regions > FLASH_MAX_REGIONS) { /* we have a hard limit on the number of regions */ return -ENOTSUP; } /* fill in basic information */ flash->f_base = base_addr; flash->f_size = 1 << qry.dev_size; /* determine number of erase regions */ flash->f_nregions = qry.num_erase_regions; /* compute actual erase region info from cfi junk */ base = 0; for (u = 0; u < flash->f_nregions; u++) { flash_region_t *fr = &flash->f_regions[u]; fr->fr_base = (void *)base; fr->fr_bnum = qry.erase_regions[u].b_count + 1; fr->fr_bsize = qry.erase_regions[u].b_size * 256; base += fr->fr_bnum * fr->fr_bsize; } return 0; }
JNIEXPORT jbyteArray JNICALL Java_jp_marisa_QueryNative_text__(JNIEnv *env, jobject pthis) { marisa::Query *query = get_query(env, pthis); const char* ptr = query->ptr(); const std::size_t length = query->length(); jbyteArray java_array = env->NewByteArray(length); jbyte* native_array = env->GetByteArrayElements(java_array, NULL); memcpy(native_array, ptr, length); // commit env->ReleaseByteArrayElements(java_array, native_array, 0); return java_array; }
//void xcorr(float *tr1, float *tr2, double *corp, long long shift, void knn (float *buffer_delayembedding_selec, float * density_vals , vl_size len_array, int num_neighbours) { VL_PRINT ("KNN search !") ; printf("size of each frame = %llu\n", len_array); // instantiate a KD TREE object // VlKDForest returns new KDForest. // The data dimension dimension and the number of trees numTrees must not be smaller than one. VlKDForest* kdtree_obj; // define params for the object kdtree_obj = vl_kdforest_new(VL_TYPE_FLOAT, 3, 1, VlDistanceL2); // populate it with the data to be subsampled vl_kdforest_build (kdtree_obj,len_array,buffer_delayembedding_selec); // instantiate a searcher object for querying knn // A searcher is an object attached to the forest which must be created before running the queries. Each query has to be invoked with the searcher as its argument; make it point to the declared and defined kdtree VlKDForestSearcher* kdforest_search_obj=vl_kdforest_new_searcher(kdtree_obj); VlKDForestNeighbor neighbours[num_neighbours+1]; float *query = malloc(3*sizeof(float)); /* for (int i=0; i<len_array; i++) { printf("% d th original :%f %f %f\n",i, buffer_delayembedding_selec [3*i],buffer_delayembedding_selec [3*i+1],buffer_delayembedding_selec [3*i+2]); } */ for (int i=0; i<len_array; i++) { // printf("DBG: buffer selec[%d] :%f %f %f\n",i, buffer_delayembedding_selec [3*i],buffer_delayembedding_selec [3*i+1],buffer_delayembedding_selec [3*i+2]); get_query(buffer_delayembedding_selec , query , i); int nvisited = vl_kdforestsearcher_query(kdforest_search_obj, &neighbours[0], num_neighbours+1, query); // printf("visited nodes = %d ", nvisited); // printf("for knn of %dth node : (%f,%f,%f) :", i,*query,*(query+1),*(query+2)); density_vals[i]=1/sqrtf(neighbours[num_neighbours].distance); // printf("DB %f \n",( density_vals[i])); } // Destroy all created instances vl_kdforest_delete ( kdtree_obj ); free(query); }
multimap< string, string > Uri::get_query_parameters( void ) const { multimap< string, string > parameters; auto query = String::split( get_query( ), '&' ); for ( auto parameter : query ) { auto index = parameter.find_first_of( '=' ); auto name = decode_parameter( parameter.substr( 0, index ) ); auto value = decode_parameter( parameter.substr( index + 1, parameter.length( ) ) ); parameters.insert( make_pair( name, value ) ); } return parameters; }
int nm_read_query(CONTEXT *ctx) { notmuch_query_t *q; struct nm_ctxdata *data; int rc = -1; if (init_context(ctx) != 0) return -1; data = get_ctxdata(ctx); if (!data) return -1; dprint(1, (debugfile, "nm: reading messages...[current count=%d]\n", ctx->msgcount)); nm_progress_reset(ctx); q = get_query(data, FALSE); if (q) { switch(get_query_type(data)) { case NM_QUERY_TYPE_MESGS: read_mesgs_query(ctx, q, 0); break; case NM_QUERY_TYPE_THREADS: read_threads_query(ctx, q, 0, get_limit(data)); break; } notmuch_query_destroy(q); rc = 0; } if (!is_longrun(data)) release_db(data); ctx->mtime = time(NULL); mx_update_context(ctx, ctx->msgcount); data->oldmsgcount = 0; dprint(1, (debugfile, "nm: reading messages... done [rc=%d, count=%d]\n", rc, ctx->msgcount)); return rc; }
/** * @brief redirect_to_splashpage * @param connection * @param client * @param host * @param url * @return */ static int redirect_to_splashpage(struct MHD_Connection *connection, t_client *client, const char *host, const char *url) { char *originurl = NULL; char *query = NULL; int ret = 0; get_query(connection, &query); if (!query) { /* no mem */ return send_error(connection, 503); } safe_asprintf(&originurl, "http://%s%s%s%s", host, url, strlen(query) ? "?" : "" , query); ret = encode_and_redirect_to_splashpage(connection, originurl); free(originurl); free(query); return ret; }
//============================================================================= ScriptRef* Uri::script_op(const ScriptAuth& auth, const ScriptRef& ref, const ScriptOp& op, const ScriptRef* right) { if (right) { // binary ops const Uri* rv = dynamic_cast<const Uri*>(right->object()); if (rv) { // Uri x Uri ops switch (op.type()) { case ScriptOp::Equality: return ScriptInt::new_ref(*this == *rv); case ScriptOp::Inequality: return ScriptInt::new_ref(*this != *rv); case ScriptOp::Assign: if (!ref.is_const()) { if (rv) { *this = *rv; } } return ref.ref_copy(); default: break; } } if (ScriptOp::Lookup == op.type()) { std::string name = right->object()->get_string(); if (name == "scheme") return ScriptString::new_ref(get_scheme()); if (name == "host") return ScriptString::new_ref(get_host()); if (name == "port") return ScriptInt::new_ref(get_port()); if (name == "path") return ScriptString::new_ref(get_path()); if (name == "query") return ScriptString::new_ref(get_query()); if (name == "base") return ScriptString::new_ref(get_base()); } } return ScriptObject::script_op(auth,ref,op,right); }
static void start_searching (DialogData *data) { char *query; GFile *file; data->searching = TRUE; g_cancellable_reset (data->cancellable); gtk_widget_set_sensitive (GET_WIDGET ("cancel_search_button"), TRUE); query = get_query (data->album, data->artist); file = g_file_new_for_uri (query); g_load_file_async (file, G_PRIORITY_DEFAULT, data->cancellable, search_query_ready_cb, data); g_object_unref (file); g_free (query); }
void transfer_data(int fd) { struct Buff* query = NULL; int query_size = get_query(fd, &query); if (!is_correct_query(query, query_size)) { //Bad_reques; send(fd, HTTP_BAD_REQUEST, strlen(HTTP_BAD_REQUEST), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); return; } if (!is_version_1_1(query, query_size)) { //Unsupport version send(fd, HTTP_UNSUPPORTED_VERSION, strlen(HTTP_UNSUPPORTED_VERSION), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); return; } char* path = NULL; get_path(query, query_size, &path); if (path == NULL) { //Error at get path send(fd, HTTP_NOT_FOUND, strlen(HTTP_NOT_FOUND), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); return; } const int path_len = strlen(path); //fprintf(stderr, "Path = %s\n", path); for (int i = 0; i < query_size; ++i) { free_buff(&query[i]); } free(query); DIR* dir = opendir(path); if (dir == NULL) { if (errno == EACCES) { send(fd, HTTP_FORBIDDEN, strlen(HTTP_FORBIDDEN), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); } else { int ret = 0; if ((ret = send_file(fd, path)) == -1) { fprintf(stderr, "Can't open dir or file(path - %s, error - %d)\n", path, errno); send(fd, HTTP_NOT_FOUND, strlen(HTTP_NOT_FOUND), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); } else if (ret == -2) { send(fd, HTTP_FORBIDDEN, strlen(HTTP_FORBIDDEN), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); } } free(path); return; } send(fd, HTTP_OK, strlen(HTTP_OK), 0); send(fd, HTTP_HTML_CONTENT_TYPE, strlen(HTTP_HTML_CONTENT_TYPE), 0); send(fd, HTTP_END, strlen(HTTP_END), 0); send(fd, HTML_BEGIN, strlen(HTML_BEGIN), 0); struct dirent* ent = NULL; int index = 0; char i_file[MAX_NUM_STR_LENGTH]; while ((ent = readdir(dir)) != NULL) { snprintf(i_file, MAX_NUM_STR_LENGTH, "%d", index); ++index; int link_path_len = path_len + 1 + strlen(ent->d_name) + 1; char* link_path = (char*) calloc(link_path_len, sizeof(char)); if (link_path == NULL) { fprintf(stderr, "Can't allocate memory!\n"); continue; } if (path[path_len - 1] == '/') { snprintf(link_path, link_path_len, "%s%s", path, ent->d_name); } else { snprintf(link_path, link_path_len, "%s/%s", path, ent->d_name); } send(fd, HTML_TABLE_BEGIN, strlen(HTML_TABLE_BEGIN), 0); send(fd, i_file, strlen(i_file), 0); send(fd, " ", 1, 0); send(fd, HTML_LINK_BEGIN, strlen(HTML_LINK_BEGIN), 0); send(fd, link_path, strlen(link_path), 0); send(fd, HTML_LINK_MIDDLE, strlen(HTML_LINK_MIDDLE), 0); send(fd, ent->d_name, strlen(ent->d_name), 0); send(fd, HTML_LINK_END, strlen(HTML_LINK_END), 0); send(fd, HTML_TABLE_END, strlen(HTML_TABLE_END), 0); free(link_path); } closedir(dir); free(path); send(fd, HTML_END, strlen(HTML_END), 0); }
void CatalogDB::GetAllObjects(const QString &catalog, QList< SkyObject* > &sky_list, QList < QPair <int, QString> > &object_names, CatalogComponent *catalog_ptr) { sky_list.clear(); QString selected_catalog = QString::number(FindCatalog(catalog)); skydb_.open(); QSqlQuery get_query(skydb_); get_query.prepare("SELECT Epoch, Type, RA, Dec, Magnitude, Prefix, " "IDNumber, LongName, MajorAxis, MinorAxis, " "PositionAngle, Flux FROM ObjectDesignation JOIN DSO " "JOIN Catalog WHERE Catalog.id = :catID AND " "ObjectDesignation.id_Catalog = Catalog.id AND " "ObjectDesignation.UID_DSO = DSO.UID"); get_query.bindValue("catID", selected_catalog); // kWarning() << get_query.lastQuery(); // kWarning() << get_query.lastError(); // kWarning() << FindCatalog(catalog); if (!get_query.exec()) { kWarning() << get_query.lastQuery(); kWarning() << get_query.lastError(); } while (get_query.next()) { int cat_epoch = get_query.value(0).toInt(); unsigned char iType = get_query.value(1).toInt(); dms RA(get_query.value(2).toDouble()); dms Dec(get_query.value(3).toDouble()); float mag = get_query.value(4).toFloat(); QString catPrefix = get_query.value(5).toString(); int id_number_in_catalog = get_query.value(6).toInt(); QString lname = get_query.value(7).toString(); float a = get_query.value(8).toFloat(); float b = get_query.value(9).toFloat(); float PA = get_query.value(10).toFloat(); float flux = get_query.value(11).toFloat(); QString name = catPrefix + ' ' + QString::number(id_number_in_catalog); SkyPoint t; t.set(RA, Dec); if (cat_epoch == 1950) { // Assume B1950 epoch t.B1950ToJ2000(); // t.ra() and t.dec() are now J2000.0 // coordinates } else if (cat_epoch == 2000) { // Do nothing { } } else { // FIXME: What should we do? // FIXME: This warning will be printed for each line in the // catalog rather than once for the entire catalog kWarning() << "Unknown epoch while dealing with custom " "catalog. Will ignore the epoch and assume" " J2000.0"; } RA = t.ra(); Dec = t.dec(); if (iType == 0) { // Add a star StarObject *o = new StarObject(RA, Dec, mag, lname); sky_list.append(o); } else { // Add a deep-sky object DeepSkyObject *o = new DeepSkyObject(iType, RA, Dec, mag, name, QString(), lname, catPrefix, a, b, -PA); o->setFlux(flux); o->setCustomCatalog(catalog_ptr); sky_list.append(o); // Add name to the list of object names if (!name.isEmpty()) { object_names.append(qMakePair<int,QString>(iType, name)); } } if (!lname.isEmpty() && lname != name) { object_names.append(qMakePair<int,QString>(iType, lname)); } } get_query.clear(); skydb_.close(); }
int main() { struct query *q = get_query(); const char *game_id = get_query_param(q, "game_id"); FILE *f, *fm; char s[8192], p1[256], p2[256], q1[256], q2[256], id[256], r[256]; int w, h; memset(id, 0, sizeof(p1)); memset(q1, 0, sizeof(p1)); memset(q2, 0, sizeof(p1)); // printf("HTTP/1.0 200 OK\n"); printf("Content-Type: text/plain\n"); printf("Connection: close\n"); printf("\n"); /* f = fopen("441", "r"); while (fgets(s, sizeof(s), f)) printf("%s", s); return 0; */ if (strchr(game_id, '|')) { if (sscanf(game_id, "%255[^|]|%255[^|]|%255[^|]", id, q1, q2) != 3) { printf("Error: invalid game_id %s\n", game_id); goto done; } } else strlcpy(id, game_id, sizeof(id)); f = fopen(fn, "r"); while (fgets(s, sizeof(s), f)) { if (!strncmp(s, "[White \"", 8)) { memset(p1, 0, sizeof(p1)); sscanf(s + 8, "%255[^\"]", p1); } if (!strncmp(s, "[Black \"", 8)) { memset(p2, 0, sizeof(p2)); sscanf(s + 8, "%255[^\"]", p2); } if (!strncmp(s, "[Result \"", 9)) { memset(r, 0, sizeof(r)); sscanf(s + 9, "%255[^\"]", r); } if (!strncmp(s, id, strlen(id)) && (!q1[0] || !strcmp(p1, q1)) && (!q2[0] || !strcmp(p2, q2))) { /* map filename */ fgets(s, sizeof(s), f); s[strlen(s) - 1] = 0; int mapid = 0; sscanf(s, "maps/map%d.txt", &mapid); printf("game_id=%s\nwinner=0\nloser=0\nmap_id=%d\n" "draw=%s\n", id, mapid, strcmp(r, "1/2-1/2") ? "0" : "1"); printf("timestamp=%s\nplayer_one=%s\nplayer_two=%s\n", timestamp(atol(id)), p1, p2); /* game_id=4414272 winner=123465 loser=123485 map_id=741 draw=0 timestamp=2010-09-08 01:42:00 player_one=phreeza player_two=UloPee playback_string= */ if ((fm = fopen(s, "r")) == NULL) { printf("Error: fopen: %s: %s", fm, strerror(errno)); goto done; } printf("playback_string="); int planets = 0; while (fgets(s, sizeof(s), fm)) { double x, y; int owner, ships, growth; /* P 11.6742243424 11.649441005 0 56 3 P 15.5644784882 23.29888201 1 100 5 P 7.7839701966 0.0 2 100 5 */ if (s[0] != 'P' || s[1]!= ' ' || sscanf(s + 2, "%lf %lf %d %d %d", &x, &y, &owner, &ships, &growth) != 5) { printf("Error: sscanf: %s: %s", fm, s); goto done; } if (planets++) printf(":"); printf("%f,%f,%d,%d,%d", x, y, owner, ships, growth); } fclose(fm); int turns = 0; while (fgets(s, sizeof(s), f)) { s[strlen(s) - 1] = 0; if (!s[0]) break; printf("%c%s", turns++ ? ':' : '|', s); } printf("\n"); break; } } done: fclose(f); fflush(stdout); return (0); }
int ztest_search (void *handle, bend_search_rr *rr) { int err; char query[1024]; char query_final[2048]; char err_string[255]; int i; if (strcmp(rr->setname,"1")) { rr->errcode = 2; return 0; } //Si la requete n'est pas de type_1 if (rr->query->which!=2) { rr->errcode = 107; return 0; } err=get_query(query,rr->query->u.type_1->RPNStructure,err_string,0); if (!err) { yaz_log(LOG_LOG,"Translated Query = %s",query); } else { rr->errcode = err; rr->errstring = err_string; return 0; } if (rr->num_bases != 1) { rr->errcode = 23; return 0; } if (yaz_matchstr (rr->basenames[0], database)) { rr->errcode = 109; rr->errstring = rr->basenames[0]; return 0; } /* Lancement de la recherche */ sprintf(query_final,"query=%s&command=search",url_encode(query)); yaz_log(LOG_LOG,"query:%s",query_final); if (http_get(query_final)) { rr->errcode=2; return 0; } if (http_err==3) { rr->errcode=114; rr->errstring=http_err_string; return 0; } strcpy(id_set,http_content); n_results=atoi(strtok(id_set,"@")); cur_results=0; i=0; while ((ids[i]=strtok(NULL,"@"))!=NULL) { i++; } rr->hits = n_results; return 0; }
int get_query(char *result, Z_RPNStructure *query_s, char *err_string, int level) { /*Analyse de la requete*/ char result1[500]; char result2[500]; char ope[8]; char escaped_buf[2048]; int err; int use; err=0; sprintf(err_string,""); if (query_s->which==Z_RPNStructure_complex) { switch (query_s->u.complex->roperator->which) { case Z_Operator_and: sprintf(ope,"and"); break; case Z_Operator_or: sprintf(ope,"or"); break; case Z_Operator_and_not: sprintf(ope,"and not"); break; default: sprintf(ope,""); err=110; return err; break; } err=get_query(result1,query_s->u.complex->s1,err_string, level+1); if (err) return err; err=get_query(result2,query_s->u.complex->s2,err_string, level+1); if (err) return err; sprintf(result,"%s arg%i!1(%s) arg%i!2(%s)",ope,level,result1,level,result2); } else { //Nombre d'attributs pour le terme > 1 ? if (query_s->u.simple->u.attributesPlusTerm->attributes->num_attributes!=1) { err=123; return err; } //Type d'attribut <> 1 ? if (*query_s->u.simple->u.attributesPlusTerm->attributes->attributes[0]->attributeType!=1) { err=113; return err; } //Attribut autorisé ? use = *query_s->u.simple->u.attributesPlusTerm->attributes->attributes[0]->value.numeric; /* if ((use!=7)&&(use!=1003)&&(use!=4)) { err=114; sprintf(err_string,"1=%i",use); return err; }*/ //Type de Terme autorisé ? if (query_s->u.simple->u.attributesPlusTerm->term->which!=1) { err=229; return err; } strcpy(escaped_buf,query_s->u.simple->u.attributesPlusTerm->term->u.general->buf); sprintf(result,"%i=%s",use,escaped_buf); } return 0; }
inline int client_handler(mg_connection* connection,mg_event event) { if(event==MG_AUTH) return MG_TRUE; if(event==MG_REQUEST) { std::string client(connection->remote_ip); for(int ii=0;ii<connection->num_headers&&client=="127.0.0.1";++ii) if(std::string(connection->http_headers[ii].name)=="X-Forwarded-For") client=connection->http_headers[ii].value; std::string method=(connection->request_method); std::string request(connection->uri); std::string post_data; std::string nonce_string=get_query(connection,"nonce"); if(method=="POST") post_data=std::string(connection->content,connection->content_len); std::string query; if(connection->query_string!=nullptr) query=connection->query_string; auto& database=get_database(connection); bool authenticated=false; std::string auth=get_query(connection,"auth"); if(auth.size()>0) { std::string query_no_auth=replace_all(query,"&auth="+auth,""); query_no_auth=replace_all(query_no_auth,"auth="+auth,""); authenticated=database.authenticate(query_no_auth+post_data,auth); } std::cout<<client; if(client==std::string(connection->remote_ip)) std::cout<<" NOLOOKUP"; else std::cout<<" LOOKUP "; if(!authenticated) std::cout<<" NOAUTH"; else std::cout<<" AUTH "; std::cout<<" "<<method<<" "<<request<<"."<<std::endl; std::cout<<"\tQuery: \""<<query<<"\""<<std::endl; if(method=="POST") std::cout<<"\tPost: \""<<post_data<<"\""<<std::endl; if(nonce_string!=""&&nonce_string!="false") { handle_nonce(connection); return MG_TRUE; } bool wrote=false; if(method=="POST") wrote=handle_write(connection,authenticated,request,query,post_data); bool read=handle_read(connection,authenticated,request,query); if(wrote||read) return MG_TRUE; } return MG_FALSE; }