示例#1
0
    template<typename... Args> explicit
    eth_topology(const Args&... args)
        : super(args...),
          m_source(m_source_buf),
          m_destination(m_destination_buf),
          m_neighbor(m_neighbor_buf),
          m_helper(m_helper_buf),
          m_two_hop(m_two_hop_buf)
    {
        constexpr const char *def = NULL;
        const char *source_tmp = kwget(source, def, args...);
        const char *destination_tmp = kwget(destination, def, args...);
        const char *neighbor_tmp = kwget(neighbor, def, args...);
        const char *helper_tmp = kwget(helper, def, args...);
        const char *two_hop_tmp = kwget(two_hop, def, args...);

        if (!parse_address(source_tmp, m_source))
            m_source = NULL;

        if (!parse_address(destination_tmp, m_destination))
            m_destination = NULL;

        if (!parse_address(neighbor_tmp, m_neighbor))
            m_neighbor = NULL;

        if (!parse_address(helper_tmp, m_helper))
            m_helper = NULL;

        if (!parse_address(two_hop_tmp, m_two_hop))
            m_two_hop = NULL;
    }
//Executes all commmands stored in 'command_arr'.
void execute_set_of_instructions(COMMAND* commands_arr, int* registers_arr, byte* mem, int* current_time, CONFIG* config, L1_CACHE* L1_cache, L2_CACHE* L2_cache ){
	int instruction_counter = 1;
	int pc = 0;
	unsigned tag_L1;
	unsigned index_L1;
	unsigned offset_L1;
	unsigned tag_L2;
	unsigned index_L2;
	unsigned offset_L2;
	int way;
	int mem_to_L2_end_time_last_trans;
	
	while (strcmp(commands_arr[pc].cmd_type, "H") != 0){
		parse_address(&offset_L1, &index_L1, &tag_L1, commands_arr[pc].inst_address, config->l1_block_size, config->l1_cache_size);
		parse_address(&offset_L2, &index_L2, &tag_L2, commands_arr[pc].inst_address, config->l2_block_size, config->l2_cache_size);
		
		if (!is_in_L1(index_L1, tag_L1,offset_L1,L1_cache, current_time, config)){
			if (is_in_L2(index_L2, tag_L2,offset_L2,L2_cache,current_time,config)){
				L2_to_L1_trans(L1_cache, offset_L1,index_L1,tag_L1,L2_cache,offset_L2,index_L2,tag_L2,*current_time,config,way,true);
			}else{
				MEM_to_L2_trans(mem, L2_cache, offset_L2, index_L2, tag_L2,*current_time,config,NULL,way,true);
				way = !L2_cache->block_arr[index_L2].LRU;
				mem_to_L2_end_time_last_trans = L2_cache->block_arr[index_L2].block_trans_end_time[way];
				L2_to_L1_trans(L1_cache, offset_L1,index_L1,tag_L1,L2_cache,offset_L2,index_L2,tag_L2,mem_to_L2_end_time_last_trans,config,way,true);
			}
		}

		execute_instruction(commands_arr[pc], commands_arr, registers_arr, mem, &pc);
		instruction_counter++;
	}

}
//Returns the word that is stored in 'mem[address]'.
int load_word(unsigned address, byte* mem, L1_CACHE* L1_cache, L2_CACHE* L2_cache,CONFIG* config,int* current_time){
	unsigned offset_L1;
	unsigned index_L1;
	unsigned tag_L1;
	unsigned offset_L2;
	unsigned index_L2;
	unsigned tag_L2;
	int way;
	int mem_to_L2_end_time_last_trans;
	byte* block;

	parse_address(&offset_L1,&index_L1,&tag_L1,address,config->l1_block_size,config->l1_cache_size);
	parse_address(&offset_L2,&index_L2,&tag_L2,address,config->l2_block_size,config->l2_cache_size);

		if (is_in_L1(index_L1, tag_L1,offset_L1,L1_cache, current_time, config)){
			block = L1_cache->block_arr[index_L1].block;
			return block[offset_L1]<<24 | block[offset_L1+1]<<16 | block[offset_L1+2]<<8 | block[offset_L1+3];
		}else if (is_in_L2(index_L2, tag_L2,offset_L2,L2_cache,current_time,config)){
			way = !L2_cache->block_arr[index_L2].LRU;
			block = L2_cache->block_arr[index_L1].block[way];
			L2_to_L1_trans(L1_cache, offset_L1,index_L1,tag_L1,L2_cache,offset_L2,index_L2,tag_L2,*current_time,config,way);
			return block[offset_L2]<<24 | block[offset_L2+1]<<16 | block[offset_L2+2]<<8 | block[offset_L2+3];
		}else{
			way = !L2_cache->block_arr[index_L2].LRU;
			MEM_to_L2_trans(mem, L2_cache, offset_L2, index_L2, tag_L2,*current_time,config,address,way,false);
			way = !L2_cache->block_arr[index_L2].LRU;
			mem_to_L2_end_time_last_trans = L2_cache->block_arr[index_L2].block_trans_end_time[way];
			L2_to_L1_trans(L1_cache, offset_L1,index_L1,tag_L1,L2_cache,offset_L2,index_L2,tag_L2,mem_to_L2_end_time_last_trans,config,way);
			return  mem[address] <<24 | mem[address+1]<<16 | mem[address+2]<<8 | mem[address+3];
		}
	
}
示例#4
0
static void
parse_ranges_property (struct hw *current,
		       const char *property_name,
		       const char *property_value)
{
  int nr_ranges;
  int range_nr;
  range_property_spec *ranges;
  const char *chp;

  /* determine the number of ranges specified */
  nr_ranges = count_entries (current, property_name, property_value, 3);

  /* create a property of that size */
  ranges = zalloc (nr_ranges * sizeof(*ranges));

  /* fill it in */
  chp = property_value;
  for (range_nr = 0; range_nr < nr_ranges; range_nr++)
    {
      chp = parse_address (current, current,
			   chp, &ranges[range_nr].child_address);
      chp = parse_address (current, hw_parent(current),
			   chp, &ranges[range_nr].parent_address);
      chp = parse_size (current, current,
			chp, &ranges[range_nr].size);
    }

  /* create it */
  hw_add_range_array_property (current, property_name, ranges, nr_ranges);

  free (ranges);
}
示例#5
0
static int
getip(int c, unsigned char **ip_r, int *af_r, gnc_t gnc, void *closure)
{
    char *t;
    unsigned char *ip;
    unsigned char addr[16];
    int af, rc;

    c = getword(c, &t, gnc, closure);
    if(c < -1)
        return c;
    rc = parse_address(t, addr, &af);
    if(rc < 0) {
        free(t);
        return -2;
    }
    free(t);

    ip = malloc(16);
    if(ip == NULL) {
        return -2;
    }
    memcpy(ip, addr, 16);
    *ip_r = ip;
    if(af_r)
        *af_r = af;
    return c;
}
示例#6
0
static void
parse_reg_property (struct hw *current,
		    const char *property_name,
		    const char *property_value)
{
  int nr_regs;
  int reg_nr;
  reg_property_spec *regs;
  const char *chp;

  /* determine the number of reg entries by counting tokens */
  nr_regs = count_entries (current, property_name, property_value, 2);

  /* create working space */
  regs = zalloc (nr_regs * sizeof (*regs));

  /* fill it in */
  chp = property_value;
  for (reg_nr = 0; reg_nr < nr_regs; reg_nr++)
    {
      chp = parse_address (current, hw_parent(current),
			   chp, &regs[reg_nr].address);
      chp = parse_size (current, hw_parent(current),
			chp, &regs[reg_nr].size);
    }

  /* create it */
  hw_add_reg_array_property (current, property_name,
			     regs, nr_regs);

  free (regs);
}
示例#7
0
CockpitConnectable *
cockpit_channel_parse_stream (CockpitChannel *self)
{
  CockpitConnectable *connectable;
  GSocketConnectable *address;
  gboolean local;
  gchar *name;

  address = parse_address (self, &name, &local);
  if (!address)
    return NULL;

  connectable = g_new0 (CockpitConnectable, 1);
  connectable->address = address;
  connectable->name = name;
  connectable->refs = 1;
  connectable->local = local;

  if (!parse_stream_options (self, connectable))
    {
      cockpit_connectable_unref (connectable);
      connectable = NULL;
    }

  return connectable;
}
示例#8
0
文件: local.c 项目: haision/GitHub_C
/* init_channel:
 *  This function will be called when a channel is created, before any 
 *  data is sent.  It should at least set the channel's return address to
 *  something meaningful or at least to a valid string if the driver can't
 *  supply a return address.  It can allocate memory, pointed to by the
 *  `data' field of the channel struct.  Return zero if successful, non-zero
 *  otherwise.
 */
