Esempio n. 1
0
connection_engine::connection_engine(class handler &h, const connection_options& opts) {
    connection_ = proton::connection(take_ownership(pn_connection()).get());
    pn_ptr<pn_transport_t> transport = take_ownership(pn_transport());
    pn_ptr<pn_collector_t> collector = take_ownership(pn_collector());
    if (!connection_ || !transport || !collector)
        throw proton::error("engine create");
    int err = pn_transport_bind(transport.get(), connection_.pn_object());
    if (err)
        throw error(msg() << "transport bind:" << pn_code(err));
    pn_connection_collect(connection_.pn_object(), collector.get());

    ctx_ = &connection_engine_context::get(connection_); // Creates context
    ctx_->engine_handler = &h;
    ctx_->transport = transport.release();
    ctx_->collector = collector.release();
    opts.apply(connection_);
    // Provide defaults for connection_id and link_prefix if not set.
    std::string cid = connection_.container_id();
    if (cid.empty()) {
        cid = make_id();
        pn_connection_set_container(connection_.pn_object(), cid.c_str());
    }
    id_generator &link_gen = connection_context::get(connection_).link_gen;
    if (link_gen.prefix().empty()) {
        link_gen.prefix(make_id()+"/");
    }
}
Esempio n. 2
0
int
main(void)
{
    gwy_type_init();

    printf(file_prologue, generated, id, id, title, title);

    const gchar* const *names = gwy_fit_func_list_builtins();
    guint nfuncs = g_strv_length((gchar**)names);
    GwyFitFunc **fitfuncs = g_new(GwyFitFunc*, nfuncs);
    for (guint i = 0; i < nfuncs; i++) {
        fitfuncs[i] = gwy_fit_func_new(names[i]);
        g_assert(GWY_IS_FIT_FUNC(fitfuncs[i]));
    }
    qsort(fitfuncs, nfuncs, sizeof(GwyFitFunc*), compare);

    GString *str = g_string_new(NULL);
    const gchar *processing_group = "NONE";
    for (guint i = 0; i < nfuncs; i++) {
        GwyFitFunc *fitfunc = fitfuncs[i];
        const gchar *name = gwy_fit_func_get_name(fitfunc);
        const gchar *group = gwy_fit_func_get_group(fitfunc);
        if (!gwy_strequal(group, processing_group)) {
            if (!gwy_strequal(processing_group, "NONE"))
                printf(group_epilogue);
            g_string_assign(str, group);
            make_id(str);
            printf(group_prologue, id, str->str, group, group);
            processing_group = group;
        }
        g_string_assign(str, name);
        make_id(str);
        printf(function_prologue, id, str->str, name);
        g_string_assign(str, gwy_fit_func_formula(fitfunc));
        convert_pango_to_docbook(str);
        make_math(str);
        printf("<entry>%s</entry>\n", str->str);
        guint n = gwy_fit_func_n_params(fitfunc);
        printf("<entry>");
        for (guint j = 0; j < n; j++) {
            g_string_assign(str, gwy_fit_func_param_name(fitfunc, j));
            convert_pango_to_docbook(str);
            make_math(str);
            printf("%s %s", j ? "," : "", str->str);
        }
        printf("</entry>\n");
        printf(function_epilogue);
        g_object_unref(fitfunc);
    }
    if (!gwy_strequal(processing_group, "NONE"))
        printf(group_epilogue);

    printf(file_epilogue);

    return 0;
}
Esempio n. 3
0
int
main(void)
{
    gwy_type_init();

    printf(file_prologue, generated, id, id, title, title);

    const gchar* const *names = gwy_grain_value_list_builtins();
    guint nvalues = g_strv_length((gchar**)names);
    GwyGrainValue **grainvalues = g_new(GwyGrainValue*, nvalues);
    for (guint i = 0; i < nvalues; i++) {
        grainvalues[i] = gwy_grain_value_new(names[i]);
        g_assert(GWY_IS_GRAIN_VALUE(grainvalues[i]));
    }
    qsort(grainvalues, nvalues, sizeof(GwyGrainValue*), compare);

    GString *str = g_string_new(NULL);
    const gchar *processing_group = "NONE";
    for (guint i = 0; i < nvalues; i++) {
        GwyGrainValue *grainvalue = grainvalues[i];
        const gchar *name = gwy_grain_value_get_name(grainvalue);
        const gchar *group = gwy_grain_value_get_group(grainvalue);
        if (!gwy_strequal(group, processing_group)) {
            if (!gwy_strequal(processing_group, "NONE"))
                printf(group_epilogue);
            g_string_assign(str, group);
            make_id(str);
            printf(group_prologue, id, str->str, group, group);
            processing_group = group;
        }
        g_string_assign(str, name);
        make_id(str);
        printf(value_prologue, id, str->str, name);
        g_string_assign(str, gwy_grain_value_get_symbol(grainvalue));
        convert_pango_to_docbook(str);
        make_math(str);
        printf("<entry>%s</entry>\n", str->str);
        printf("<entry><code>%s</code></entry>",
               gwy_grain_value_get_ident(grainvalue));
        g_string_assign(str, "");
        if (gwy_grain_value_needs_same_units(grainvalue))
            append_separated(str, "needs same lateral and value units");
        if (gwy_grain_value_is_angle(grainvalue))
            append_separated(str, "represents angle in radians");
        printf("<entry>%s</entry>\n", str->str);
        printf(value_epilogue);
        g_object_unref(grainvalue);
    }
    if (!gwy_strequal(processing_group, "NONE"))
        printf(group_epilogue);

    printf(file_epilogue);

    return 0;
}
Esempio n. 4
0
 DrawRectDrawOp(const Rect& rect_, const Color& color_)
   : DrawOp(DRAWRECT_DRAWOP),
     rect(rect_),
     color(color_)
 {
   id = make_id(type, rect.left, rect.top);
 }
