Пример #1
0
/*
 * construct SetupList (policy) part of manifest structure (w/o channels)
 * note: malloc(). must be called only once
 */
void SetupUserPolicy(struct NaClApp *nap)
{
  /* allocate space for policy */
  struct SetupList *policy = malloc(sizeof(*policy));
  COND_ABORT(!policy, "cannot allocate memory for user policy\n");
  policy->self_size = sizeof(*policy); /* set self size */

  /* setup limits */
  TRANSET(policy->max_cpu, "CPUMax");
  TRANSET(policy->max_mem, "MemMax");
  TRANSET(policy->max_setup_calls, "SetupCallsMax");
  TRANSET(policy->max_syscalls, "SyscallsMax");

  /* setup counters */
  policy->cnt_cpu = 0;
  policy->cnt_cpu_last = 0;
  policy->cnt_mem = 0;
  policy->cnt_setup_calls = 0;
  policy->cnt_syscalls = 0;
  policy->heap_ptr = 0; /* set user heap to NULL until it allocated */

  /* clear syscallback */
  policy->syscallback = 0;

  /* setup custom attributes */
#define STRNCPY_NULL(a, b, n) if ((a) && (b)) strncpy(a, b, n);
  STRNCPY_NULL(policy->content_type, get_value_by_key(nap, "ContentType"), CONTENT_TYPE_LEN);
  STRNCPY_NULL(policy->timestamp, get_value_by_key(nap, "TimeStamp"), TIMESTAMP_LEN);
  STRNCPY_NULL(policy->x_object_meta_tag, get_value_by_key(nap, "XObjectMetaTag"), X_OBJECT_META_TAG_LEN);
  STRNCPY_NULL(policy->user_etag, get_value_by_key(nap, "UserETag"), USER_TAG_LEN);
#undef STRNCPY_NULL
  nap->manifest->user_setup = policy;
}
void Query::init_people()
{
	int i;
	QSqlQuery query;
	QString sql;

	for (i = 0; i < PARAMETER_SIZE; i++) {
		this->lists[i] = NULL;
	}
	this->people =  new People[11000];
	this->npeople = 0;

	i = 0;
	sql = "select number,name,birthday,jointime,people,jiguan,\
		  bingyuan,wenhua,bingzhong,junxian,region from info";
	query.exec(sql);
	while (query.next()) {
		QString number = query.value(0).toString().toUpper();
		QString name = query.value(1).toString();
		QString birthday = query.value(2).toString();
		QString jointime = query.value(3).toString();
		QString nation = query.value(4).toString();
		int nativeplace = get_value_by_key(nativeplace_map, query.value(5).toString());
		QString soldierhome = query.value(6).toString();
		int education = get_value_by_key(education_map, query.value(7).toString());
		int armtype = get_value_by_key(armtype_map, query.value(8).toString());
		int military = get_value_by_key(militaryrank_map, query.value(9).toString());
		int district = get_value_by_key(district_map, query.value(10).toString());

		people[i].number = number;
		people[i].name = name;
		people[i].birthday = birthday;
		people[i].birthday = birthday;
		people[i].jointime = jointime;
		people[i].nation = nation;
		people[i].nativeplace = nativeplace;
		people[i].soldierhome = soldierhome;
		people[i].education = education;
		people[i].armtype = armtype;
		people[i].military = military;
		people[i].district = district;
//void Query::build_index(People *p, int key, enum parameter_t pm)
		build_index(&people[i], nativeplace, NATIVEPLACE);
		build_index(&people[i], education, EDUCATION);
		build_index(&people[i], military, MILITARYRANK);
		build_index(&people[i], armtype, ARMTYPE);
		build_index(&people[i], district, DISTRICT);

		people_map.insert(number, i);
		i = i + 1;
	}
	this->npeople = i;
}
void Query::query_data(Stat &stat, QString item, QString nativeplace, 
					   QString district, QString armtype, QString education, QString militaryrank)
{
	int pm;
	QList<int> parameters;

	stat.reset();
	if (item == "") return;

	parameters << get_value_by_key(nativeplace_map, nativeplace);
	parameters << get_value_by_key(district_map, district);
	parameters << get_value_by_key(armtype_map, armtype);
	parameters << get_value_by_key(education_map, education);
	parameters << get_value_by_key(militaryrank_map, militaryrank);

	pm = 0;
	while (pm < PARAMETER_SIZE && parameters[pm] == -1) {
		pm++;
	}
	if (pm == PARAMETER_SIZE) {
		for (int i = 0; i < this->npeople; i++) {
			People *p = &people[i];
			float item_data = get_data_by_item(p, item);
			if (item_data > 0) {
				stat.add_element(item_data);
			}
		}
	} else {
		List *l = find_list(parameters[pm], pm);
		People *p = l->first;

		while (p) {
			bool all_parameter_match = true;
			for (int ii = pm + 1; ii < PARAMETER_SIZE; ii++) {
				if (parameters[ii] != -1 && !match_parameter(p, ii, parameters[ii])) {
					all_parameter_match = false;
					break;
				}
			}
			float item_data = get_data_by_item(p, item);
			if (all_parameter_match && item_data > 0) {
				stat.add_element(item_data);
			}
			p = p->next[pm];
		}
	}
}
Пример #4
0
/*
 * construct Report (zerovm report to proxy) part of manifest structure
 * note: malloc(). must be called only once
 */
