示例#1
0
int
grecs_str_to_sockaddr(struct grecs_sockaddr **sap,
		      const char *arg, struct grecs_sockaddr_hints *gh,
		      grecs_locus_t const *locus)
{
	char *p;
	struct grecs_sockaddr_hints ghints;
	
	if (!gh) {
		memset(&ghints, 0, sizeof(ghints));
		if (grecs_default_port) {
			ghints.flags = GRECS_HINT_PORT;
			ghints.port = ntohs(grecs_default_port);
		}
		gh = &ghints;
	}
	
	p = strchr(arg, ':');
	if (p && p > arg && p[1] == '/' && p[2] == '/') {
		size_t len = p - arg;
		struct schemetab *sp;

		for (sp = schemetab; sp->scheme; sp++)
			if (len == sp->len &&
			    memcmp(arg, sp->scheme, len) == 0)
				return sp->parser(sap, arg, p + 3, gh, locus);
		grecs_error(locus, 0,
			    _("unknown or unsupported scheme: %s"), arg);
		return -1;
	}

	if (arg[0] == '/')
		return parse_unix(sap, arg, arg, gh, locus);
	else if (strlen(arg) > 5 && memcmp(arg, "unix:", 5) == 0) {
		if (arg[5] != '/')
			grecs_error(locus, 0,
				    _("%s: UNIX socket must be an absolute file name"),
				    arg);
		return parse_unix(sap, arg, arg + 5, gh, locus);
	}
	
	return parse_inet(sap, AF_UNSPEC, arg, arg, gh, locus);
}
示例#2
0
static void test_parse_unix(const char *uri_text, const char *pathname) {
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
  grpc_uri *uri = grpc_uri_parse(&exec_ctx, uri_text, 0);
  grpc_resolved_address addr;

  GPR_ASSERT(1 == parse_unix(uri, &addr));
  struct sockaddr_un *addr_un = (struct sockaddr_un *)addr.addr;
  GPR_ASSERT(AF_UNIX == addr_un->sun_family);
  GPR_ASSERT(0 == strcmp(addr_un->sun_path, pathname));

  grpc_uri_destroy(uri);
  grpc_exec_ctx_finish(&exec_ctx);
}
示例#3
0
static int 
ftpparse_int(struct ftpparse *fp,char *buf,int len)
{
  unsigned int count;
  char *p[MAXWORDS];
  int l[MAXWORDS] = { 0,0,0,0,0,0,0,0,0,0 };

  SETUP();

  if (len < 2) /* an empty name in EPLF, with no info, could be 2 chars */
    return 0;

  /* cheap cases first */
  switch (*buf) {
  case '+':
    if (parse_eplf(fp,buf,len))
      return 1;
    break;
  case '0': case '1': case '2': case '3': case '4':
  case '5': case '6': case '7': case '8': case '9':
    if (parse_msdos(fp,buf,len)) return 1;
    break;
  }

  count=dosplit(buf, len, p,l);

  switch(*buf) {
  case 'b': case 'c': case 'd': case 'l':
  case 'p': case 's': case '-':
    if (parse_unix(fp,buf,len,p,l,count)) return 1;
    break;
  }

  if (*buf==' ') {
    switch(p[0][0]) {
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
      if (parse_os2(fp,p,l,count)) return 1;
      break;
    }
  }

  if (parse_multinet(fp,p,l,count)) return 1;
  if (parse_supertcp(fp,p,l,count)) return 1;

  return 0;
}