static int local_init_channel(NET_CHANNEL *chan, const char *addr)
{
    channel_data_t *data;
    port_t *port;
    int num;

    MUTEX_LOCK(port_list);

    num = parse_address(addr);
    if (num < 0) {
	MUTEX_UNLOCK(port_list);
	return -1;
    }
    
    port = create_port(num);

    /* We don't need the lock any more because `create_port' incremented
     * the usage counter on the port, so it won't vanish, and we're not 
     * dereferencing the pointer any more. */
    MUTEX_UNLOCK(port_list);

    if (!port)
        return -1;
    
    sprintf(chan->local_addr, "%d", num);

    chan->data = data = malloc(sizeof *data);
    data->port = port;
    data->target = -1;
    
    return 0;
}
示例#9
0
/*!	If there are any arguments given, this will remove only the specified
	addresses from the interface named \a name.
	If there are no arguments, it will remove the complete interface with all
	of its addresses.
*/
void
delete_interface(const char* name, char* const* args, int32 argCount)
{
	BNetworkInterface interface(name);

	for (int32 i = 0; i < argCount; i++) {
		int family = get_address_family(args[i]);
		if (family != AF_UNSPEC)
			i++;

		BNetworkAddress address;
		if (!parse_address(family, args[i], address)) {
			fprintf(stderr, "%s: Could not parse address \"%s\".\n",
				kProgramName, args[i]);
			exit(1);
		}

		status_t status = interface.RemoveAddress(address);
		if (status != B_OK) {
			fprintf(stderr, "%s: Could not delete address %s from interface %s:"
				" %s\n", kProgramName, args[i], name, strerror(status));
		}
	}

	if (argCount == 0) {
		// Delete interface
		BNetworkRoster& roster = BNetworkRoster::Default();

		status_t status = roster.RemoveInterface(interface);
		if (status != B_OK) {
			fprintf(stderr, "%s: Could not delete interface %s: %s\n",
				kProgramName, name, strerror(errno));
		}
	}
}
示例#10
0
parse_reg_property(device *current,
		   const char *property_name,
		   const char *property_value)
{
  int nr_regs;
  int reg_nr;
  reg_property_spec *regs;
  const char *chp;
  device *bus = device_parent(current);

  /* determine the number of reg entries by counting tokens */
  nr_regs = count_entries(current, property_name, property_value,
			  1 + (device_nr_size_cells(bus) > 0));

  /* create working space */
  regs = zalloc(nr_regs * sizeof(*regs));

  /* fill it in */
  chp = property_value;
  for (reg_nr = 0; reg_nr < nr_regs; reg_nr++) {
    chp = parse_address(current, bus, chp, &regs[reg_nr].address);
    if (device_nr_size_cells(bus) > 0)
      chp = parse_size(current, bus, chp, &regs[reg_nr].size);
    else
      memset(&regs[reg_nr].size, 0, sizeof (&regs[reg_nr].size));
  }

  /* create it */
  device_add_reg_array_property(current, property_name,
				regs, nr_regs);

  zfree(regs);
}
示例#11
0
文件: cfido.cpp 项目: kosfango/fips
// ============================================================
	void CFido::operator= (LPCSTR name)