void SetupReportSettings(struct NaClApp *nap)
{
  /*
   * allocate space for report
   * todo: memory must be allocated before nexe start
   */
  struct Report *report = malloc(sizeof(*report));
  COND_ABORT(!report, "cannot allocate memory for report\n");

  /* set results. note: etag is temporary disabled  */
  report->etag = MakeEtag(nap);

  /* get custom attributes from the manifest */
  report->content_type = get_value_by_key(nap, "ContentType");
  report->x_object_meta_tag = get_value_by_key(nap, "XObjectMetaTag");

  nap->manifest->report = report;
}
Пример #5
0
int
main(int argc, char **argv) 
{
    char        mode[32] = {0};
    int         ret = -1;
    FILE        *fp;

    // section 和 key 获取 value
    printf("==================start==================\n");
    printf("=====================================\n");
    printf("根据sction和key获取value值:\n");
    fp = fopen("/root/waf/a.info", "r");
    if (fp == NULL) {
        printf("打开文件%s失败!\n", "/root/waf/a.info");
        goto second;
    }
    ret = section_get_value_by_key(fp, "History", "policy", mode);
    if (ret < 0) {
        printf("发生错误!\n");
        fclose(fp);
        fp = NULL;
        return ret;
    }
    fclose(fp);
    fp = NULL;
    printf("section=%s key=%s value=%s\n","History", "policy", mode);
    printf("=====================================\n");
    printf("=================end===================\n\n");

second:
    // key 获取 value
    printf("==================start==================\n");
    printf("=====================================\n");
    printf("根据获取value值:\n");
    fp = fopen("./option.conf", "r");
    if (fp == NULL) {
        printf("打开文件%s失败!\n", "./option.conf");
    }
    ret = get_value_by_key(fp, "TOPWAF_EXPIRE", mode);
    if (ret < 0) {
        printf("发生错误!\n");
        fclose(fp);
        fp = NULL;
        return ret;
    }
    fclose(fp);
    fp = NULL;
    printf("key=%s value=%s\n", "TOPWAF_EXPIRE", mode);
    printf("=====================================\n");
    printf("=================end===================\n\n");
    return 0;
}
Пример #6
0
//---------------------------------------------------------------------------
Container::Value* Json::get_value_in_array_by_key(Value& v, const std::string& key)
{
    if (v.type != Value::CONTAINER_TYPE_ARRAY)
        return NULL;

    for (size_t i = 0; i < v.array.size(); ++i)
    {
        Container::Value* val = get_value_by_key(v.array[i], key);
        if (val)
            return val;
    }
    return NULL;
}
Пример #7
0
/*
 * construct i/o channel and update SetupList with not mounted channel
 * if successful return 0, otherwise - 1
 * note: SetupList object must be allocated
 */
int32_t ConstructChannel(struct NaClApp *nap, enum ChannelType ch)
{
  /* allocate channel */
  char prefix[1024];
  struct PreOpenedFileDesc *channel = &nap->manifest->user_setup->channels[ch];
  channel->self_size = sizeof(*channel); /* set self size */
  GetChannelPrefixById(ch, prefix);

  /*
   * todo: we must detect not initialized keywords
   * and make default actions (or set default values)
   */
#define SET_LIMIT(a, limit)\
  do {\
    char str[1024];\
    char *p;\
    if(!limit) break;\
    sprintf(str, "%s%s", prefix, limit);\
    p = get_value_by_key(nap, str);\
    a = p ? atoll(p) : 0;\
  } while (0);

  /* check if channel is set in manifest and set main attributes */
  channel->name = (uint64_t)get_value_by_key(nap, prefix);
  if(!channel->name) return 1;
  SET_LIMIT(channel->mounted, "Mode");
  channel->type = ch;

  /* set limits */
  SET_LIMIT(channel->max_size, "Max");
  SET_LIMIT(channel->max_get_size, "MaxGet");
  SET_LIMIT(channel->max_gets, "MaxGetCnt");
  SET_LIMIT(channel->max_put_size, "MaxPut");
  SET_LIMIT(channel->max_puts, "MaxPutCnt");

  /* set counters */
  channel->cnt_get_size = 0;
  channel->cnt_gets = 0;
  channel->cnt_put_size = 0;
  channel->cnt_puts = 0;

#undef SET_LIMIT
  return 0;
}
void Query::init_data()
{
	QString sql;
	QSqlQuery query;

	for (int t = 0; t < TABLESIZE; t++) {
		sql = "select number, " + table.all_column_str(t) + " from " + table.get_table_str(t);
		//qDebug() << sql;
		query.exec(sql);
		while (query.next()) {
			QString number = query.value(0).toString().toUpper();
			int ind = get_value_by_key(people_map, number);
			if (ind != -1) {
				People *p = &people[ind];
				fill_data(query, p, t);
			} else {
				//qDebug() << "找不到军人 " << number;
			}
		}
	}
}
Пример #9
0
/*
 * construct SystemList (zerovm settings) part of manifest structure
 * note: malloc(). must be called only once
 */
