示例#1
0
smtp_etrn_node_t
smtp_etrn_add_node (smtp_session_t session, int option, const char *domain)
{
  smtp_etrn_node_t node;
  char *dup_domain;

  SMTPAPI_CHECK_ARGS (session != NULL
                      && domain != NULL
                      && (option == 0 || option == '@'), NULL);

  if ((node = malloc (sizeof (struct smtp_etrn_node))) == NULL)
    {
      set_errno (ENOMEM);
      return 0;
    }
  if ((dup_domain = strdup (domain)) == NULL)
    {
      free (node);
      set_errno (ENOMEM);
      return 0;
    }

  memset (node, 0, sizeof (struct smtp_etrn_node));
  node->session = session;
  node->option = option;
  node->domain = dup_domain;
  APPEND_LIST (session->etrn_nodes, session->end_etrn_nodes, node);
  session->required_extensions |= EXT_ETRN;
  return node;
}
示例#2
0
/* Take all decedents, return them in a list. */
static struct mapping *
__mapping_linearize_decendents(struct mapping *m)
{
	struct mapping *first, *last, *c, *gc;

	first = c = m->c;
	m->c = NULL;
	if (!c) return NULL;
	do {
		last = LAST_LIST(first, _s, s_);
		c->p = NULL;
		gc = c->c;
		c->c = NULL;
		if (gc) APPEND_LIST(last, gc, _s, s_);
		c = FIRST_LIST(c, _s, s_);
	} while (first != c);

	return first;
}
示例#3
0
文件: idnconv.c 项目: 274914765/C
int main (int ac, char **av)
{
    char *cmd = *av;

    char *cname;

    unsigned long delimiters[MAX_DELIMITER];

    char *localmappers[MAX_LOCALMAPPER];

    char *nameprep_version = NULL;

    int ndelimiters = 0;

    int nlocalmappers = 0;

    char *in_code = NULL;

    char *out_code = NULL;

    char *resconf_file = NULL;

    int no_resconf = 0;

    char *encoding_alias = NULL;

    int flags = DEFAULT_FLAGS;

    FILE *fp;

    idn_result_t r;

    idn_resconf_t resconf1, resconf2;

    idn_converter_t conv;

    int exit_value;

#ifdef HAVE_SETLOCALE
    (void) setlocale (LC_ALL, "");
#endif

    /*
     * If the command name begins with 'r', reverse mode is assumed.
     */
    if ((cname = strrchr (cmd, '/')) != NULL)
        cname++;
    else
        cname = cmd;
    if (cname[0] == 'r')
        flags |= FLAG_REVERSE;

    ac--;
    av++;
    while (ac > 0 && **av == '-')
    {

#define OPT_MATCH(opt) (strcmp(*av, opt) == 0)
#define MUST_HAVE_ARG if (ac < 2) print_usage(cmd)
#define APPEND_LIST(array, size, item, what) \
    if (size >= (sizeof(array) / sizeof(array[0]))) { \
        errormsg("too many " what "\n"); \
        exit(1); \
    } \
    array[size++] = item; \
    ac--; av++

        if (OPT_MATCH ("-in") || OPT_MATCH ("-i"))
        {
            MUST_HAVE_ARG;
            in_code = av[1];
            ac--;
            av++;
        }
        else if (OPT_MATCH ("-out") || OPT_MATCH ("-o"))
        {
            MUST_HAVE_ARG;
            out_code = av[1];
            ac--;
            av++;
        }
        else if (OPT_MATCH ("-conf") || OPT_MATCH ("-c"))
        {
            MUST_HAVE_ARG;
            resconf_file = av[1];
            ac--;
            av++;
        }
        else if (OPT_MATCH ("-nameprep") || OPT_MATCH ("-n"))
        {
            MUST_HAVE_ARG;
            nameprep_version = av[1];
            ac--;
            av++;
        }
        else if (OPT_MATCH ("-noconf") || OPT_MATCH ("-C"))
        {
            no_resconf = 1;
        }
        else if (OPT_MATCH ("-reverse") || OPT_MATCH ("-r"))
        {
            flags |= FLAG_REVERSE;
        }
        else if (OPT_MATCH ("-nolocalmap") || OPT_MATCH ("-L"))
        {
            flags &= ~FLAG_LOCALMAP;
        }
        else if (OPT_MATCH ("-nonameprep") || OPT_MATCH ("-N"))
        {
            flags &= ~FLAG_NAMEPREP;
        }
        else if (OPT_MATCH ("-unassigncheck") || OPT_MATCH ("-u"))
        {
            flags |= FLAG_UNASSIGNCHECK;
        }
        else if (OPT_MATCH ("-nounassigncheck") || OPT_MATCH ("-U"))
        {
            flags &= ~FLAG_UNASSIGNCHECK;
        }
        else if (OPT_MATCH ("-nobidicheck") || OPT_MATCH ("-B"))
        {
            flags &= ~FLAG_BIDICHECK;
        }
        else if (OPT_MATCH ("-noasciicheck") || OPT_MATCH ("-A"))
        {
            flags &= ~FLAG_ASCIICHECK;
        }
        else if (OPT_MATCH ("-nolengthcheck"))
        {
            flags &= ~FLAG_LENGTHCHECK;
        }
        else if (OPT_MATCH ("-noroundtripcheck"))
        {
            flags &= ~FLAG_ROUNDTRIPCHECK;
        }
        else if (OPT_MATCH ("-whole") || OPT_MATCH ("-w"))
        {
            flags &= ~FLAG_SELECTIVE;
        }
        else if (OPT_MATCH ("-localmap"))
        {
            MUST_HAVE_ARG;
            APPEND_LIST (localmappers, nlocalmappers, av[1], "local maps");
        }
        else if (OPT_MATCH ("-delimiter"))
        {
            unsigned long v;

            MUST_HAVE_ARG;
            v = get_ucs (av[1]);
            APPEND_LIST (delimiters, ndelimiters, v, "delimiter maps");
        }
        else if (OPT_MATCH ("-alias") || OPT_MATCH ("-a"))
        {
            MUST_HAVE_ARG;
            encoding_alias = av[1];
            ac--;
            av++;
        }
        else if (OPT_MATCH ("-flush"))
        {
            flush_every_line = 1;
        }
        else if (OPT_MATCH ("-version") || OPT_MATCH ("-v"))
        {
            print_version ();
        }
        else
        {
            print_usage (cmd);
        }
#undef OPT_MATCH
#undef MUST_HAVE_ARG
#undef APPEND_LIST

        ac--;
        av++;
    }

    if (ac > 1)
        print_usage (cmd);

    /* Initialize. */
    if ((r = idn_resconf_initialize ()) != idn_success)
    {
        errormsg ("error initializing library\n");
        return (1);
    }

    /*
     * Create resource contexts.
     * `resconf1' and `resconf2' are almost the same but local and
     * IDN encodings are reversed.
     */
    resconf1 = NULL;
    resconf2 = NULL;
    if (idn_resconf_create (&resconf1) != idn_success || idn_resconf_create (&resconf2) != idn_success)
    {
        errormsg ("error initializing configuration contexts\n");
        return (1);
    }

    /* Load configuration file. */
    if (no_resconf)
    {
        set_defaults (resconf1);
        set_defaults (resconf2);
    }
    else
    {
        load_conf_file (resconf1, resconf_file);
        load_conf_file (resconf2, resconf_file);
    }

    /* Set encoding alias file. */
    if (encoding_alias != NULL)
        set_encoding_alias (encoding_alias);

    /* Set input codeset. */
    if (flags & FLAG_REVERSE)
    {
        if (in_code == NULL)
        {
            conv = idn_resconf_getidnconverter (resconf1);
            if (conv == NULL)
            {
                errormsg ("cannot get the IDN encoding.\n" "please specify an appropriate one " "with `-in' option.\n");
                exit (1);
            }
            idn_resconf_setlocalconverter (resconf2, conv);
            idn_converter_destroy (conv);
        }
        else
        {
            set_idncode (resconf1, in_code);
            set_localcode (resconf2, in_code);
        }
    }
    else
    {
        if (in_code == NULL)
        {
            conv = idn_resconf_getlocalconverter (resconf1);
            if (conv == NULL)
            {
                errormsg ("cannot get the local encoding.\n"
                          "please specify an appropriate one " "with `-in' option.\n");
                exit (1);
            }
            idn_resconf_setidnconverter (resconf2, conv);
            idn_converter_destroy (conv);
        }
        else
        {
            set_localcode (resconf1, in_code);
            set_idncode (resconf2, in_code);
        }
    }

    /* Set output codeset. */
    if (flags & FLAG_REVERSE)
    {
        if (out_code == NULL)
        {
            conv = idn_resconf_getlocalconverter (resconf1);
            if (conv == NULL)
            {
                errormsg ("cannot get the local encoding.\n"
                          "please specify an appropriate one " "with `-out' option.\n");
                exit (1);
            }
            idn_resconf_setidnconverter (resconf2, conv);
            idn_converter_destroy (conv);
        }
        else
        {
            set_localcode (resconf1, out_code);
            set_idncode (resconf2, out_code);
        }
    }
    else
    {
        if (out_code == NULL)
        {
            conv = idn_resconf_getidnconverter (resconf1);
            if (conv == NULL)
            {
                errormsg ("cannot get the IDN encoding.\n"
                          "please specify an appropriate one " "with `-out' option.\n");
                exit (1);
            }
            idn_resconf_setlocalconverter (resconf2, conv);
            idn_converter_destroy (conv);
        }
        else
        {
            set_idncode (resconf1, out_code);
            set_localcode (resconf2, out_code);
        }
    }

    /* Set delimiter map(s). */
    if (ndelimiters > 0)
    {
        set_delimitermapper (resconf1, delimiters, ndelimiters);
        set_delimitermapper (resconf2, delimiters, ndelimiters);
    }

    /* Set local map(s). */
    if (nlocalmappers > 0)
    {
        set_localmapper (resconf1, localmappers, nlocalmappers);
        set_localmapper (resconf2, localmappers, nlocalmappers);
    }

    /* Set NAMEPREP version. */
    if (nameprep_version != NULL)
    {
        set_nameprep (resconf1, nameprep_version);
        set_nameprep (resconf2, nameprep_version);
    }

    idn_res_enable (1);

    /* Open input file. */
    if (ac > 0)
    {
        if ((fp = fopen (av[0], "r")) == NULL)
        {
            errormsg ("cannot open file %s: %s\n", av[0], strerror (errno));
            return (1);
        }
    }
    else
    {
        fp = stdin;
    }

    /* Do the conversion. */
    if (flags & FLAG_REVERSE)
        exit_value = decode_file (resconf1, resconf2, fp, flags);
    else
        exit_value = encode_file (resconf1, resconf2, fp, flags);

    idn_resconf_destroy (resconf1);
    idn_resconf_destroy (resconf2);

    return exit_value;
}
示例#4
0
/*---------------------------------------------------------------*/
int
_dxf_ExManageCacheTable(ModPath *mod_path, uint32 reccrc, int outnbr)
{
    int i, limit;
    pathtag  *pt;
    pathtag  npt;
    int	     ret = FALSE;

    DXDebug ("1", 
     "cache table entry: cpath = %s, reccrc = 0x%08x, outnbr = %d",
             _dxf_ExPathToString(mod_path), reccrc, outnbr);	

    limit = SIZE_LIST(_dxd_pathtags); 

    for (i = 0; i < limit; i++ ) { 
        pt = FETCH_LIST(_dxd_pathtags,i);
        if (pt->entry_inuse == TRUE) {
            if (_dxf_ExPathsEqual( &pt->mod_path, mod_path ) && 
	              pt->outnbr == outnbr) {
                DXDebug ("1", "  Found cache table entry %s / 0x%08x.",
                    _dxf_ExPathToString( &pt->mod_path ), pt->reccrc);	
                if (pt->reccrc != reccrc ) {
                    DXDebug ("1",
                     "Changing tag 0x%08x to 0x%08x for cache table entry %s.",
                          pt->reccrc, reccrc, 
			  _dxf_ExPathToString( &pt->mod_path ));	
                    if(pt->reccrc != 0)
                        _dxf_ExCacheDelete(pt->reccrc);
                    pt->reccrc = reccrc;
                    ret = TRUE;
                }
                return(ret);
            }
        }
    }

    /* Create new entry in pathtag table unless there is one 
     * available for reuse 
     */
    for (i = 0; i < limit; i++ ) { 
        pt = FETCH_LIST(_dxd_pathtags,i);
        if (pt->entry_inuse == FALSE) {
            DXDebug ("1", "  Reusing cache table entry %s.%d / 0x%08x.",
                _dxf_ExPathToString( &pt->mod_path ), pt->outnbr, pt->reccrc);	
            pt->reccrc = reccrc;
            pt->outnbr = outnbr;
            pt->entry_inuse = TRUE;
	    _dxf_ExPathCopy( &pt->mod_path, mod_path );
            return(TRUE);
        }
    }

    npt.reccrc = reccrc;
    npt.outnbr = outnbr;
    npt.entry_inuse = TRUE;
    _dxf_ExPathCopy( &npt.mod_path, mod_path );
    DXDebug ("1", "  Appending cache table entry %s.%d / 0x%08x.",
            _dxf_ExPathToString( &npt.mod_path ), npt.outnbr, npt.reccrc);	
    APPEND_LIST(pathtag,_dxd_pathtags,npt);
    return(TRUE); 
}