Exemplo n.º 1
0
static void ConsoleCmdHandler(ConsoleInformation* console, char* args)
{
    auto argsSplit = split_args(args);
    const auto cmd(argsSplit.front());
    argsSplit.erase(argsSplit.begin());
    gConsoleMap[console]->ExecuteCommand(cmd, argsSplit);
}
Exemplo n.º 2
0
Arquivo: repl.c Projeto: bcho/homework
void
repl()
{
    int i, command_length, command_rv, argc;
    char argv[ARGS_MAX][ARG_MAX + 1];
    char *inputs;
    command_func_type *command;

    help(0, NULL);
    inputs = NULL;
    while (1) {
        printf("%c ", PROMPT_CHAR);
        u_getline(&inputs, (size_t *) &i, stdin);

        command = help;
        for (i = 0; i < COUNT(commands); i++) {
            command_length = strlen(commands[i].name);
            if (strncmp(commands[i].name, inputs, command_length) == 0) {
                command = commands[i].func;
                break;
            }
        }

        argc = split_args(inputs, argv);

        command_rv = command(argc, argv);
        switch (command_rv) {
            case STATUS_EXIT:
                return;
            case STATUS_INPUT:
                printf("输入有误\n");
                break;
        }
    }
}
Exemplo n.º 3
0
static BUILT_IN_COMMAND(loopcmd)
{
	int	argc;
	char	*argv[10];

	if (!subargs)
		subargs = empty_string;

	argc = split_args(args, argv, 9);

	if (argc < 2)
		my_error("%s: syntax error", command);
	else if (!my_stricmp(argv[1], "from") || !my_stricmp(argv[1], "="))
		for_next_cmd(argc, argv, subargs);
	else if (!my_stricmp(argv[1], "in"))
	{
		if (argc < 4)
			my_error("%s: syntax error", command);
		else if (*argv[2] == '(')
			for_fe_cmd(argc, argv, subargs);
		else
			for_pattern_cmd(argc, argv, subargs);
	}
	else
		my_error("%s: syntax error", command);
}
Exemplo n.º 4
0
Arquivo: exec.c Projeto: ratschlab/dss
/**
 * Exec the command given as a command line.
 *
 * \param pid Will hold the pid of the created process upon return.
 * \param cmdline Holds the command and its arguments, seperated by spaces.
 *
 * This function uses fork/exec to create a new process.
 *
 * \return Standard.
 */
void dss_exec_cmdline_pid(pid_t *pid, const char *cmdline)
{
	char **argv, *tmp = dss_strdup(cmdline);

	split_args(tmp, &argv, " \t");
	dss_exec(pid, argv[0], argv);
	free(argv);
	free(tmp);
}
Exemplo n.º 5
0
bool split_args(char const *args,char ***args_array,MyString *error_msg) {
	SimpleList<MyString> args_list;
	if(!split_args(args,&args_list,error_msg)) {
		*args_array = NULL;
		return false;
	}

	*args_array = ArgListToArgsArray(args_list);
	return *args_array != NULL;
}
Exemplo n.º 6
0
/*
 * First we divide the given arguments into FUSE and cmd arguments, pass the
 * FUSE arguments to FUSE, and call cmd_Dispatch in the FUSE init function.
 */
