예제 #1
0
void findLaddersDST(
	const string& start,
	const string& end,
	unordered_set<string> &dict,
	vector<string>& ladder,
	vector<vector<string> >& ladders)
{
	if (isChangable(start, end))
	{
		ladder.push_back(end);
		ladders.push_back(ladder);
		return;
	}

	unordered_set<string>::iterator it = dict.begin();
	unordered_set<string>::iterator it_end = dict.end();

	while (it != it_end)
	{
		string str = *it;

		if (isChangable(str, start))
		{
			unordered_set<string> new_dict(dict);
			vector<string> new_ladder(ladder);
			new_dict.erase(str);
			new_ladder.push_back(str);

			findLaddersDST(str, end, new_dict, new_ladder, ladders);
		}
		it++;
	}
}
예제 #2
0
파일: subjson.c 프로젝트: josephwecker/mx
int toplevel(pstate *state) {
    UNPACK_STATE();
    int found = 0;
    while(curr <= eof) {
        qscan3('{','[','#');
        switch(*curr) {
            case '{': discard(); found += new_dict(state); break;
            case '[': discard(); found += new_list(state); break;
            case '#': discard(); found ++; break;
            default:  discard(); // EOF
        }
    }
    return found;
}
예제 #3
0
파일: pkv.c 프로젝트: flirc/prjstart
struct pkv *new_pkv(uint32_t type)
{
	struct pkv *p;

	if((p = malloc(sizeof(*p))) == NULL) {
		logerror("could not allocate new pkv : %s\n", strerror(errno));
		return NULL;
	}
	memset(p, 0, sizeof(*p));

	p->type = type;

	if((p->payload = new_dict()) == NULL) {
		logerror("could not allocate new pkv payload\n");
		free(p);
		return NULL;
	}

