static NEOERR* city_cmd_id(struct city_entry *e, QueueEntry *q) { unsigned char *val = NULL; size_t vsize = 0; int id; NEOERR *err; mdb_conn *db = e->db; struct cache *cd = e->cd; REQ_GET_PARAM_INT(q->hdfrcv, "id", id); if (cache_getf(cd, &val, &vsize, PREFIX_CITY"%d", id)) { unpack_hdf(val, vsize, &q->hdfsnd); } else { MDB_QUERY_RAW(db, "city", _COL_CITY, "id=%d", NULL, id); err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_Z); if (err != STATUS_OK) return nerr_pass(err); /* * get city's parents */ int cnt = 0; char *pid = hdf_get_valuef(q->hdfsnd, "citys.0.pid"); while (pid && atoi(pid) > 0) { MDB_QUERY_RAW(db, "city", _COL_CITY, "id=%d", NULL, atoi(pid)); err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_Z); TRACE_NOK(err); pid = hdf_get_valuef(q->hdfsnd, "citys.%d.pid", ++cnt); } CACHE_HDF(q->hdfsnd, CITY_CC_SEC, PREFIX_CITY"%d", id); } return STATUS_OK; }
static int ewf_request_type(void) { char *val = NULL; val = hdf_get_valuef(cgi->hdf, "HTTP.XRequestedHandler"); if (val != NULL && nbu_string_matches(val, "ajax") == NBU_STRING_EQUAL) { /* ajax request */ nbu_log_debug("request type: AJAX"); return ajax_request; } val = hdf_get_valuef(cgi->hdf, "CGI.RequestMethod"); if (val != NULL && nbu_string_matches(val, "POST") == NBU_STRING_EQUAL) { /* form request */ nbu_log_debug("request type: FORM"); return form_request; } /* otherwise display request */ nbu_log_debug("request type: DISPLAY"); return display_request; }
/* * input : uname(STR) aname(STR) * return: NORMAL * reply : NULL */ static NEOERR* aic_cmd_appuserin(struct queue_entry *q, struct cache *cd, mdb_conn *db) { STRING str; string_init(&str); char *aname, *uname; int aid, uid; NEOERR *err; REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname); REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname); aid = hash_string(aname); uid = hash_string(uname); hdf_set_int_value(q->hdfrcv, "uid", uid); hdf_set_int_value(q->hdfrcv, "aid", aid); err = aic_cmd_appusers(q, cd, db); if (err != STATUS_OK) return nerr_pass(err); if (hdf_get_valuef(q->hdfsnd, "userlist.%s.uname", uname)) return STATUS_OK; err = mcs_build_incol(q->hdfrcv, hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.userinfo"), &str); if (err != STATUS_OK) return nerr_pass(err); MDB_EXEC(db, NULL, "INSERT INTO userinfo %s", NULL, str.buf); string_clear(&str); cache_delf(cd, PREFIX_USERLIST"%d", aid); return STATUS_OK; }
bool lutil_client_attack(HDF *hdf, session_t *ses, char *cname) { if (!hdf || !ses || !ses->dataer) return false; char *limit = hdf_get_valuef(g_cfg, PRE_CFG_REQLIMIT".%s", ses->dataer); if (!limit || atoi(limit) <= 0) return false; return mutil_client_attack(hdf, ses->dataer, cname, atoi(limit), ONE_MINUTE); }
int mmg_get_int_valuef(mmg_conn *db, char *dsn, char *key, int skip, int limit, char *qfmt, ...) { HDF *tmpnode; hdf_init(&tmpnode); char *querys, sels[256]; int val; va_list ap; HDF *node; NEOERR *err; va_start(ap, qfmt); querys = vsprintf_alloc(qfmt, ap); va_end(ap); if (!querys) { mtc_err("Unable to allocate mem for query string"); return 0; } snprintf(sels, sizeof(sels), "{'%s': 1}", key); err = mmg_prepare(db, MMG_FLAG_EMPTY, skip, limit, NULL, sels, querys); RETURN_V_NOK(err, 0); err = mmg_query(db, dsn, NULL, tmpnode); RETURN_V_NOK(err, 0); val = 0; if(hdf_get_valuef(tmpnode, "0.%s", key)) { node = hdf_obj_child(tmpnode); while (node) { val += hdf_get_int_value(node, key, 0); node = hdf_obj_next(node); } } else { val = hdf_get_int_value(tmpnode, key, 0); } hdf_destroy(&tmpnode); SAFE_FREE(querys); return val; }
int ewf_fastcgi_get_parameter( const char *name, char **value ) { char buf[64]; if ( name == NULL ) { nbu_log_error( "param name is NULL" ); return EWF_ERROR; } nbu_string_printf( buf, sizeof buf, "Query.%s", name ); *value = hdf_get_valuef( cgi->hdf, buf ); if ( *value == NULL ) { return EWF_ERROR; } return EWF_SUCCESS; }
static NEOERR* aic_cmd_appuserout(struct queue_entry *q, struct cache *cd, mdb_conn *db) { char *uname, *aname; int aid; NEOERR *err; REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname); REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname); aid = hash_string(aname); err = aic_cmd_appusers(q, cd, db); if (err != STATUS_OK) return nerr_pass(err); if (!hdf_get_valuef(q->hdfsnd, "userlist.%s.uname", uname)) return nerr_raise(REP_ERR_NOTJOIN, "%s not join %s", uname, aname); MDB_EXEC(db, NULL, "DELETE FROM userinfo WHERE uid=%d AND aid=%d;", NULL, hash_string(uname), aid); cache_delf(cd, PREFIX_USERLIST"%d", aid); return STATUS_OK; }
/* TODO read file's type */ char* mfile_get_type(CGI *cgi, char *form_name) { if (form_name) return hdf_get_valuef(cgi->hdf, PRE_QUERY".%s.Type", form_name); else return hdf_get_value(cgi->hdf, "HTTP.XFileType", NULL); }
static NEOERR* city_cmd_s(struct city_entry *e, QueueEntry *q) { unsigned char *val = NULL; size_t vsize = 0; char *p = NULL, *c; NEOERR *err; mdb_conn *db = e->db; struct cache *cd = e->cd; REQ_GET_PARAM_STR(q->hdfrcv, "c", c); REQ_FETCH_PARAM_STR(q->hdfrcv, "p", p); if (cache_getf(cd, &val, &vsize, PREFIX_CITY"%s.%s", p, c)) { unpack_hdf(val, vsize, &q->hdfsnd); } else { if (p) { char tok[64] = {0}; strncpy(tok, p, 64); if (!strstr(p, "省") && !strstr(p, "区")) snprintf(tok, sizeof(tok), "%s省", p); MDB_QUERY_RAW(db, "city", _COL_CITY, "s=$1", "s", tok); mdb_set_row(q->hdfsnd, db, _COL_CITY, "province", MDB_FLAG_NO_ERR); } MDB_QUERY_RAW(db, "city", _COL_CITY, "s=$1", "s", c); err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_Z); if (nerr_handle(&err, NERR_NOT_FOUND)) { if (strstr(c, "市")) c[strlen(c)-3] = '\0'; MDB_QUERY_RAW(db, "city", _COL_CITY, "s=$1", "s", c); err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_EMPTY_OK); } if (err != STATUS_OK) return nerr_pass(err); /* * get city's parents */ int cnt = 0; char *pid = hdf_get_valuef(q->hdfsnd, "citys.0.pid"); while (pid && atoi(pid) > 0) { MDB_QUERY_RAW(db, "city", _COL_CITY, "id=%d", NULL, atoi(pid)); err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "citys", NULL, MDB_FLAG_Z); TRACE_NOK(err); pid = hdf_get_valuef(q->hdfsnd, "citys.%d.pid", ++cnt); } /* * 北京市 has no subcities */ /* int id = hdf_get_int_value(q->hdfsnd, "city.id", 0); MDB_QUERY_RAW(db, "city", _COL_CITY, "pid=%d", NULL, id); err = mdb_set_rows(q->hdfsnd, db, _COL_CITY, "subcities", NULL, MDB_FLAG_EMPTY_OK); if (err != STATUS_OK) return nerr_pass(err); */ CACHE_HDF(q->hdfsnd, CITY_CC_SEC, PREFIX_CITY"%s.%s", p, c); } return STATUS_OK; }