Esempio n. 5
0
/**
   Setup Kademlia.
   Must be called after MPI_Init() and whoami().
*/
void
KDA_Init(int alpha_in, int k_in)
{
  NOTE_F;

  KDA_Data(alpha_in, k_in);

  MPIRPC_Node node;
  node.comm = MPI_COMM_NULL;
  node.rank = 0;
  id      = make_id(debug_rank);
  self    = KDA_Neighbor_create_id(id, node);
  NOTE_XI("SELF: ", id, id);

  port[0] = '\0';

  clients = list_create();

  MPIRPC_Register("info",       handle_info);
  // MPIRPC_Register("neighbor",   handle_neighbor);
  MPIRPC_Register("ping",       handle_ping);
  MPIRPC_Register("join",       handle_join);
  MPIRPC_Register("find_node",  handle_find_node);
  MPIRPC_Register("query_id",   handle_query_id);
  MPIRPC_Register("query_id_k", handle_query_id_k);
  MPIRPC_Register("store",      handle_store);
  MPIRPC_Register("retrieve",   handle_retrieve);
  MPIRPC_Register("shutdown",   handle_shutdown);

  KDA_Init_conn();
}
void mergeItemName (UnitData* item)
{
  char const* id = make_id (item->getID ());
  char* name = strip_item (item->getStringData ("Name"));
  if (!strcmp (name, "Ultimate Orb"))
    int asdf = 0;
  int len = (int) strlen (name);
  if (len >= 7 && !strnicmp (name + len - 7, "Level ", 6))
  {
    name[len - 7] = name[len - 1];
    name[len - 6] = 0;
  }
  if (len >= 4 && name[len - 1] == ')' && (name[len - 3] == '(' || name[len - 4] == '('))
  {
    if (name[len - 4] == '(')
      len -= 5;
    else
      len -= 4;
    name[len] = 0;
  }
  int pos = sgetValue (idir, name) - 1;
  if (pos >= 0 && getValue (dir, id) == 0)
  {
    dir = addString (dir, id, 1);
    char const* abils = item->getData ("abilList");
    if ((abils[0] == 0 || abils[0] == '_') && stricmp (item->getData ("class"), "Campaign"))
      pos = items[pos].realid;
    items[pos].ids[items[pos].numIds] = item->getID ();
    items[pos].numIds++;
  }
}
Esempio n. 7
0
/*
Erstmal Vektor von DT-Links aufbauen, dann über alle DT-Blöcke gehen und die
Daten in 1000er-Blöcken nach oGroup.data[i] kopieren.
*/
void data_group::read_DL(rawfile* file, link pos) const {
//  int nExtra = 0;
//  int dt_first = 0;
  std::vector<link> dt_extra;

  link next = pos;
  while (next) {
    file->seek(next);
    block_header dl = prase_block_header(file, make_id('D', 'L'));

    std::vector<link> dl_links;
    file->read_to_container(dl_links, dl.link_count);

    dt_extra.insert(dt_extra.end(), dl_links.begin() + 1, dl_links.end());

    /*
                // Wird nicht benötigt
                dl_flags = fread_uint8(fp, 1);
                reserved = fread_uint8(fp, 3);
                dl_count = fread_uint32(fp, 1);
                if (dl_flags & 1) {
                    dl_equal_length = fread_uint64(fp, 1);
                } else {
                    dl_offset = fread_uint64(fp, dl_count);
                }*/


    next = dl_links[0];
  }

  data_.get() = get_recs(file, dt_extra);
}
Esempio n. 8
0
 SurfaceDrawOp(const Vector2i& pos_,
               const FramebufferSurface& surface_,
               const Rect& rect_) :
   DrawOp(SURFACE_DRAWOP),
   pos(pos_),
   surface(surface_),
   rect(rect_)
 {
   id = make_id(type, pos.x, pos.y);
 }