// ============================================================
{
int ret;

    isdigit=zone=net=node=point=0;

	if (*name=='#')	   // it's a direct phone number
	{
	   isdigit=1;
	   strcpy(asciibuf,name);
	   return;
	}

	// if number contains '~' than FileSystem has long filenames
	if (strchr(name,'~'))
	{
	   ::MessageBox(NULL,"Detected problem with filename length!","Error",MB_OK);
	   return;
	}

	if (strchr(name,'_'))
	{
		ret=sscanf(name,"%d_%d_%d_%d",&zone,&net,&node,&point);
		ASSERT((ret==3) || (ret==4));
	}
	else
	{
		ret=parse_address(name,&zone,&net,&node,&point);
		ASSERT(ret==3 || ret==4);
	}
// store this adress internally
	make_address(asciibuf,zone,net,node,point);
}
示例#12
0
文件: Parser.cpp 项目: dpp/SBook5
int Parser::identifyLine(const char *aLine)
{
    int	res = 0;

    res |= parse_address(aLine);
    res |= parse_case(aLine);
    
    //    if(strchr(aLine,ICON_CHAR))	res |= P_PUSHBUTTON;

    if(zip->match(aLine)) 	res |= (P_ZIP | P_ADDRESS);
    if(label->match(aLine))	res |= P_LABEL;
    if(address->match(aLine))	res |= P_ADDRESS;

    if(res & (P_ADDRESS|P_EMAIL)){
	/* Paper and electronic addresses cannot be telephone numbers */
	res	&= ~P_TELEPHONE;
    }
    else{
	/* Things to check if we are not an address */
	if(telephones->match(aLine))	res |= P_TELEPHONE;
	if(notphone->match(aLine))	res &= ~P_TELEPHONE;
	if(blankLine->match(aLine))	res |= P_BLANKLINE;

	/* fix the bug with Office */
	if(res & P_OFFICE){
	    if(telephones->match(aLine)){
		res	&= ~P_ADDRESS;
		res	|= P_TELEPHONE;
	    }
	}
    }
    return res;
}
示例#13
0
int cmd_mail(struct client *client, const char *args)
{
	const char *addr, *const *argv;

	if (client->state.mail_from != NULL) {
		client_send_line(client, "503 5.5.1 MAIL already given");
		return 0;
	}

	if (strncasecmp(args, "FROM:", 5) != 0 ||
	    parse_address(args + 5, &addr, &args) < 0) {
		client_send_line(client, "501 5.5.4 Invalid parameters");
		return 0;
	}

	argv = t_strsplit(args, " ");
	for (; *argv != NULL; argv++) {
		if (strcasecmp(*argv, "BODY=7BIT") == 0)
			client->state.mail_body_7bit = TRUE;
		else if (strcasecmp(*argv, "BODY=8BITMIME") == 0)
			client->state.mail_body_8bitmime = TRUE;
		else {
			client_send_line(client,
				"501 5.5.4 Unsupported options");
			return 0;
		}
	}

	client->state.mail_from = p_strdup(client->state_pool, addr);
	p_array_init(&client->state.rcpt_to, client->state_pool, 64);
	client_send_line(client, "250 2.1.0 OK");
	client_state_set(client, "MAIL FROM");
	return 0;
}
示例#14
0
    board_impl(const std::string& netaddr) {
        std::string host;
        unsigned short port;
        boost::tie(host, port) = parse_address(netaddr);
        
        pbus_.reset((port == 0 ?
                     new brd::bus::udp_bus(host) :
                     new brd::bus::udp_bus(host, port)));

    }