	return p;
}
예제 #4
0
int main(int argc, char** argv) {
    if (argc < 3) {
        printf("Bad args\n");
        return 1;
    }

    char* str = argv[1];
    unsigned long value = strtoul(argv[2], 0, 10);

    struct dict t;
    if(new_dict("dictname", &t) == -1) {
        printf("Internal error\n");
        return 1;
    }

    t.set(str, value);
    printf("%lu\n", t.validate());

    return 0;
}
예제 #5
0
파일: account.c 프로젝트: JJjie/RuCTF-2015
int gen_page() {
    char* login = cgigetval("login");
    if(check_args(login) == -1) {
        return 1;
    }

    printf("              <h1>Your bank accounts (%s)</h1>\n", login);
    printf("              <div class='extra-space-m'></div>\n");

    struct dict t;
    if(new_dict(login, &t) == -1) {
        printf("Internal error\n");
        return 1;
    }

    long accounts_num = t.size();
    if (accounts_num == 0) {
        printf("<h6>You don't have any accounts yet</h6>\n");
        printf("<br>\n");
    } else {
        printf("  <table class='table table-striped'>\n");

        printf("  <thead>\n");
        printf("      <tr>\n");
        printf("          <th>Account</th>\n");
        printf("          <th>Balance</th>\n");
        printf("          <th class='col-md-1 text-right'></th>\n");
        printf("      </tr>\n");
        printf("  </thead>\n");
        printf("  <tbody>\n");


        int i;
        for (i = 0; i < accounts_num; i += 1) {
            unsigned char* key = t.key_at(i);
            if (!key) {
                continue;
            }

            unsigned long value = t.get(key);

            printf("      <tr>\n");
            printf("          <td>%s</td>\n", key);
            printf("          <td>%lu₽</td>\n", value);
            printf("          <td class='col-md-1 text-right'><span data-toggle='modal' data-target='#Modal%d' class='glyphicon glyphicon-transfer pointer-cursor' aria-hidden='true'></span></td>\n", i);
            printf("<div id='Modal%d' class='modal fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>\n", i);
            printf(" <div class='modal-dialog'>\n");
            printf("    <div class='modal-content'>\n");
            printf("      <div class='modal-header'>\n");
            printf("        <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;  </button>\n");
            printf("        <h4 class='modal-title' id='myModalLabel'>Transfer money</h4>\n");
            printf("      </div>\n");
            printf("      <form action='transfer_money.cgi'>\n");
            printf("      <div class='modal-body'>\n");
            printf("        <div class='form-group'>\n");
            printf("          <label for='fromAccount'>From</label>\n");
            printf("          <input value='%s' name='account' class='form-control' id='fromAccount' placeholder='Account' readonly>\n", key);
            printf("        </div>\n");
            printf("        <div class='form-group'>\n");
            printf("          <label for='toLogin'>To</label>\n");
            printf("          <input value='' name='login_to' class='form-control' id='toLogin' placeholder='Login'>\n");
            printf("          <input value='' name='account_to' class='form-control' id='toLogin' placeholder='Account'>\n");
            printf("        </div>\n");
            printf("        <div class='form-group'>\n");
            printf("          <label for='toAmount'>Amount</label>\n");
            printf("          <input type='number' value='' min='0' name='amount' class='form-control' id='toAmount' placeholder='Up to %lu₽'>\n", value);
            printf("        </div>\n");
            printf("        <input type='hidden' value='%s' name='login'><br>\n", login);
            printf("      </div>\n");
            printf("      <div class='modal-footer'>\n");
            printf("        <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>\n");
            printf("        <input type='submit' class='btn btn-primary' value='Execute'>\n");
            printf("      </div>\n");
            printf("      </form>\n");
            printf("    </div>\n");
            printf("  </div>\n");
            printf("</div>\n");
            printf("      </tr>\n");
        }

        printf("  </tbody>\n");
        printf("  </table>\n");

    }
    printf("         <form class='sparser-form form-inline' action='add_money.cgi'>\n");
    printf("         <input type='hidden' value='%s' name='login'><br>\n", login);
    printf("         <legend><h5>Add money to the account (this is free and always will be):</h5></legend>\n");
    printf("         <div class='form-group'>\n");
    printf("         <input class='form-control' id='account' value='' name='account' placeholder='Account'>\n");
    printf("         </div>\n");
    printf("         <div class='form-group'>\n");
    printf("         <input type='number' min='0' class='form-control' id='amount' value='' name='amount' placeholder='Amount'>\n");
    printf("         </div>\n");
    printf("         <button type='submit' class='btn btn-success'>Add</button>\n");
    printf("         </form>\n");
    printf("         <div class='extra-space-l'></div>\n");
    printf("         <?--JuryValidator:%lu-->\n", t.validate());
}
예제 #6
0
파일: rf.cpp 프로젝트: rkday/ralf
// Create an ACR message from a JSON descriptor.  Most AVPs are auto-created from the
// contents parameter which should be a JSON object with keys named after AVPs.  For example
// this object could be the "event" part of the original HTTP request received by Ralf.
AccountingRequest::AccountingRequest(const Dictionary* dict,
                                     Diameter::Stack* diameter_stack,
                                     const std::string& session_id,
                                     const std::string& dest_host,
                                     const std::string& dest_realm,
                                     const uint32_t& record_number,
                                     const rapidjson::Value& contents) :
  Diameter::Message(dict, dict->ACCOUNTING_REQUEST, diameter_stack)
{
  LOG_DEBUG("Building an Accounting-Request");

  // Fill in the default fields
  if (session_id == "")
  {
    add_new_session_id();
  }
  else
  {
    add_session_id(session_id);
  }
  add_origin();
  add_app_id(Dictionary::Application::ACCT, dict->RF);

  // Fill in contributed fields
  Diameter::Dictionary::AVP dest_host_dict("Destination-Host");
  Diameter::AVP dest_host_avp(dest_host_dict);
  add(dest_host_avp.val_str(dest_host));

  Diameter::Dictionary::AVP dest_realm_dict("Destination-Realm");
  Diameter::AVP dest_realm_avp(dest_realm_dict);
  add(dest_realm_avp.val_str(dest_realm));

  Diameter::Dictionary::AVP record_number_dict("Accounting-Record-Number");
  Diameter::AVP record_number_avp(record_number_dict);
  add(record_number_avp.val_i32(record_number));

  if (contents.GetType() != rapidjson::kObjectType)
  {
    LOG_ERROR("Cannot build ACR from JSON type %d", contents.GetType());
    return;
  }

  // Fill in the dynamic fields
  for (rapidjson::Value::ConstMemberIterator it = contents.MemberBegin();
       it != contents.MemberEnd();
       ++it)
  {
    try
    {
      switch (it->value.GetType())
      {
      case rapidjson::kFalseType:
      case rapidjson::kTrueType:
      case rapidjson::kNullType:
        LOG_ERROR("Invalid format (true/false) in JSON block, ignoring");
        continue;
      case rapidjson::kStringType:
      case rapidjson::kNumberType:
      case rapidjson::kObjectType:
        {
          Diameter::Dictionary::AVP new_dict(VENDORS, it->name.GetString());
          Diameter::AVP avp(new_dict);
          add(avp.val_json(VENDORS, new_dict, it->value));
        }
        break;
      case rapidjson::kArrayType:
        for (rapidjson::Value::ConstValueIterator array_iter = it->value.Begin();
             array_iter !=  it->value.End();
             ++array_iter)
        {
          Diameter::Dictionary::AVP new_dict(VENDORS, it->name.GetString());
          Diameter::AVP avp(new_dict);
          add(avp.val_json(VENDORS, new_dict, *array_iter));
        }
        break;
      }
    }
    catch (Diameter::Stack::Exception e)
    {
      LOG_WARNING("AVP %s not recognised, ignoring", it->name.GetString());
    }
  }
}
예제 #7
0
파일: fsinfo.c 프로젝트: 0mp/freebsd
/*
 * MAIN
 */