Esempio n. 9
0
void file::prase_basic_hdblock() {
  // prase HDBLOCK
  handle_->seek(64, rawfile::seek_orgin::begin);

  // read header
  block_header header = prase_block_header(handle_.get(), make_id('H', 'D'));

  // read links
  handle_->read_to_container(links_, header.link_count);
}
static C_RESULT add_device(device_t* device, const int32_t id_wanted)
{
	int32_t id = make_id(device);
	if( id_wanted == GAMEPAD_ID && id == id_wanted)
	{
		PRINT("Input device %s found\n", device->name);
		strncpy(gamepad.name, device->handlers, MAX_NAME_LENGTH);
		return C_OK;
	}

	return C_FAIL;
}
Esempio n. 11
0
int propagate_link( int state , Config_set *A , Config_set *B )
{
    
    STATE *shift_state;
    Config_set *C_ptr , *ptr;
    TOKEN *T_ptr , *first;
    TOKEN *dot;
    TOKEN *L2;
    TOKEN *L1;
    int i;
    
    if( B == NULL )
        return 0;
    
    
    L1 = A->lookahead;
    dot = A->dot;
    L2 = B->lookahead;
    
    if ( add_set( L2 , L1 ) == FALSE )
        return 0;
    
    if( B->dot == NULL )
        return 0;
    i = parser_table[state][make_id(B->dot->string)-1].go_to;
    
    
    
    //printf("%d  %s -> %d\n",state , B->dot->string , i );
    //view_state(state);

//    if ( i == 105 )
//       printf("hit\n");

    // shift state
    for( shift_state = state_start ; i != shift_state->statenum ; shift_state = shift_state->next );
    
    for( C_ptr = shift_state->config_set ; C_ptr != NULL && B->rule != C_ptr->rule ; C_ptr = C_ptr->set_next );
        propagate_link( i , B , C_ptr );
    
    //comput lookahead by closue 0
    for( C_ptr = shift_state->config_set ; C_ptr != NULL && C_ptr->set_next != NULL ; C_ptr = C_ptr->set_next )
    {
        for( ptr = shift_state->config_set ; ptr != NULL ; ptr = ptr->set_next )
        {
            if ( C_ptr->dot == NULL ) 
                continue;
            if ( strcmp( C_ptr->dot->string , ptr->rule->lhs ) == 0 )
                propagate( shift_state->statenum , C_ptr , ptr );
        }
	}
	return 0;    
}
Esempio n. 12
0
std::vector<std::string> data_group::get_recs(rawfile* file, std::vector<link> dt_links) const {
    std::vector<std::string> data;

    for (std::size_t i = 0; i < dt_links.size(); i++) {
        file->seek(dt_links[i]);
        block_header dt = prase_block_header(file, make_id('D', 'T'));
        uint64_t ndt_Bytes = dt.length - 24;
//        uint64_t ndt_Rec = ndt_Bytes / (get_data_bytes() + get_inval_bytes());
        data.push_back(std::string());
        file->read_to_container(data.back(), ndt_Bytes);
    }
    return data;
}
void maze_generator_kruskal_private::generate_edges()
{
	edges_sets.clear();
	for (unsigned int x = 0; x < size_x ; x++)
		for (unsigned int y = 0; y < size_y ; y++)
		{
			unsigned int edge_id;
			//get all left walls
			if (x < size_x - 1)
			{
				edge_id = make_id(x, y) + (make_id(x + 1, y) << locations_id_mask);
				edges_sets.push_back(edge_id);
			}
			if (y < size_y - 1)
			{
				edge_id = make_id(x, y) + (make_id(x, y + 1) << locations_id_mask);
				edges_sets.push_back(edge_id);
			}
		}
	srand((unsigned int)time(NULL));
	std::random_shuffle(edges_sets.begin(), edges_sets.end());
}
Esempio n. 14
0
data_group::data_group(std::shared_ptr<rawfile>& file, uint64_t l) :
    block(file, l), links_(), channel_groups_(), rec_id_size_()
{
  file->seek(l);
  block_header header = prase_block_header(file.get(), make_id('D', 'G'));
  file->read_to_container(links_, header.link_count);

  file->read(rec_id_size_);
  if (rec_id_size_ != 0) {
    throw std::invalid_argument("unsorted MDF4 files not supported");
  }

  prase_channel_groups();
}
Esempio n. 15
0
void
prepare_utmp (struct utmp *utmp, char *tty,
	      const char *username, const char *hostname)
{
    char *ttyx = clean_ttyname (tty);

    memset(utmp, 0, sizeof(*utmp));
    utmp->ut_time = time(NULL);
    strncpy(utmp->ut_line, ttyx, sizeof(utmp->ut_line));
    strncpy(utmp->ut_name, username, sizeof(utmp->ut_name));

# ifdef HAVE_STRUCT_UTMP_UT_USER
    strncpy(utmp->ut_user, username, sizeof(utmp->ut_user));
# endif

# ifdef HAVE_STRUCT_UTMP_UT_ADDR
    if (hostname[0]) {
        struct hostent *he;
	if ((he = gethostbyname(hostname)))
	    memcpy(&utmp->ut_addr, he->h_addr_list[0],
		   sizeof(utmp->ut_addr));
    }
# endif

# ifdef HAVE_STRUCT_UTMP_UT_HOST
    shrink_hostname (hostname, utmp->ut_host, sizeof(utmp->ut_host));
# endif

# ifdef HAVE_STRUCT_UTMP_UT_TYPE
    utmp->ut_type = USER_PROCESS;
# endif

# ifdef HAVE_STRUCT_UTMP_UT_PID
    utmp->ut_pid = getpid();
# endif

# ifdef HAVE_STRUCT_UTMP_UT_ID
    strncpy(utmp->ut_id, make_id(ttyx), sizeof(utmp->ut_id));
# endif
}
Esempio n. 16
0
static void
utmpx_update(struct utmpx *ut, char *line, const char *user, const char *host)
{
    struct timeval tmp;
    char *clean_tty = clean_ttyname(line);

    strncpy(ut->ut_line, clean_tty, sizeof(ut->ut_line));
#ifdef HAVE_STRUCT_UTMPX_UT_ID
    strncpy(ut->ut_id, make_id(clean_tty), sizeof(ut->ut_id));
#endif
    strncpy(ut->ut_user, user, sizeof(ut->ut_user));
    shrink_hostname (host, ut->ut_host, sizeof(ut->ut_host));
#ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
    ut->ut_syslen = strlen(host) + 1;
    if (ut->ut_syslen > sizeof(ut->ut_host))
        ut->ut_syslen = sizeof(ut->ut_host);
#endif
    ut->ut_type = USER_PROCESS;
    gettimeofday (&tmp, 0);
    ut->ut_tv.tv_sec = tmp.tv_sec;
    ut->ut_tv.tv_usec = tmp.tv_usec;
    pututxline(ut);
#ifdef WTMPX_FILE
    updwtmpx(WTMPX_FILE, ut);
#elif defined(WTMP_FILE)
    { /* XXX should be removed, just drop wtmp support */
	struct utmp utmp;
	int fd;

	prepare_utmp (&utmp, line, user, host);
	if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
	    write(fd, &utmp, sizeof(struct utmp));
	    close(fd);
	}
    }