示例#15
0
/**
 * Initialize a SSDP listener. This parses and sets the forwarder address,
 * creates a socket and sets all applicable configuration values to it.
 *
 * @param listener The listener to initialize.
 * @param conf The configuration to use.
 * @param active TRUE if an active SSDP listener is to be initialized.
 * @param port The port to listen on. 0 will set the port to the SSDP port.
 * @param recv_timeout The timeout to set for receiveing/waiting for SSDP
 *        nodes to respond to a SEARCH query.
 *
 * @return 0 on success, errno otherwise.
 */
static int ssdp_listener_init(ssdp_listener_s *listener,
    configuration_s *conf, BOOL is_active, int port, int recv_timeout) {
  PRINT_DEBUG("ssdp_listener_init()");
  SOCKET sock = SOCKET_ERROR;

  if (!listener) {
    PRINT_ERROR("No listener specified");
    return 1;
  }

  memset(listener, 0, sizeof *listener);

  /* If set, parse the forwarder address */
  if (conf->forward_address) {
    if (parse_address(conf->forward_address, &listener->forwarder)) {
      PRINT_WARN("Errnoeous forward address");
      return 1;
    }
  }

  int listen_queue_len = is_active ? ACTIVE_LISTEN_QUEUE_LENGTH :
      PASSIVE_LISTEN_QUEUE_LENGTH;

  socket_conf_s sock_conf = {
    conf->use_ipv6,       // BOOL is_ipv6
    TRUE,                 // BOOL is_udp
    is_active,            // BOOL is_multicast
    conf->interface,      // char interface
    conf->ip,             // the IP we want to bind to
    NULL,                 // struct sockaddr_storage *sa
    SSDP_ADDR,            // The IP we wnat to send to
    port,                 // The port we want to send to (?)
    TRUE,                 // BOOL is_server
    listen_queue_len,  // the length of the listen queue
    FALSE,                // BOOL keepalive
    conf->ttl,            // time to live (router hops)
    conf->enable_loopback,// see own messages on multicast
    0,                    // set the send timeout for the socket (0 = default)
    recv_timeout          // set the receive timeout for the socket
  };

  sock = setup_socket(&sock_conf);
  if (sock == SOCKET_ERROR) {
    PRINT_DEBUG("[%d] %s", errno, strerror(errno));
    return errno;
  }

  listener->sock = sock;
  PRINT_DEBUG("ssdp_listener has been initialized");

  return 0;
}
示例#16
0
文件: session.c 项目: plundstr/ngfd
static gchar*
load_session_bus_address (const char *filename)
{
    FILE   *fp         = NULL;
    size_t  file_size  = 0;
    size_t  bytes_read = 0;
    char   *buf        = NULL;
    gchar  *address    = NULL;

    if (!filename)
        return NULL;

    if ((fp = fopen (filename, "r")) == NULL) {
        N_DEBUG (LOG_CAT "no address file %s", filename);
        return NULL;
    }

    fseek (fp, 0L, SEEK_END);
    file_size = ftell (fp);
    fseek (fp, 0L, SEEK_SET);

    if (file_size > 0) {
        if ((buf = (char*) g_try_malloc0 (sizeof (char) * file_size)) == NULL) {
            N_WARNING (LOG_CAT "failed to allocate memory to read session bus "
                               "address file.");
            fclose (fp);
            return NULL;
        }

        bytes_read = fread (buf, sizeof (char), file_size, fp);
        if (bytes_read != file_size) {
            N_WARNING (LOG_CAT "failed to read the session bus address file.");
            g_free (buf);
            fclose (fp);
            return NULL;
        }

        if ((address = parse_address (buf)) != NULL) {
            N_DEBUG (LOG_CAT "parsed DBus session bus address: %s", address);
        }
        else {
            N_WARNING (LOG_CAT "failed to parse DBus session bus address.");
        }

        g_free (buf);
    }

    fclose (fp);

    return address;
}
示例#17
0
// ===========================================================================
// ASCII file import in format:   xxxxxxxxxx ?:???/?.?
	void receiver::OnImport()