void SetupSystemPolicy(struct NaClApp *nap)
{
  /* allocate space for policy */
  struct SystemList *policy = malloc(sizeof(*policy));
  COND_ABORT(!policy, "cannot allocate memory for system policy\n");

  /* get zerovm settings */
  policy->version = get_value_by_key(nap, "Version");
  policy->zerovm = get_value_by_key(nap, "ZeroVM");
  policy->log = get_value_by_key(nap, "Log");
  policy->report = get_value_by_key(nap, "Report");
  COND_ABORT(policy->nexe, "nexe file name is already specified in the command line\n");
  policy->nexe = get_value_by_key(nap, "Nexe");
  policy->blob = get_value_by_key(nap, "Blob");
  policy->nexe_etag = get_value_by_key(nap, "NexeEtag");

  TRANSET(policy->nexe_max, "NexeMax");
  TRANSET(policy->timeout, "Timeout");
  TRANSET(policy->kill_timeout, "KillTimeout");

  nap->manifest->system_setup = policy;
}
Пример #10
0
int main(int argc, char* argv[]) {
    std::string output_filename;

    static struct option long_options[] = {
        {"help",         no_argument, 0, 'h'},
        {"output", required_argument, 0, 'o'},
        {0, 0, 0, 0}
    };

    while (1) {
        int c = getopt_long(argc, argv, "ho:", long_options, 0);
        if (c == -1)
            break;

        switch (c) {
            case 'h':
                print_help();
                exit(return_code_ok);
            case 'o':
                output_filename = optarg;
                break;
            default:
                exit(return_code_fatal);
        }
    }

    if (output_filename.empty()) {
        std::cerr << "Missing -o/--output=OSMFILE option\n";
        exit(return_code_cmdline);
    }

    if (optind != argc - 1) {
        std::cerr << "Usage: osmcoastline_filter [OPTIONS] OSMFILE\n";
        exit(return_code_cmdline);
    }

    osmium::io::Header header;
    header.set("generator", "osmcoastline_filter");
    header.add_box(osmium::Box(-180.0, -90.0, 180.0, 90.0));

    osmium::io::File infile(argv[optind]);

    try {
        osmium::io::Writer writer(output_filename, header);

        std::set<osmium::object_id_type> ids;
        osmium::memory::Buffer output_buffer(10240);

        {
            osmium::io::Reader reader(infile, osmium::osm_entity_bits::way);
            while (auto input_buffer = reader.read()) {
                for (auto it = input_buffer.begin<const osmium::Way>(); it != input_buffer.end<const osmium::Way>(); ++it) {
                    const char* natural = it->get_value_by_key("natural");
                    if (natural && !strcmp(natural, "coastline")) {
                        output_buffer.add_item(*it);
                        output_buffer.commit();
                        if (output_buffer.committed() >= 10240) {
                            osmium::memory::Buffer new_buffer(10240);
                            std::swap(output_buffer, new_buffer);
                            writer(std::move(new_buffer));
                        }
                        for (const auto& nr : it->nodes()) {
                            ids.insert(nr.ref());
                        }
                    }
                }
            }
            reader.close();
        }

        {
            osmium::io::Reader reader(infile, osmium::osm_entity_bits::node);
            while (auto input_buffer = reader.read()) {
                for (auto it = input_buffer.begin<const osmium::Node>(); it != input_buffer.end<const osmium::Node>(); ++it) {
                    const char* natural = it->get_value_by_key("natural");
                    if ((ids.find(it->id()) != ids.end()) || (natural && !strcmp(natural, "coastline"))) {
                        output_buffer.add_item(*it);
                        output_buffer.commit();
                        if (output_buffer.committed() >= 10240) {
                            osmium::memory::Buffer new_buffer(10240);
                            std::swap(output_buffer, new_buffer);
                            writer(std::move(new_buffer));
                        }
                    }
                }
            }
            reader.close();
        }

        if (output_buffer.committed() > 0) {
            writer(std::move(output_buffer));
        }

        writer.close();
    } catch (osmium::io_error& e) {
        std::cerr << "io error: " << e.what() << "'\n";
        exit(return_code_fatal);
    }

    google::protobuf::ShutdownProtobufLibrary();
}