#endif
}
Esempio n. 17
0
int propagate( int state , Config_set *A , Config_set *B )
{
    
    STATE *shift_state;
    Config_set *C_ptr , *ptr;
    TOKEN *T_ptr , *first;
    TOKEN *dot;
    TOKEN *L2;
    TOKEN *L1;
    int i;
    
    L1 = A->lookahead;
    dot = A->dot;
    L2 = B->lookahead;
    
    
    //First(£^L)
    for( T_ptr = dot->next ; T_ptr != NULL ; T_ptr = T_ptr->next )
    {
        first = search_token( first_set_start , T_ptr->string );
        if (first == NULL )
            continue;
        if ( search_set(first,"£f") == TRUE )
        {
            add_set(L2,first);
            delete_set( &(L2->set) , "£f" );
            continue;
        }
        else
        {
            if ( add_set(L2,first) == FALSE ) 
                return 0;
            break;
        }
    }
    //First(£^L) ,  £^ is lambda
    if(T_ptr == NULL)
    {
        add_set( L2 , L1 );         
    }
    
    //printf("%d\n", parser_table[state][make_id(dot->string)].go_to );
    if( B->dot == NULL )
        return 0;
    
    i = parser_table[state][make_id(B->dot->string)-1].go_to;
    //printf("%d  %s -> %d\n",state , B->dot->string , i );
    //view_state(state);


    if( i == state )
        return 0;
    // shift state
    for( shift_state = state_start ; i != shift_state->statenum ; shift_state = shift_state->next );
    
    for( C_ptr = shift_state->config_set ; C_ptr != NULL && B->rule != C_ptr->rule ; C_ptr = C_ptr->set_next );
    {
//        if ( i == 105 )
//            printf("hit\n");
        propagate_link( i , B , C_ptr );
    }
    
    //comput lookahead by closue 0
    C_ptr = shift_state->config_set;
    
    
    for( C_ptr = shift_state->config_set ; C_ptr != NULL && C_ptr->set_next != NULL ; C_ptr = C_ptr->set_next )
    {
        for( ptr = shift_state->config_set ; ptr != NULL ; ptr = ptr->set_next )
        {
            if ( C_ptr->dot == NULL ) 
                continue;
            if ( strcmp( C_ptr->dot->string , ptr->rule->lhs ) == 0 )
            {
                propagate( shift_state->statenum , C_ptr , ptr );
            }
        }
    }
	return 0;    
}
bool saveDotaData (char const* dest)
{
  MPQFILE file = MPQOpenFile (((CDotAReplayApp*) ::AfxGetApp ())->res, dest, MPQFILE_REWRITE);
  if (file)
  {
    static int hsub[256];
    static int isub[512];
    memset (hsub, 0, sizeof hsub);
    memset (isub, 0, sizeof isub);
    int mxh = bk_numHeroes;
    for (int i = 1; i < numHeroes; i++)
    {
      bool found = false;
      for (int j = 1; j < bk_numHeroes && !found; j++)
      {
        if (samename (heroes[i].name, bk_heroes[j].name))
        {
          hsub[j] = i;
          found = true;
        }
      }
      if (!found)
        hsub[mxh++] = i;
    }
    int mxi = bk_numItems;
    for (int i = 1; i < numItems; i++)
    {
      bool found = false;
      for (int j = 1; j < bk_numItems && !found; j++)
      {
        if (items[i].type/2 == bk_items[j].type/2 && samename (items[i].name, bk_items[j].name))
        {
          isub[j] = i;
          found = true;
        }
      }
      if (!found)
        isub[mxi++] = i;
    }
    MPQFilePuts (file, "[HERO]\r\n");
    for (int m = 0; m < mxh; m++)
    {
      int i = hsub[m];
      DotaHero* hero = &heroes[i];
      MPQFilePuts (file, mprintf ("\"%s\",\"%s\",%d,\"%s\",%d,%d", hero->name, hero->oname, hero->tavern,
        hero->imgTag, hero->slot, hero->point));
      for (int j = 0; j < 5; j++)
        MPQFilePuts (file, mprintf (",%s", make_id (hero->abils[j])));
      for (int j = 0; j < hero->numIds; j++)
        MPQFilePuts (file, mprintf (",%s", make_id (hero->ids[j])));
      MPQFilePuts (file, "\r\n");
    }
    MPQFilePuts (file, "[ITEM]\r\n");
    for (int m = 0; m < mxi; m++)
    {
      int i = isub[m];
      DotaItem* item = getItem (i);
      MPQFilePuts (file, mprintf ("\"%s\",%d,\"%s\"", item->name, item->cost, item->imgTag));
      for (int j = 0; j < item->numIds; j++)
        MPQFilePuts (file, mprintf (",%s", make_id (item->ids[j])));
      MPQFilePuts (file, "\r\n");
    }
    MPQFilePuts (file, "[ABILITY]\r\n");
    for (int i = 1; i < numAbilities; i++)
    {
      DotaAbility* abil = getAbility (i);
      MPQFilePuts (file, mprintf ("\"%s\",%d,\"%s\"", abil->name, abil->slot, abil->imgTag));
      for (int j = 0; j < abil->numIds; j++)
        MPQFilePuts (file, mprintf (",%s", make_id (abil->ids[j])));
      MPQFilePuts (file, "\r\n");
    }
    MPQFilePuts (file, "[RECIPE]\r\n");
    for (int i = 0; i < numRecipes; i++)
    {
      DotaRecipe* recipe = getRecipe (i);
      MPQFilePuts (file, make_id (recipe->result));
      for (int j = 0; j < recipe->numsrc; j++)
        MPQFilePuts (file, mprintf (",%s,%d", make_id (recipe->srcid[j]), recipe->srccount[j]));
      MPQFilePuts (file, "\r\n");
    }
    MPQCloseFile (file);
  }
  else
    return false;
  MPQFlushListfile (((CDotAReplayApp*) ::AfxGetApp ())->res);
  return true;
}
Esempio n. 19
0
connection_engine::container::container(const std::string& s) : id_(make_id(s)) {}
Esempio n. 20
0
void
start_login(const char *host, int autologin, char *name)
{
    struct arg_val argv;
    char *user;
    int save_errno;

#ifdef ENCRYPTION
    encrypt_output = NULL;
    decrypt_input = NULL;
#endif

#ifdef HAVE_UTMPX_H
    {
	int pid = getpid();
	struct utmpx utmpx;
	struct timeval tv;
	char *clean_tty;

	/*
	 * Create utmp entry for child
	 */

	clean_tty = clean_ttyname(line);
	memset(&utmpx, 0, sizeof(utmpx));
	strncpy(utmpx.ut_user,  ".telnet", sizeof(utmpx.ut_user));
	strncpy(utmpx.ut_line,  clean_tty, sizeof(utmpx.ut_line));
#ifdef HAVE_STRUCT_UTMP_UT_ID
	strncpy(utmpx.ut_id, make_id(clean_tty), sizeof(utmpx.ut_id));
#endif
	utmpx.ut_pid = pid;

	utmpx.ut_type = LOGIN_PROCESS;

	gettimeofday (&tv, NULL);
	utmpx.ut_tv.tv_sec = tv.tv_sec;
	utmpx.ut_tv.tv_usec = tv.tv_usec;

	if (pututxline(&utmpx) == NULL)
	    fatal(net, "pututxline failed");
    }
#endif

    scrub_env();

    /*
     * -h : pass on name of host.
     *		WARNING:  -h is accepted by login if and only if
     *			getuid() == 0.
     * -p : don't clobber the environment (so terminal type stays set).
     *
     * -f : force this login, he has already been authenticated
     */

    /* init argv structure */
    argv.size=0;
    argv.argc=0;
    argv.argv=malloc(0); /*so we can call realloc later */
    addarg(&argv, "login");
    addarg(&argv, "-h");
    addarg(&argv, host);
    addarg(&argv, "-p");
    if(name && name[0])
	user = name;
    else
	user = getenv("USER");
#ifdef AUTHENTICATION
    if (auth_level < 0 || autologin != AUTH_VALID) {
	if(!no_warn) {
	    printf("User not authenticated. ");
	    if (require_otp)
		printf("Using one-time password\r\n");
	    else
		printf("Using plaintext username and password\r\n");
	}
	if (require_otp) {
	    addarg(&argv, "-a");
	    addarg(&argv, "otp");
	}
	if(log_unauth)
	    syslog(LOG_INFO, "unauthenticated access from %s (%s)",
		   host, user ? user : "******");
    }
    if (auth_level >= 0 && autologin == AUTH_VALID)
	addarg(&argv, "-f");
#endif
    if(user){
	addarg(&argv, "--");
	addarg(&argv, strdup(user));
    }
    if (getenv("USER")) {
	/*
	 * Assume that login will set the USER variable
	 * correctly.  For SysV systems, this means that
	 * USER will no longer be set, just LOGNAME by
	 * login.  (The problem is that if the auto-login
	 * fails, and the user then specifies a different
	 * account name, he can get logged in with both
	 * LOGNAME and USER in his environment, but the
	 * USER value will be wrong.
	 */
	unsetenv("USER");
    }
    closelog();
    /*
     * This sleep(1) is in here so that telnetd can
     * finish up with the tty.  There's a race condition
     * the login banner message gets lost...
     */
    sleep(1);

    execv(new_login, argv.argv);
    save_errno = errno;
    syslog(LOG_ERR, "%s: %m", new_login);
    fatalperror_errno(net, new_login, save_errno);
    /*NOTREACHED*/
}
Esempio n. 21
0
int main(int argc, char ** argv)
{
    int nwritten;

    struct timeval last_time,this_time;

    strcpy(hcand_ip, "127.0.0.1");
    strcpy(device, "can0");

    // Optionen parsen:
    if (parse_options(argc,argv) != 0)
        exit (1);

    openlog("hcanhid",LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID,
            LOG_LOCAL7);

    if( (sock_inet = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
        perror("Error while opening socket");
        return(-1);
    }
    struct sockaddr_in sin;
    memset(&sin, 0, sizeof(sin));
    sin.sin_family = AF_INET;
    sin.sin_addr.s_addr = inet_addr(hcand_ip);
    sin.sin_port = htons(3600);

    if( (sock_can = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
        perror("Error while opening socket");
       return(-2);
    }
    struct sockaddr_can can_addr;
    struct can_frame CanFrame;
    struct ifreq can_ifr;

    strcpy(can_ifr.ifr_name, device);
    ioctl(sock_can, SIOCGIFINDEX, &can_ifr);

    can_addr.can_family  = AF_CAN;
    can_addr.can_ifindex = can_ifr.ifr_ifindex;
    if(debug) printf("%s at index %d\n", device, can_ifr.ifr_ifindex);
    if(bind(sock_can, (struct sockaddr *)&can_addr, sizeof(can_addr)) < 0) {
        perror("Error in socket bind");
        return(-3);
    }
    canBuffer[0].can_id  = make_id(35, 35, 1, 0) | CAN_EFF_FLAG;
    canBuffer[0].can_dlc = 2;
    canBuffer[0].data[0] = 0x11;
    canBuffer[0].data[1] = 0x22;
 
    nwritten = write(sock_can, &canBuffer[0], sizeof(struct can_frame));
 
    if(debug) printf("Wrote %d bytes\n", nwritten);
    if (nwritten != sizeof(struct can_frame)) {
        syslog(LOG_ERR,"could not send complete CAN packet !");
        exit(-4);
    }

 
    hcanBuffer[0].id  = make_id(0, 0, 0, 0);
    hcanBuffer[0].size = 0;
    nwritten = sendto(sock_inet, &hcanBuffer[0], sizeof(struct hcan_frame), 0,
            (struct sockaddr *) &sin, sizeof(sin));

    if(debug) printf("Wrote %d bytes\n", nwritten);
    if (nwritten != sizeof(struct hcan_frame)) {
        syslog(LOG_ERR,"could not send complete UDP packet !");
        exit(-5);
    }


    // Durchsatz zaehlen
    packet_sent = 0;
    last_time = get_time();

    fd_set recv_fdset;
    fd_set send_fdset;
    int max_fd;
    int nread;
    struct timeval timeout;
    max_fd = sock_inet;
    if(sock_can > max_fd)
        max_fd = sock_can;

    while (1) {
        int ret;
        timeout.tv_sec = 0;
        timeout.tv_usec = 500000;
        FD_ZERO(&recv_fdset);
        FD_ZERO(&send_fdset);
        FD_SET(sock_inet, &recv_fdset);
        FD_SET(sock_can, &recv_fdset);
        if(hcanBufferWPtr != hcanBufferRPtr)
        	FD_SET(sock_inet, &send_fdset);
        if(canBufferWPtr != canBufferRPtr)
        	FD_SET(sock_can, &send_fdset);
        ret = select (max_fd + 1, &recv_fdset, &send_fdset, NULL, &timeout);
        if(ret > 0) {// no timeout
            if (FD_ISSET(sock_inet, &recv_fdset)) {
                // read a frame from inet;
                nread = recv(sock_inet, &HcanFrame, sizeof(HcanFrame), MSG_WAITALL);
                if (nread != sizeof(HcanFrame)) {
                    syslog(LOG_ERR, "could not read full packet from server, dropping...");
                    exit(1);
                }
                else {
                    if(debug) printf("received udpframe: %lu %d\n", HcanFrame.id, HcanFrame.size);
                    if(((canBufferWPtr+1)&(BUFFERSIZE-1)) == canBufferRPtr) {
                        printf("no buffer left\n");
                    } else {
                        canBuffer[canBufferWPtr].can_id = HcanFrame.id | CAN_EFF_FLAG;
                        canBuffer[canBufferWPtr].can_dlc = HcanFrame.size;
                        memcpy(canBuffer[canBufferWPtr].data, HcanFrame.data, HcanFrame.size);
                        canBufferWPtr++;
                        canBufferWPtr &= BUFFERSIZE-1;
                    }
                }
            }
            if (FD_ISSET(sock_can, &recv_fdset)) {
                // read a frame from can;
                nread = recv(sock_can, &CanFrame, sizeof(struct can_frame), MSG_WAITALL);
                if (nread != sizeof(struct can_frame)) {
                    syslog(LOG_ERR, "could not read full packet from can, dropping...");
                    exit(1);
                }
                else {
                    if(debug) printf("received can frame: %lu %d\n", CanFrame.can_id, CanFrame.can_dlc);
                    if(((hcanBufferWPtr+1)&(BUFFERSIZE-1)) == hcanBufferRPtr) {
                        printf("no buffer left\n");
                    } else {
                        hcanBuffer[hcanBufferWPtr].id = CanFrame.can_id & CAN_EFF_MASK;
                        hcanBuffer[hcanBufferWPtr].size = CanFrame.can_dlc;
                        memcpy(hcanBuffer[hcanBufferWPtr].data, CanFrame.data, CanFrame.can_dlc);
                        hcanBufferWPtr++;
                        hcanBufferWPtr &= BUFFERSIZE-1;
                    }
                }
            }
            if ((canBufferWPtr != canBufferRPtr) && FD_ISSET(sock_can, &send_fdset)) {
                nwritten = write(sock_can, &canBuffer[canBufferRPtr], sizeof(struct can_frame));
                if(debug) printf("send can frame\n");
                if (nwritten != sizeof(struct can_frame))
                    syslog(LOG_ERR,"could not send complete CAN packet !");
                canBufferRPtr++;
                canBufferRPtr &= BUFFERSIZE-1;
            }
            if ((hcanBufferWPtr != hcanBufferRPtr) && FD_ISSET(sock_inet, &send_fdset)) {
                nwritten = sendto(sock_inet, &hcanBuffer[hcanBufferRPtr], sizeof(struct hcan_frame), 0,
                            (struct sockaddr *) &sin, sizeof(sin));
                if(debug) printf("send hcan frame\n");
                if (nwritten != sizeof(struct hcan_frame))
                    syslog(LOG_ERR,"could not send complete UDP packet !");
                hcanBufferRPtr++;
                hcanBufferRPtr &= BUFFERSIZE-1;
            }
        }
    }

    return 0;
}
Esempio n. 22
0
    void configure( const memory_grammar& /*grammar*/, const std::string& schema )
    {
        configure();
        XERCES_CPP_NAMESPACE::MemBufInputSource source( reinterpret_cast< const XMLByte* >( schema.c_str() ), schema.size(), make_id().c_str() );
        XERCES_CPP_NAMESPACE::Wrapper4InputSource input( &source, false );
#if XERCES_VERSION_MAJOR == 3
        if( ! parser_.loadGrammar( &input, XERCES_CPP_NAMESPACE::Grammar::SchemaGrammarType, true ) )
#else
        if( ! parser_.loadGrammar( input, XERCES_CPP_NAMESPACE::Grammar::SchemaGrammarType, true ) )
#endif // XERCES_VERSION_MAJOR
            throw exception( "Failed to load memory grammar" );
    }
Esempio n. 23
0
int run_parser( TTreeView *TreeView1 , char *file_name )
{
    Config_set *config_ptr;
    GRAMMAR *G_ptr; 
    STATE *state_ptr;
    TOKEN *T_ptr , *T_tmp;
    FILE *input ,*out;
    char grammar_rule[1024];
    char *ptr , *ptr_string;
    char *ptr_lhs , *ptr_rhs;
    SET *S_ptr;
    int i , j;
    int rule_num; 

    strncpy( lambda , "£f" , strlen("£f")+1 );
	G_start = NULL;
    G_end = NULL;
	terminal_start = NULL;
    terminal_end = NULL;
    nonterminal_start = NULL;
    nonterminal_end = NULL;
    first_set_start = NULL;
    first_set_end = NULL;
    follow_set_start = NULL;
    follow_set_end = NULL;
    predict_set_start = NULL;
    predict_set_end = NULL;
    config_start = NULL;
    config_end = NULL;
    state_start = NULL;
    state_end = NULL;
    state_num = 0;
    
    
    //scanner();
	input = fopen( file_name ,"r");
	scan = fopen("out.txt","r");

    
    if ( input == NULL )
	{
    	Application->MessageBoxA("grammar file error","error",0);
        return 0;     
    }
     
//    out = fopen("table.csv","w");
     
    for ( i = 0 ; fgets( grammar_rule , 1024 , input ) ;  )
    {
        ptr = grammar_rule;
        // remove \n
        ptr = strstr(grammar_rule , "\n");
        if(ptr != NULL)
            *ptr = '\0';
            
        // remove rule num
        ptr = strstr( grammar_rule , "." );
        // get left handside
        ptr_lhs = ptr + 2;
        ptr = strstr( grammar_rule , " " );
        *ptr = '\0';
        insert_token( &nonterminal_start , &nonterminal_end , ptr_lhs );    // make nonterminal table
        insert_token( &first_set_start , &first_set_end , ptr_lhs );        // make first set table with nonterminal 
        insert_token( &follow_set_start , &follow_set_end , ptr_lhs );      // make follow set table
        insert_token( &predict_set_start , &predict_set_end , ptr_lhs );    // make predict set table
		// get right handside
		ptr = strstr( ++ptr , "¡÷" );
        do
        {
            ptr = strstr( ++ptr , " " );
            while(isspace(*ptr))
                ptr++;
            ptr_rhs = ptr;
            ptr = strstr( ptr_rhs , "|" );
            if ( ptr != NULL &&  *(ptr+1) != '|' )
            {
                for ( j = 1 ; isspace(*(ptr-j)) ; j++ )
                *(ptr-j) = '\0';
            }
            
            insert_grammar( ++i , ptr_lhs , ptr_rhs );
            
        } while ( ptr != NULL &&  *(ptr+1) != '|' ); 
    }
    
    
    // remove nonterminal in termainal table
    T_ptr = nonterminal_start;
    i = 0;
    while ( T_ptr != NULL )
    {
        T_tmp = search_token( terminal_start , T_ptr->string );
        delete_token( &terminal_start , T_tmp );
        T_ptr = T_ptr->next;
        i++;
    }
    num_of_nonterm = i;

    for ( T_ptr = terminal_start , i =0 ; T_ptr != NULL ; T_ptr = T_ptr->next , i++ )
    {
        insert_token( &first_set_start , &first_set_end , T_ptr->string );        // make first set table
    }
    num_of_term = ++i;
    
    fill_frist_set();
    fill_follow_set();
    i = 0;
    view = fopen("state.txt","w");
    //view = stdout;
    out = fopen("go_to_table.csv","w");
    
    build_CFSM();
    

    
    // build goto table
    parser_table = (PARSER**) malloc( sizeof(PARSER) * state_num );
    for( i = 0 ; i < state_num ; i++ )
    {
        parser_table[i] = (PARSER*) malloc( sizeof(PARSER) * ( num_of_term  + num_of_nonterm ));
        for( j = 0 ; j < num_of_term  + num_of_nonterm ; j++ )
        {
            parser_table[i][j].go_to = go_to_state(i,j+1);
            if( j+1 != make_id("$") )
                parser_table[i][j].action = SHIFT;
            else
                parser_table[i][j].action = ACCEPT;
                
            if( parser_table[i][j].go_to == 0 )
                parser_table[i][j].action = ERROR;
        }
    }
    
    // comput lalr lookahead
    build_LALR_lookahead();

    fprintf(out,"\t,");
    for( j = 0 ; j < num_of_term  + num_of_nonterm ; j++ )
    {
        if( j+1 != make_id(",") )
            fprintf(out," %s,",idtostr(j+1));
        else
           fprintf(out," ' ,");
    }
    fprintf( out ,"\n");
    
    // build action table
    for( i = 0 , state_ptr = state_start ; i < state_num ; i++ , state_ptr = state_ptr->next )
    {
        fprintf(out,"state%d,",i); 

        for( j = 0 ; j < num_of_term  + num_of_nonterm ; j++ )
        { 
            for( config_ptr = state_ptr->config_set ; config_ptr != NULL ; config_ptr = config_ptr->set_next )
            {
                if( config_ptr->dot == NULL && search_set( config_ptr->lookahead , idtostr(j+1) ) == TRUE )
                {
                    if(parser_table[i][j].go_to == 0)
                    {
                        //printf("hit\n");
                        parser_table[i][j].go_to = config_ptr->rule->rule;
                        parser_table[i][j].action = REDUCE;
                    }
                    //fprintf(out,"R%02d,",parser_table[i][j].go_to);
                }
            }
            if(parser_table[i][j].go_to > 0)
            {
                if( parser_table[i][j].action == SHIFT )                        
                    fprintf( out , "S%02d,",parser_table[i][j].go_to);
                else
                    fprintf( out , "R%02d,",parser_table[i][j].go_to);
            }
            else
                fprintf( out , ",");                
        }
        fprintf( out ,"\n"); 
    }
    fclose(out);
    
    
    //printf( "%d\n", go_to_state(4,5) );
    for ( i = 0 ; i < state_num ; i++ )
    {
        view_state(i);
        fprintf(view,"\n");
        //getch();
        //system("cls");
	}
    shift_reduce_driver( TreeView1 );

    free_token(&terminal_start);
    free_token(&nonterminal_start);
    free_grammar();
    free_state(&state_start);
    //free_config(&config_start);
    
	//system("pause");
	return 0;
}
Esempio n. 24
0
void shift_reduce_driver( TTreeView *TreeView1 )
{
	char string[64];
	SET *scan_ptr;
	int reduce_rule;
	TTreeNode *root , *parent , *son;

	// clean old tree
	TreeView1->Items->Clear();

	// get scanner token
	do
	{
		fscanf( scan , "%s" , string );
		insert_predict( &scan_start , &scan_end , string );
	} while ( strcmp(string,"$") != 0 );
	scan_ptr = scan_start;
	// push the start state , S ,
	// onto an empty parse stack
	root = (TreeView1)->Items->Add( NULL , state_start->config_set->rule->lhs );

	push_stack( state_start->statenum , root );
	//son = TreeView1->Items->Add( NULL , "1" );
	//parent = TreeView1->Items->AddChild( root , "2" );
	//son->MoveTo( parent , naAddChild );
	//view_stack();
    
    while(TRUE)
    {
		switch(parser_table[stack_top->index][make_id(scan_ptr->string)-1].action)
        {
			case ERROR:
				 //system("pause");
				 //printf("error\n");
				 Application->MessageBoxA("syntax error","error",0);
                 return;
                 
            case ACCEPT:
				 pop_stack(1 , son );
				 son->MoveTo( root , naAddChildFirst );
                 printf("%s\n",state_start->config_set->rule->lhs);
                 //view_stack();
                 printf("pares sucess!\n");
                 return;
                 
			case SHIFT:
				 son = TreeView1->Items->Add( NULL , scan_ptr->string );
				 push_stack( parser_table[stack_top->index][make_id(scan_ptr->string)-1].go_to , son );
				 printf("%s\n",scan_ptr->string , son );
                 //view_stack();
                 scan_ptr = scan_ptr->next;
                 break;
                 
            case REDUCE:
				 reduce_rule = parser_table[stack_top->index][make_id(scan_ptr->string)-1].go_to;
				 son = TreeView1->Items->Add( NULL , idtogram(reduce_rule)->lhs );
				 pop_stack( count_rhs_num( reduce_rule ) , son );
				 push_stack( parser_table[stack_top->index][make_id( idtogram(reduce_rule)->lhs )-1].go_to , son );
                 printf("%s\n",idtogram(reduce_rule)->lhs);
                 //view_stack();
                 break;
                 
        }
    }
}