// ===========================================================================
{
FILE *fp;
CString path,str;
char buf[300],fido[20];
int  zone,net,node,point,ret;
char *p;

	str.LoadString(IDS_TEXTFILT);
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,str);

	ret=dlg.DoModal();
	restore_base_path();
	if (ret!=IDOK)	return;
	BeginWaitCursor();
	path=dlg.GetPathName();
	fp=fopen(path,"rt");
	if (fp)
	{
		while (fgets(buf,199,fp))
		{
		   if (*buf==';')		   // comment
		      continue;

		   replace_tabs(buf);	   // remove TAB's
		   p=strchr(buf,':');
		   if (!p)
		      continue;
		   while (*p!=' ')
		         p--;
		   p++;
		   if (parse_address(p,&zone,&net,&node,&point)<3)
			  continue;

		   sscanf(p,"%s",fido);
		   *p=0;

		   m_edit_fido.SetWindowText(fido);
		   m_edit_name.SetWindowText(trim_all(buf));
		   OnAddMember();

		}
		fclose(fp);
	}
	else
		ERR_MSG2_RET("E_CANOPIM",path);

	EndWaitCursor();
}
示例#18
0
LPCSTR parse_addr_spec( LPCSTR s, LPSTR comment, size_t * commentlen,
            size_t commentmax, PPerson addr )
{
  char token[ 128 ];
  size_t tokenlen = 0;

  s = parse_address( s, token, &tokenlen, sizeof( token ) - 1, comment, commentlen, commentmax, addr );
  if ( s && *s && *s != ',' && *s != ';' )
  {
//    RFC822Error = ERR_BAD_ADDR_SPEC;
    return NULL;
  }
  return s;
}
示例#19
0
static int read_managers(node *n, const char *nodesfile, endpointid **outids, int *outcount)
{
  endpointid *managerids;
  int count;
  array *nodes = read_nodes(nodesfile);
  int i;

  *outids = NULL;
  *outcount = 0;

  if (NULL == nodes)
    return -1;

  count = array_count(nodes);
  managerids = (endpointid*)calloc(count,sizeof(endpointid));

  for (i = 0; i < count; i++) {
    char *nodename = array_item(nodes,i,char*);
    char *host = NULL;
    int port = 0;

    if (NULL == strchr(nodename,':')) {
      host = strdup(nodename);
      port = WORKER_PORT;
    }
    else if (0 > parse_address(nodename,&host,&port)) {
      fprintf(stderr,"Invalid node address: %s\n",nodename);
      array_free(nodes);
      free(managerids);
      return -1;
    }
    managerids[i].port = port;
    managerids[i].localid = MANAGER_ID;

    if (0 > lookup_address(host,&managerids[i].ip,NULL)) {
      fprintf(stderr,"%s: hostname lookup failed\n",host);
      array_free(nodes);
      free(managerids);
      return -1;
    }
    free(host);
  }

  *outids = managerids;
  *outcount = count;

  array_free(nodes);
  return 0;
}
示例#20
0
l_slot nodexists(const char *name, const l_slot *Order)
	{
	char alias[4];
	char locID[5];
	Bool addrsearch = FALSE;

	if (isaddress(name))
		{
		parse_address(name, alias, locID, 0);
		addrsearch = TRUE;
		}

	// check to see if name is in log table
	for (l_slot i = 0; i < cfg.MAXLOGTAB; i++)
		{
		l_slot S = Order ? Order[i] : i;

		if (LogTab[S].IsInuse() && LogTab[S].IsNode())
			{
			if (addrsearch)
				{
				if (	// same alias and...
						LogTab[S].IsSameAlias(alias) &&

						// either...
						(
							// not searching locIDs or...
							!*locID || 

							// it matches, too
							LogTab[S].IsSameLocID(locID)
						)
					)
					{
					return (i);
					}
				}
			else
				{
				if (LogTab[S].IsSameName(name))
					{
					return (i);
					}
				}
			}
		}

	return (CERROR);
	}