int
main(int argc, char *argv[])
{
  /*
   * Process arguments
   */
  fsi_get_args(argc, argv);

  /*
   * If no hostname given then use the local name
   */
  if (!*hostname && gethostname(hostname, sizeof(hostname)) < 0) {
    perror("gethostname");
    exit(1);
  }
  hostname[sizeof(hostname) - 1] = '\0';

  /*
   * Get the username
   */
  username = find_username();

  /*
   * New hosts and automounts
   */
  list_of_hosts = new_que();
  list_of_automounts = new_que();

  /*
   * New dictionaries
   */
  dict_of_volnames = new_dict();
  dict_of_hosts = new_dict();

  /*
   * Parse input
   */
  show_area_being_processed("read config", 11);
  if (fsi_parse())
    errors = 1;
  errors += file_io_errors + parse_errors;

  if (errors == 0) {
    /*
     * Do semantic analysis of input
     */
    analyze_hosts(list_of_hosts);
    analyze_automounts(list_of_automounts);
  }

  /*
   * Give up if errors
   */
  if (errors == 0) {
    /*
     * Output data files
     */

    write_atab(list_of_automounts);
    write_bootparams(list_of_hosts);
    write_dumpset(list_of_hosts);
    write_exportfs(list_of_hosts);
    write_fstab(list_of_hosts);
  }
  col_cleanup(1);

  exit(errors);
  return errors; /* should never reach here */
}
예제 #8
0
파일: literals.c 프로젝트: gvx/deja
bool read_literals(char *oldpos, size_t size, Header* h)
{
	int i, j;
	int n = 0;
	char type;
	uint32_t str_length;
	uint32_t ref;
	char *startpos = oldpos + h->size * 4;
	char *curpos = startpos;
	while (!eofreached)
	{
		type = *curpos++;
		if (eofreached)
		{
			break;
		}
		n++;
		switch (type)
		{
			case TYPE_NUM:
				curpos += 8;
				break;
			case TYPE_NUM | TYPE_SHORT:
				curpos += 3;
				break;
			case TYPE_STR:
			case TYPE_IDENT:
				memcpy(&str_length, curpos, 4);
				curpos += 4 + ntohl(str_length);
				break;
			case TYPE_STR | TYPE_SHORT:
			case TYPE_IDENT | TYPE_SHORT:
				str_length = (unsigned char)*curpos++;
				curpos += str_length;
				break;
			case TYPE_PAIR:
				curpos += 6;
				break;
			case TYPE_FRAC:
				curpos += 16;
				break;
			case TYPE_FRAC | TYPE_SHORT:
				curpos += 2;
				break;
			case TYPE_LIST:
				memcpy(&str_length, curpos, 4);
				curpos += 4 + 3 * ntohl(str_length);
				break;
			case TYPE_DICT:
				memcpy(&str_length, curpos, 4);
				curpos += 4 + 6 * ntohl(str_length);
				break;
		}
	}
	V* arr = calloc(n, sizeof(V));
	V t;
	curpos = startpos;
	for (i = 0; i < n; i++)
	{
		type = *curpos++;
		if (type == TYPE_NUM)
		{
			union double_or_uint64_t d;
			memcpy(&d, curpos, 8);
			curpos += 8;
			d.i = ntohll(d.i);
			t = double_to_value(d.d);
		}
		else if (type == (TYPE_NUM | TYPE_SHORT))
		{
			ref = 0;
			memcpy(((char*)&ref) + 1, curpos, 3);
			ref = ntohl(ref);
			curpos += 3;
			t = int_to_value(ref);
		}
		else if (type == TYPE_STR)
		{
			memcpy(&str_length, curpos, 4);
			curpos += 4;
			str_length = ntohl(str_length);
			if (!valid_utf8(str_length, curpos))
			{
				set_error_msg("wrong encoding for string literal, should be UTF-8");
				return false;
			}
			t = str_to_string(str_length, curpos);
			curpos += str_length;
		}
		else if (type == TYPE_IDENT)
		{
			memcpy(&str_length, curpos, 4);
			curpos += 4;
			str_length = ntohl(str_length);
			char data[str_length + 1];
			memcpy(&data, curpos, str_length);
			data[str_length] = '\0';
			t = lookup_ident(str_length, data);
			curpos += str_length;
		}
		else if (type == (TYPE_STR | TYPE_SHORT))
		{
			str_length = (unsigned char)*curpos++;
			if (!valid_utf8(str_length, curpos))
			{
				set_error_msg("wrong encoding for string literal, should be UTF-8");
				return false;
			}
			t = str_to_string(str_length, curpos);
			curpos += str_length;
		}
		else if (type == (TYPE_IDENT | TYPE_SHORT))
		{
			str_length = *curpos++;
			char data[str_length + 1];
			memcpy(&data, curpos, str_length);
			data[str_length] = '\0';
			t = lookup_ident(str_length, data);
			curpos += str_length;
		}
		else if (type == TYPE_PAIR)
		{
			ref = 0;
			memcpy(((char*)&ref) + 1, curpos, 3);
			ref = ntohl(ref);
			if (ref >= i)
			{
				set_error_msg("illegal pair detected");
				return false;
			}
			V v1 = arr[ref];

			ref = 0;
			memcpy(((char*)&ref) + 1, curpos + 3, 3);
			ref = ntohl(ref);
			if (ref >= i)
			{
				set_error_msg("illegal pair detected");
				return false;
			}
			V v2 = arr[ref];

			t = new_pair(v1, v2);
			curpos += 6;
		}
		else if (type == TYPE_FRAC)
		{
			int64_t numer;
			int64_t denom;
			memcpy(&numer, curpos, 8);
			numer = ntohll(numer);
			memcpy(&denom, curpos + 8, 8);
			denom = ntohll(denom);
			t = new_frac(numer, denom);
			curpos += 16;
		}
		else if (type == (TYPE_FRAC | TYPE_SHORT))
		{
			int8_t numer;
			uint8_t denom;
			numer = *curpos++;
			denom = *curpos++;
			t = new_frac(numer, denom);
		}
		else if (type == TYPE_LIST)
		{
			memcpy(&str_length, curpos, 4);
			str_length = ntohl(str_length);
			t = new_list();
			curpos += 4;
			if (str_length > 0)
			{
				uint32_t size = 64;
				while (size < str_length) size <<= 1;
				toStack(t)->size = size;
				toStack(t)->used = str_length;
				toStack(t)->nodes = calloc(size, sizeof(V));
				for (j = 0; j < str_length; j++)
				{
					ref = 0;
					memcpy(((char*)&ref) + 1, curpos, 3);
					ref = ntohl(ref);
					toStack(t)->nodes[j] = intToV((uint64_t)ref);
					curpos += 3;
				}
			}
		}
		else if (type == TYPE_DICT)
		{
			memcpy(&str_length, curpos, 4);
			curpos += 4;
			str_length = ntohl(str_length);
			t = new_dict();
			if (str_length > 0)
			{
				uint32_t size = 16;
				while (size < str_length) size <<= 1;
				toHashMap(t)->size = size;
				toHashMap(t)->used = str_length;
				toHashMap(t)->map = (Bucket**)curpos;
			}
			curpos += 6 * str_length;
		}
		else
		{
			set_error_msg("Unknown literal type.");
			return false;
		}
		arr[i] = t;
	}

	for (i = 0; i < n; i++)
	{
		t = arr[i];
		switch(getType(t))
		{
			case TYPE_LIST:
				for (j = 0; j < toStack(t)->used; j++)
				{
					toStack(t)->nodes[j] = arr[toInt(toStack(t)->nodes[j])];
				}
				break;
			case TYPE_DICT:
				if (toHashMap(t)->map)
				{
					curpos = ((char*)toHashMap(t)->map);

					toHashMap(t)->map = NULL;
					str_length = toHashMap(t)->used; //worst abuse of variable name ever Y/Y?
					toHashMap(t)->used = 0;
					for (j = 0; j < str_length; j++)
					{
						ref = 0;
						memcpy(((char*)&ref) + 1, curpos, 3);
						ref = ntohl(ref);
						V key = arr[ref];

						ref = 0;
						memcpy(((char*)&ref) + 1, curpos + 3, 3);
						ref = ntohl(ref);
						V value = arr[ref];

						set_hashmap(toHashMap(t), key, value);

						curpos += 6;
					}
				}
				break;
		}
	}

	h->n_literals = n;
	h->literals = arr;
	return true;
}