int
main(int argc, char **argv)
{
	int code;
	struct fuse_args args = FUSE_ARGS_INIT(argc-1, &argv[1]);
	fuse_opt_add_arg(&afsd_args, argv[0]);

#ifdef AFS_SUN511_ENV
	/* for some reason, Solaris 11 FUSE takes the filesystem name from
	 * argv[0], and ignores the -ofsname option */
	fuse_opt_add_arg(&fuse_args, "AFS");
#else
	fuse_opt_add_arg(&fuse_args, argv[0]);
#endif

	/* let us determine file inode numbers, not FUSE. also make "AFS" appear
	 * in df/mount/mnttab/etc output. */
	fuse_opt_add_arg(&fuse_args, "-ouse_ino,fsname=AFS");

	if (getuid() == 0) {
	    /* allow other users to access the mountpoint. only do this for
	     * root, since non-root may or may not be able to do this */
	    fuse_opt_add_arg(&fuse_args, "-oallow_other");
	}

	code = uafs_Setup("/afs");
	if (code) {
		errno = code;
		perror("libuafs");
		return 1;
	}

	split_args(&args);

	uafs_ParseArgs(afsd_args.argc, afsd_args.argv);

	/* pass "-- /mount/dir" to fuse to specify dir to mount; "--" is
	 * just to make sure fuse doesn't interpret the mount dir as a flag
	 */
#ifndef AFS_SUN511_ENV
	/* This seems to screw up option parsing on Solaris 11 FUSE, so just
	 * don't do it. This makes it slightly more annoying to mount on a dir
	 * called -foo or something, but oh well. */
	fuse_opt_add_arg(&fuse_args, "--");
#endif
	fuse_opt_add_arg(&fuse_args, uafs_MountDir());

	return fuse_main(fuse_args.argc, fuse_args.argv, &fuafsd_oper, NULL);
}
Exemplo n.º 7
0
static void process_section(FILE *f, int *lnptr, 
			    masterconf_process *func, void *rock)
{
    struct entry e;
    char buf[4096];
    int lineno = *lnptr;

    while (fgets(buf, sizeof(buf), f)) {
	char *p, *q;

	lineno++;

	/* remove EOL character */
	if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
	/* remove starting whitespace */
	for (p = buf; *p && Uisspace(*p); p++);

	/* remove comments */
	q = strchr(p, '#');
	if (q) *q = '\0';

	/* skip empty lines or all comment lines */
	if (!*p) continue;
	if (*p == '}') break;

	for (q = p; Uisalnum(*q); q++) ;
	if (*q) {
	    if (q > p && !Uisspace(*q))
		fatalf(EX_CONFIG, "configuration file %s: "
				  "bad character '%c' in name on line %d",
				  MASTER_CONFIG_FILENAME, *q, lineno);
	    *q++ = '\0';
	}

	if (q - p > 0) {
	    /* there's a value on this line */
	    memset(&e, 0, sizeof(e));
	    e.lineno = lineno;
	    split_args(&e, q);
	    func(p, &e, rock);
	}

	/* end of section? */
	if (strchr(q, '}')) break;
    }

    *lnptr = lineno;
}
Exemplo n.º 8
0
int run_cmd(void *d, void *opt)
{
     struct vtun_cmd *cmd = d;	
     char *argv[50], *args;
     int pid, st;

     switch( (pid=fork()) ){
	case 0:
	   break;
	case -1:
	   vtun_syslog(LOG_ERR,"Couldn't fork()");
	   return 0;
	default:
    	   if( cmd->flags & VTUN_CMD_WAIT ){
	      /* Wait for termination */
	      if( waitpid(pid,&st,0) > 0 && (WIFEXITED(st) && WEXITSTATUS(st)) )
		 vtun_syslog(LOG_INFO,"Command [%s %.20s] error %d", 
				cmd->prog ? cmd->prog : "sh",
				cmd->args ? cmd->args : "", 
				WEXITSTATUS(st) );
	   }
    	   if( cmd->flags & VTUN_CMD_DELAY ){
	      struct timespec tm = { VTUN_DELAY_SEC, 0 };
	      /* Small delay hack to sleep after pppd start.
	       * Until I have no good solution for solving 
	       * PPP + route problem  */
	      nanosleep(&tm, NULL);
	   }
	   return 0;	 
     }

     args = subst_opt(cmd->args, opt);
     if( !cmd->prog ){
	/* Run using shell */
	cmd->prog = "/bin/sh";
        argv[0] = "sh";	
	argv[1] = "-c";
	argv[2] = args;
	argv[3] = NULL;
     } else {
        argv[0] = cmd->prog;	
        split_args(args, argv + 1);
     }
     execv(cmd->prog, argv);

     vtun_syslog(LOG_ERR,"Couldn't exec program %s", cmd->prog);
     exit(1);
}
Exemplo n.º 9
0
user_tasks()
{
	char buffer[260];
	int argc;
	char *argv[10];


	if(kbhiteol(0)) /// second argument 1 = only report when an EOL is detectedEOL
	{
		fgets(buffer,255,stdin);
		printf("Command:[%s]\n",buffer);
		argc = split_args(buffer, argv, 10);
		if(!user_tests(argc,argv))
			printf("unknown command:[%s]\n", buffer);
	}
}
Exemplo n.º 10
0
static void
process_line(struct bufferevent *bev, void *ctx, char *line)
{
    char **argv;
    int argc = split_args(line, &argv);
    int i;

    for (i = 0; cmdlist[i].cmd; i++)
	if (evutil_ascii_strcasecmp(line, cmdlist[i].cmd) == 0)
	    break;

    (cmdlist[i].func)(bev, ctx, argc - 1, argv + 1);

    free(argv);
    free(line);
}
Exemplo n.º 11
0
void splitArgs(IO &io,char *args){
	if (strlen(args)==0)
		return;

	int argc;
	UNICODE_STRING str;
	wchar_t *wstr;
	char buffer[100];
	wstr=(wchar_t*)buffer;
	mbstowcs(wstr,args,50);
	NT::RtlInitUnicodeString(&str,wstr);
	str.Length-=2;
	char **argv=split_args(io,str.Buffer,str.Length/2,&argc);
	for (int i=0;i<argc;i++)
		io.println(argv[i]);
}
Exemplo n.º 12
0
bool
Env::MergeFromV2Raw( const char *delimitedString, MyString *error_msg )
{
	SimpleList<MyString> env_list;

	if(!delimitedString) return true;

	if(!split_args(delimitedString,&env_list,error_msg)) {
		return false;
	}

	SimpleListIterator<MyString> it(env_list);
	MyString *env_entry;
	while(it.Next(env_entry)) {
		if(!SetEnvWithErrorMessage(env_entry->Value(),error_msg)) {
			return false;
		}
	}
	return true;
}
Exemplo n.º 13
0
void
coquille(void)
{
  int             nb_arg, pid, status, cexit = 0;
  char            prompt_line[255];
  char            buffer[255];
  // char            ibuf[3];

  strcpy("coquille> ", prompt_line);
  print(prompt_line);

  while (!cexit)
  {
    // waiting for the user to enter a command
    gets(buffer, 255);
    printn();

    // split the string
    nb_arg = split_args(buffer, command_arg);

    if (nb_arg != -1)
    {
      // if the command is exit, exit the shell
      if (strcmp("exit", command_arg[0]) == 0)
        cexit = 1;
      // otherwise create the desirated process
      else
      {
        pid =
          fourchette(command_arg[0], BAS_PRI, nb_arg, (char **) command_arg);
        if (pid > 0)
          wait(pid, &status);
        else
					perror("Error");
      }
    }
    if (!cexit)
      print("coquille> ");
  }
  exit(0);
}
Exemplo n.º 14
0
static idn_result_t
parse_local_map(idn_resconf_t ctx, char *args, int lineno) {
	idn_result_t r;
	char *argv[MAX_CONF_LINE_ARGS + 1];
	int argc;
	int i;

	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);

	if (argc < 2 || argc > MAX_CONF_LINE_ARGS) {
		ERROR(("libidnkit: wrong # of args for local-map, line %d\n",
		       lineno));
		return (idn_invalid_syntax);
	}

	if (ctx->local_mapper == NULL) {
		r = idn_mapselector_create(&ctx->local_mapper);
		if (r != idn_success) {
			ERROR(("libidnkit: cannot create local mapper, %s, "
			       "line %d\n", idn_result_tostring(r), lineno));
			return (r);
		}
	}

	for (i = 1; i < argc; i++) {
		r = idn_mapselector_add(ctx->local_mapper, argv[0], argv[i]);
		if (r == idn_invalid_name) {
			ERROR(("libidnkit: map scheme unavailable \"%-.30s\""
			       " or invalid TLD \"%-.30s\", line %d\n",
			       argv[i], argv[0], lineno));
			return (r);
		} else if (r != idn_success) {
			return (r);
		}
	}

	return (idn_success);
}
Exemplo n.º 15
0
// === CODE ===
void EmergencyConsole(void)
{
    for(;;)
    {
        dprintf(STDOUT, "(kernel)$ ");
        char *line = read_line(STDIN);

        // Explode line into args
        char **args = split_args(line);
        // Get command from first arg
        ASSERT(args);
        ASSERT(args[0]);
        if( strcmp(args[0], "help") == 0 ) {
            dprintf(STDOUT,
                    "Commands:\n"
                    "ls <path> - List the contents of a directory\n"
                    "hd <path> - Dump a file in a 16 bytes/line hex format\n"
                    "mount <fs> <device> <point> - Mount a filesystem\n"
                   );
        }
        else if( strcmp(args[0], "ls") == 0 ) {
            Command_ls(args[1]);
        }
        else if( strcmp(args[0], "hd") == 0 ) {
            Command_hd(args[1]);
        }
        else if( strcmp(args[0], "mount") == 0 ) {
            Command_mount(args[1], args[2], args[3]);
        }
        else
        {
            dprintf(STDERR, "Unknown command '%s'\n", args[0]);
        }
        // Free args
        free(args);
        free(line);
    }
}
Exemplo n.º 16
0
static idn_result_t
parse_idn_encoding(idn_resconf_t ctx, char *args, int lineno) {
	idn_result_t r;
	char *argv[MAX_CONF_LINE_ARGS + 1];
	int argc;

	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);

	if (argc != 1) {
		ERROR(("libidnkit: wrong # of args for idn-encoding, "
		       "line %d\n", lineno));
		return (idn_invalid_syntax);
	}

	r = idn_converter_create(argv[0], &ctx->idn_converter,
				 IDN_CONVERTER_DELAYEDOPEN |
				 IDN_CONVERTER_RTCHECK);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create idn converter, %s, "
		       "line %d\n", idn_result_tostring(r), lineno));
	}

	return (r);
}
Exemplo n.º 17
0
int process_line(char *line){
     int i=0;
     char *str,*args,**argv=NULL;
     struct conf_entry *entry;

     str=line;
     while(*str!='\0' && isspace(*str)) /*Eat the spaces in the begging*/
	  str++;
     if(*str=='\0' || *str=='#') /*Empty line or comment*/
	  return 0;
     
     entry=find_action(str,&args);
//     debug_printf(10,"Line %s (Args:%s)\n",entry->name,args);
     
     if(entry && entry->action){
	  argv=split_args(args);
	  (*(entry->action))(entry->name,argv,entry->data);
	  free_args(argv);
	  return 1;/*OK*/
     }
     //Else parse error.......
     //Log an error.....
     return 0;
}
Exemplo n.º 18
0
void
GangliaD::initAndReconfig()
{
	std::string libname;
	std::string gmetric_path;
	param(libname,"GANGLIA_LIB");
	param(gmetric_path,"GANGLIA_GMETRIC");
	if( libname.empty() && gmetric_path.empty()) {
		std::string libpath;
		char const *libpath_param = "GANGLIA_LIB_PATH";
		if( __WORDSIZE == 64 ) {
			libpath_param = "GANGLIA_LIB64_PATH";
		}
		param(libpath,libpath_param);

		dprintf(D_FULLDEBUG,"Searching for libganglia in %s=%s\n",libpath_param,libpath.c_str());
		locateSharedLib(libpath,"libganglia",libname);

		gmetric_path = "gmetric";

		if( libname.empty() && gmetric_path.empty()) {
			EXCEPT("libganglia was not found via %s, and GANGLIA_LIB is not configured, "
				   "and GANGLIA_GMETRIC is not configured.  "
				   "Ensure that libganglia is installed in a location included in %s "
				   "or configure GANGLIA_LIB and/or GANGLIA_GMETRIC.",
				   libpath_param, libpath_param);
		}
	}
	m_ganglia_noop = false;
	if( libname == "NOOP" ) {
		dprintf(D_ALWAYS,"GANGLIA_LIB=NOOP, so we will go through the motions, but not actually interact with ganglia\n");
		m_ganglia_noop = true;
	}

	if( !m_ganglia_noop ) {
		bool gmetric_initialized = false;
		bool libganglia_initialized = false;
		if( !gmetric_path.empty() ) {
			dprintf(D_ALWAYS,"Testing %s\n",gmetric_path.c_str());
			if( ganglia_init_gmetric(gmetric_path.c_str()) ) {
				gmetric_initialized = true;
			}
		}
		if( !libname.empty() ) {
			if( libname == m_ganglia_libname ) {
				libganglia_initialized = true;
				dprintf(D_ALWAYS,"Already loaded libganglia %s\n",libname.c_str());
				// I have observed instabilities when reloading the library, so
				// it is best to not do that unless it is really necessary.
			}
			else {
				dprintf(D_ALWAYS,"Loading libganglia %s\n",libname.c_str());
				ganglia_config_destroy(&m_ganglia_context,&m_ganglia_config,&m_ganglia_channels);
				if( ganglia_load_library(libname.c_str()) ) {
					libganglia_initialized = true;
					m_ganglia_libname = libname;
				}
				else if( gmetric_initialized ) {
					dprintf(D_ALWAYS,"WARNING: failed to load %s, so gmetric (which is slower) will be used instead.\n",libname.c_str());
				}
			}
		}

		if( libganglia_initialized ) {
			dprintf(D_ALWAYS,"Will use libganglia to interact with ganglia.\n");
		}
		else if( gmetric_initialized ) {
			dprintf(D_ALWAYS,"Will use gmetric to interact with ganglia.\n");
		}
		else {
			EXCEPT("Neither gmetric nor libganglia were successfully initialized.  Aborting");
		}

		std::string ganglia_conf_location;
		param(ganglia_conf_location, "GANGLIA_CONFIG", "/etc/ganglia/gmond.conf");
		int fd;
		if ((fd = safe_open_wrapper_follow(ganglia_conf_location.c_str(), O_RDONLY)) < 0)
		{
			EXCEPT("Cannot open Ganglia configuration file GANGLIA_CONFIG=%s.", ganglia_conf_location.c_str());
			return;
		}
		close(fd);

		if( !ganglia_reconfig(ganglia_conf_location.c_str(),&m_ganglia_context,&m_ganglia_config,&m_ganglia_channels) ) {
			EXCEPT("Failed to configure ganglia library.");
		}
	}

	param(m_gstat_command, "GANGLIA_GSTAT_COMMAND");
    split_args(m_gstat_command.c_str(), &m_gstat_argv);

    m_send_data_for_all_hosts = param_boolean("GANGLIA_SEND_DATA_FOR_ALL_HOSTS", false);

	StatsD::initAndReconfig("GANGLIAD");

	// the interval we tell ganglia is the max time between updates
	m_tmax = m_stats_pub_interval*2;
	// the interval we tell ganglia is the lifetime of the metric
	if( m_tmax*3 < 86400 ) {
		m_dmax = 86400;
	}
	else {
		m_dmax = m_tmax*3;
	}
}
Exemplo n.º 19
0
term *handle_input_from_toolbus(term *e)
{
  char *txt, *cmd_txt, output[MAXOUTPUT], *outp;
  int n, len, r, status;
  FILE *from_cmd;
  term *arg;

  outp = output;

  if(TBmatch(e, "rec-terminate(%t)", &arg)){
    unlink(tmp_in);
    unlink(tmp_out);
    exit(0);
  } else if(TBmatch(e, "rec-eval(cmd(%s,input(%s)))", &cmd_txt, &txt)){  
    split_args(cmd_txt);
    the_cmd = cmd;
    len = strlen(txt);
    goto exec_cmd;
  } else if(TBmatch(e, "rec-eval(input(%s))", &txt)){
    the_cmd = def_cmd;
    len = strlen(txt);
    goto exec_cmd;
  } else if(TBmatch(e, "rec-eval(input-term(%t))", &arg)) {
    the_cmd = def_cmd;
    txt = TBsprintf("%t", arg);
    len = strlen(txt);
    goto exec_cmd;
  } else if(TBmatch(e, "rec-eval(cmd(%s,input-term(%t)))", &cmd_txt, &arg)){  
    split_args(cmd_txt);
    the_cmd = cmd;
    txt = TBsprintf("%t", arg);
    len = strlen(txt);
    goto exec_cmd;
  } else if(TBmatch(e, "rec-eval(input(%b))", &txt, &len)){
    the_cmd = def_cmd;
exec_cmd:

    if(addnewline)
      txt[len++] = '\n';

    exec_cmd(txt, len);    
    while ((r = wait(&status)) != cmd_pid && r != -1)
      fprintf(stderr, "wait = %d\n", r);  

    if((from_cmd = fopen(tmp_out, "rb")) == NULL)
      err_sys_fatal("Can't open tmp output file");

    /* Mon May  3 17:36:12 MET DST 1999 mdejonge
     *
     * When output type != tb_term, we read the output of the  command that
     * we executed (stored in the file tmp_out) as string. When output type
     * equals tb_term, we use TBreadTerm to read (and parse) the contents of
     * that file to obtain an term. 
     *
     * NOTE: With the new aterm library we would probably have used the function
     * ATparse to obtain an aterm from a string.
     *
     */
    if( output_type != tb_term )
    {
      while((n=fread(outp, 1, 512, from_cmd)) > 0){
	if(outp + n > &output[MAXOUTPUT]) 
	  err_fatal("Executed command produces too long output");
	outp += n;
      }
      if(*(outp-1) == '\n' && !keepnewline) {
	if(output_type == tb_bstring)
	  outp--;
	else
	  *(outp-1) = '\0';
      } else {
	if(output_type != tb_bstring)
	  *outp++ = '\0';
      }
      fclose(from_cmd);
      switch( output_type )
      {
	case tb_bstring:
	  return TBmake(TBfalse, "snd-value(output(%b))", output, outp-output);
	case tb_string:
	  return TBmake(TBfalse, "snd-value(output(%s))", output);
	case tb_term:
	  return NULL;
      }
    }
    else
    {
      /* Mon May  3 17:36:12 MET DST 1999 mdejonge
       *
       * Construct a term from the contents of the file tmp_out by using
       * the function TBreadTerm.
       */
      term *t;
      t = TBreadTerm( from_cmd );
      fclose(from_cmd );
      return TBmake(TBfalse,  "snd-value(output(%t))", t );
    }

  } 
  TBmsg("Ignore: %t\n", e);
  return NULL;
}
Exemplo n.º 20
0
static idn_result_t
parse_nameprep(idn_resconf_t ctx, char *args, int lineno) {
	idn_result_t r;
	char *argv[MAX_CONF_LINE_ARGS + 1];
	char scheme_name[MAX_CONF_LINE_LENGTH + 1];
	int argc;

	argc = split_args(args, argv, MAX_CONF_LINE_ARGS + 1);

	if (argc != 1) {
		ERROR(("libidnkit: wrong # of args for nameprep, line %d\n",
		       lineno));
		return (idn_invalid_syntax);
	}

	/*
	 * Set mapper.
	 */
	r = idn_mapper_create(&ctx->mapper);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create mapper, %s, line %d\n",
		       idn_result_tostring(r), lineno));
		return (r);
	}

	r = idn_mapper_add(ctx->mapper, argv[0]);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: map scheme unavailable \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set normalizer.
	 */
	r = idn_normalizer_create(&ctx->normalizer);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create normalizer, %s, line %d\n",
		       idn_result_tostring(r), lineno));
		return (r);
	}

	r = idn_normalizer_add(ctx->normalizer, argv[0]);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown normalization scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set prohibit checker.
	 */
	r = idn_checker_create(&ctx->prohibit_checker);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create prohibit checker, %s, "
		       "line %d\n", idn_result_tostring(r), lineno));
		return (r);
	}

	sprintf(scheme_name, "%s%s", IDN_CHECKER_PROHIBIT_PREFIX, argv[0]);
	r = idn_checker_add(ctx->prohibit_checker, scheme_name);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown prohibit scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set unassigned checker.
	 */
	r = idn_checker_create(&ctx->unassigned_checker);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create unassigned checker, %s, "
		       "line %d\n", idn_result_tostring(r), lineno));
		return (r);
	}

	sprintf(scheme_name, "%s%s", IDN_CHECKER_UNASSIGNED_PREFIX, argv[0]);
	r = idn_checker_add(ctx->unassigned_checker, scheme_name);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown unassigned scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	/*
	 * Set bidi checker.
	 */
	r = idn_checker_create(&ctx->bidi_checker);
	if (r != idn_success) {
		ERROR(("libidnkit: cannot create bidi checker, %s, line %d\n",
		       idn_result_tostring(r), lineno));
		return (r);
	}

	sprintf(scheme_name, "%s%s", IDN_CHECKER_BIDI_PREFIX, argv[0]);
	r = idn_checker_add(ctx->bidi_checker, scheme_name);
	if (r == idn_invalid_name) {
		ERROR(("libidnkit: unknown bidi scheme \"%-.30s\", "
		       "line %d\n", argv[0], lineno));
		return (r);
	} else if (r != idn_success) {
		return (r);
	}

	return (idn_success);
}
Exemplo n.º 21
0
static idn_result_t
parse_conf(idn_resconf_t ctx, FILE *fp) {
	char line[MAX_CONF_LINE_LENGTH + 1];
	int lineno = 0;
	char *argv[3];
	int argc;
	idn_result_t r;
	int conf_mask = 0;

	TRACE(("parse_conf()\n"));

	/*
	 * Parse config file.  parsing of 'idn-encoding' line is
	 * postponed because 'alias-file' line must be processed
	 * before them.
	 */
	while (fgets(line, sizeof(line), fp) != NULL) {
		char *newline;

		lineno++;
		newline = strpbrk(line, "\r\n");
		if (newline != NULL)
			*newline = '\0';
		else if (fgetc(fp) != EOF) {
			ERROR(("libidnkit: too long line \"%-.30s\", "
			       "line %d\n", line, lineno));
			return (idn_invalid_syntax);
		}

		argc = split_args(line, argv, 2);
		if (argc == -1) {
			ERROR(("libidnkit: syntax error, line %d\n", lineno));
			return (idn_invalid_syntax);
		} else if (argc == 0 || argv[0][0] == '#') {
			continue;
		} else if (argc == 1) {
			ERROR(("libidnkit: syntax error, line %d\n", lineno));
			return (idn_invalid_syntax);
		}

		if (strcmp(argv[0], "idn-encoding") == 0) {
			if (conf_mask & DEFAULT_CONF_IDN_ENCODING) {
				ERROR(("libidnkit: \"%s\" redefined, "
				       "line %d\n", argv[0], lineno));
				r = idn_invalid_syntax;
			} else {
				conf_mask |= DEFAULT_CONF_IDN_ENCODING;
				r = parse_idn_encoding(ctx, argv[1], lineno);
			}
		} else if (strcmp(argv[0], "local-map") == 0) {
			r = parse_local_map(ctx, argv[1], lineno);

		} else if (strcmp(argv[0], "nameprep") == 0) {
			if (conf_mask & DEFAULT_CONF_NAMEPREP) {
				ERROR(("libidnkit: \"%s\" redefined, "
				       "line %d\n", argv[0], lineno));
				r = idn_invalid_syntax;
			} else {
				conf_mask |= DEFAULT_CONF_NAMEPREP;
				r = parse_nameprep(ctx, argv[1], lineno);
			}
		} else if (strcmp(argv[0], "nameprep-map") == 0 ||
			   strcmp(argv[0], "nameprep-normalize") == 0 ||
			   strcmp(argv[0], "nameprep-prohibit") == 0 ||
			   strcmp(argv[0], "nameprep-unassigned") == 0 ||
			   strcmp(argv[0], "alias-file") == 0 ||
			   strcmp(argv[0], "encoding-alias-file") == 0 ||
			   strcmp(argv[0], "normalize") == 0 ||
			   strcmp(argv[0], "server-encoding") == 0 ||
		           strcmp(argv[0], "alternate-encoding") == 0 ||
			   strcmp(argv[0], "delimiter-map") == 0) {
			WARNING(("libidnkit: obsolete command \"%s\", line %d "
			         "(ignored)\n", argv[0], lineno));
			r = idn_success;
		} else {
			ERROR(("libidnkit: unknown command \"%-.30s\", "
			       "line %d\n", argv[0], lineno));
			r = idn_invalid_syntax;
		}
		if (r != idn_success)
			return (r);
	}

	lineno++;

	if (conf_mask != DEFAULT_CONF_ALL) {
		return setdefaults_body(ctx, conf_mask);
	}

	return (idn_success);
}
Exemplo n.º 22
0
bool
ArgList::AppendArgsV2Raw(char const *args,MyString *error_msg)
{
	return split_args(args,&args_list,error_msg);
}