示例#21
0
文件: rfc822.c 项目: tejux/mutt-hacks
static const char *
parse_addr_spec (const char *s,
char *comment, size_t *commentlen, size_t commentmax,
ADDRESS *addr)
{
        char token[LONG_STRING];
        size_t tokenlen = 0;

        s = parse_address (s, token, &tokenlen, sizeof (token) - 1, comment, commentlen, commentmax, addr);
        if (s && *s && *s != ',' && *s != ';') {
                RFC822Error = ERR_BAD_ADDR_SPEC;
                return NULL;
        }
        return s;
}
示例#22
0
static inline
uint8_t process_data ( bt_addresses * addresses, struct nlmsghdr * data, bool add )
{
    bt_address * address = parse_address ( addresses, NLMSG_DATA ( data ), IFLA_PAYLOAD ( data ) );
    if ( address == NULL ) {
        return 1;
    }
    
    if ( add ) {
        ;
    } else {
        ;
    }

    return 0;
}
示例#23
0
文件: rfc822.c 项目: 2ion/mutt-1.5.22
static const char *
parse_route_addr (const char *s,
		  char *comment, size_t *commentlen, size_t commentmax,
		  ADDRESS *addr)
{
  char token[LONG_STRING];
  size_t tokenlen = 0;

  s = skip_email_wsp(s);

  /* find the end of the route */
  if (*s == '@')
  {
    while (s && *s == '@')
    {
      if (tokenlen < sizeof (token) - 1)
	token[tokenlen++] = '@';
      s = parse_mailboxdomain (s + 1, ",.\\[](", token,
			       &tokenlen, sizeof (token) - 1,
			       comment, commentlen, commentmax);
    }
    if (!s || *s != ':')
    {
      RFC822Error = ERR_BAD_ROUTE;
      return NULL; /* invalid route */
    }

    if (tokenlen < sizeof (token) - 1)
      token[tokenlen++] = ':';
    s++;
  }

  if ((s = parse_address (s, token, &tokenlen, sizeof (token) - 1, comment, commentlen, commentmax, addr)) == NULL)
    return NULL;

  if (*s != '>')
  {
    RFC822Error = ERR_BAD_ROUTE_ADDR;
    return NULL;
  }

  if (!addr->mailbox)
    addr->mailbox = safe_strdup ("@");

  s++;
  return s;
}
示例#24
0
文件: local.c 项目: haision/GitHub_C
/* update_target:
 *  This will be called if the target_addr for the channel changes. 
 *  If necessary, the address could be converted into network format here.
 *  Return zero if any conversion was possible, but don't bother checking
 *  whether or not the target is reachable.
 */
static int local_update_target(NET_CHANNEL *chan)
{
    char *addr;
    int target;

    addr = chan->target_addr;
    if (!addr) return -1;
    
    MUTEX_LOCK(port_list);
    target = parse_address(addr);
    MUTEX_UNLOCK(port_list);

    if (target < 0) return -1;
    ((channel_data_t *)chan->data)->target = target;

    return 0;
}
int main(int argc, char **argv) {
    /*
     From http://codereview.stackexchange.com/questions/71970/creating-a-string-from-command-line-arguments
    */
    if(argc == 1) {
        printf("ERROR: Expected at least 1 argument\n");
        return 0;
    }

    int i, v = 1, size = argc - 1;
    int newsize  = 0;

    char *str = (char *)malloc(v);
    strcpy(str,"");

    for(i = 1; i <= size; i++) {
        newsize = newsize + 1 + sizeof(*str) +strlen(argv[i]);
        str = (char *)realloc(str, (newsize));
        strcat(str, argv[i]);
        strcat(str, " ");
    }


    // Setup (only called once at the beginning of your program)
    if (!libpostal_setup() || !libpostal_setup_parser()) {
        exit(EXIT_FAILURE);
    }

    /* 
        From https://github.com/openvenues/libpostal
     */
    address_parser_options_t options = get_libpostal_address_parser_default_options();
    address_parser_response_t *parsed = parse_address(str, options);

    for (size_t i = 0; i < parsed->num_components; i++) {
        printf("%s: %s\n", parsed->labels[i], parsed->components[i]);
    }

    // Free parse result
    address_parser_response_destroy(parsed);

    // Teardown (only called once at the end of your program)
    libpostal_teardown();
    libpostal_teardown_parser();
}
示例#26
0
// ===========================================================================
	void receiver::OnAddMember()
// ===========================================================================
{
CString name,addr,str,buf;
int		sel,zone,node,net,point;

	GET_SEL(m_groups);
	m_edit_name.GetWindowText(name);
	if (name.IsEmpty())	return;
	m_edit_fido.GetWindowText(addr);
	if (parse_address(addr,&zone,&net,&node,&point) < 3)	ERR_MSG_RET("E_INVALDFIDOA");
	str=name+"\t"+addr;
	m_members.AddString(str);
	m_groups.GetText(sel,str);
	get_token(str,0,buf);
	refresh_groups(buf);
	SET_SEL(m_members,m_members.GetCount()-1);
}
示例#27
0
pn_listener_t *pn_messenger_isource(pn_messenger_t *messenger, const char *source)
{
  char buf[strlen(source) + 1];
  strcpy(buf, source);
  char *domain, *name;
  parse_address(buf, &domain, &name);
  char *user = NULL;
  char *pass = NULL;
  char *host = "0.0.0.0";
  char *port = "5672";
  parse_url(domain + 1, &user, &pass, &host, &port);

  pn_listener_t *listener = pn_listener(messenger->driver, host, port, NULL);
  if (listener) {
    messenger->listeners++;
  }
  return listener;
}
示例#28
0
STATIC cmd_result_t
cmd_esw_dma_get_dv(int unit, args_t *a, dv_t  **laddr)
{
   char *arg;

    if (laddr == NULL) {
        return CMD_FAIL;
    }

    /* Parse the logical address */
    if ((arg = ARG_GET(a)) == NULL &&
        (arg = var_get(CMD_ESW_DMA_DV)) == NULL) {
        return CMD_FAIL;
    }

    *laddr = (void *)parse_address(arg);
    
    return CMD_OK;
}
示例#29
0
STATIC cmd_result_t
cmd_esw_dma_get_paddr(int unit, args_t *a, uint32 *paddr)
{
    char *arg;

    if (paddr == NULL) {
        return CMD_FAIL;
    }

    /* Parse the logical address */
    if ((arg = ARG_GET(a)) == NULL &&
        (arg = var_get(CMD_ESW_DMA_PADDR)) == NULL) {
        return CMD_FAIL;
    }

    *paddr = parse_address(arg);
    
    return CMD_OK;
}
示例#30
0
LPCSTR parse_route_addr( LPCSTR s,
             LPSTR comment, size_t *commentlen, size_t commentmax,
             PPerson addr )
{
  char token[128];
  size_t tokenlen = 0;

  SKIPWS (s);

  /* find the end of the route */
  if (*s == '@')
  {
    while (s && *s == '@')
    {
      if (tokenlen < sizeof (token) - 1)
        token[tokenlen++] = '@';
      s = parse_mailboxdomain (s + 1, ",.\\[](", token,
        &tokenlen, sizeof (token) - 1,
        comment, commentlen, commentmax);
    }
    if (!s || *s != ':')
    {
//      RFC822Error = ERR_BAD_ROUTE;
      return NULL; /* invalid route */
    }

    if (tokenlen < sizeof (token) - 1)
      token[tokenlen++] = ':';
    s++;
  }

  if ((s = parse_address (s, token, &tokenlen, sizeof (token) - 1, comment, commentlen, commentmax, addr)) == NULL)
    return NULL;

  if ( *s != '>' || addr->Addr.IsEmpty() )
  {
//    RFC822Error = ERR_BAD_ROUTE_ADDR;
    return NULL;
  }

  s ++;
  return s;
}