Exemplo n.º 1
0
Arquivo: vars.c Projeto: srfrog/epic5
/* 
 * Create a clone of 'var' suitable for putting on the symbol table stack 
 * This does not create a new built in variable!
 * The new IrcVariable created here can be "used" by $symbolctl() but
 * can not be put into the bucket!  
 * Pass it to 'unclone_biv' later.
 */
IrcVariable *	clone_biv (IrcVariable *old)
{
	IrcVariable *var;

	if (!old)
		return NULL;		/* Take THAT! */

	var = (IrcVariable *)new_malloc(sizeof(IrcVariable));
	var->type = old->type;
	if (old->script)
		var->script = malloc_strdup(old->script);
	else
		var->script = NULL;
	var->func = old->func;

	var->data = new_malloc(sizeof(union builtin_variable));
	var->flags = 0;

	switch (old->type) {
	    case BOOL_VAR:
	    case CHAR_VAR:
	    case INT_VAR:
		var->data->integer = old->data->integer;
		break;
	    case STR_VAR:
		if (old->data->string)
			var->data->string = malloc_strdup(old->data->string);
		else
			var->data->string = NULL;
		break;
	}

	return var;
}
Exemplo n.º 2
0
static char *	cipher_evp (const unsigned char *key, int keylen, const unsigned char *plaintext, int plaintextlen, const EVP_CIPHER *type, int *retsize, int ivsize)
{
        unsigned char *outbuf;
        int     outlen = 0;
	int	extralen = 0;
	unsigned char	*iv = NULL;
	unsigned long errcode;
	u_32int_t	randomval;
	int		iv_count;
        EVP_CIPHER_CTX a;
        EVP_CIPHER_CTX_init(&a);
	EVP_CIPHER_CTX_set_padding(&a, 0);

	if (ivsize < 0)
		ivsize = 0;		/* Shenanigans! */

	if (ivsize > 0)
	{
	    if (ivsize % sizeof(u_32int_t) != 0)
		panic(1, "The IV size for a crypto type you're using is %d "
			"which is not a multiple of %d", 
			ivsize, sizeof(u_32int_t));

	    iv = new_malloc(ivsize);
	    for (iv_count = 0; iv_count < ivsize; iv_count += sizeof(u_32int_t))
	    {
		randomval = arc4random();  
		memmove(iv + iv_count, &randomval, sizeof(u_32int_t));
	    }
	}

	outbuf = new_malloc(plaintextlen + 100);
	if (iv)
		memcpy(outbuf, iv, ivsize);

        EVP_EncryptInit_ex(&a, type, NULL, NULL, iv);
	EVP_CIPHER_CTX_set_key_length(&a, keylen);
        EVP_EncryptInit_ex(&a, NULL, NULL, key, NULL);
        EVP_EncryptUpdate(&a, outbuf + ivsize, &outlen, plaintext, plaintextlen);
	EVP_EncryptFinal_ex(&a, outbuf + ivsize + outlen, &extralen);
        EVP_CIPHER_CTX_cleanup(&a);
	outlen += extralen;

	ERR_load_crypto_strings();
	while ((errcode = ERR_get_error()))
	{
	    char r[256];
	    ERR_error_string_n(errcode, r, 256);
	    yell("ERROR: %s", r);
	}

	*retsize = outlen + ivsize;
	if (iv)
		new_free(&iv);		/* XXX Is this correct? */
	return outbuf;
}
Exemplo n.º 3
0
/*
 * XXX - Ugh!  Some getaddrinfo()s take AF_UNIX paths as the 'servname'
 * instead of as the 'nodename'.  How heinous!
 */
int	my_getaddrinfo (const char *nodename, const char *servname, const AI *hints, AI **res)
{
#ifdef GETADDRINFO_DOES_NOT_DO_AF_UNIX
	int	do_af_unix = 0;
	USA 	storage;
	AI *	results;
	int	len;

	if (nodename && strchr(nodename, '/'))
		do_af_unix = 1;
	if (hints && hints->ai_family == AF_UNIX)
		do_af_unix = 1;

	if (do_af_unix)
	{
                memset(&storage, 0, sizeof(storage));
                storage.sun_family = AF_UNIX;
                strlcpy(storage.sun_path, nodename, sizeof(storage.sun_path));
#ifdef HAVE_SA_LEN
# ifdef SUN_LEN
                storage.sun_len = SUN_LEN(&storage);
# else
                storage.sun_len = strlen(nodename) + 1;
# endif
#endif
                len = strlen(storage.sun_path) + 3;

		(*res) = new_malloc(sizeof(*results));
		(*res)->ai_flags = 0;
		(*res)->ai_family = AF_UNIX;
		(*res)->ai_socktype = SOCK_STREAM;
		(*res)->ai_protocol = 0;
		(*res)->ai_addrlen = len;
		(*res)->ai_canonname = malloc_strdup(nodename);
		(*res)->ai_addr = new_malloc(sizeof(storage));
		*(USA *)((*res)->ai_addr) = storage;
		(*res)->ai_next = 0;

                return 0;
	}
#endif

	/*
	 * XXX -- Support getaddrinfo()s that want an AF_UNIX path to
	 * be the second argument and not the first one.  Bleh.
	 */
	if ((nodename && strchr(nodename, '/')) || 
	    (hints && hints->ai_family == AF_UNIX))
		return getaddrinfo(NULL, nodename, hints, res);
	else
		return getaddrinfo(nodename, servname, hints, res);
}
Exemplo n.º 4
0
int Encrypt_Init(IrcCommandDll **intp, Function_ptr *global_table)
{
int i, j;
char buffer[BIG_BUFFER_SIZE+1];
	initialize_module("encrypt");
	
	add_module_proc(ALIAS_PROC, "encrypt", "MENCODE", NULL, 0, 0, func_encode, NULL);
	add_module_proc(ALIAS_PROC, "encrypt", "MDECODE", NULL, 0, 0, func_decode, NULL);
	encode_string = (char *)new_malloc(512);
	for (i = 1, j = 255; i <= 255; i++, j--)
	{
		switch (i)
		{
			case 27:
			case 127:
			case 255:
				encode_string[i-1] = i;
				break;
			default:
				encode_string[i-1] = j;
				break;
		}
	}
	sprintf(buffer, "$0+%s by panasync - $2 $3", encode_version);
	fset_string_var(FORMAT_VERSION_FSET, buffer);
	put_it("%s", convert_output_format("$G $0 v$1 by panasync. Based on suicide's Abot script.", "%s %s", encode_version, ENCODE_VERSION));
	return 0;
}
Exemplo n.º 5
0
Arquivo: files.c Projeto: srfrog/epic5
char *	file_readb (int fd, int numb)
{
	File *ptr = lookup_file(fd);
	if (!ptr)
		return malloc_strdup(empty_string);
	else
	{
                char *	ret;
		char *	blah;

		blah = (char *)new_malloc(numb+1);
                if (ptr->elf->fp) {
                    clearerr(ptr->elf->fp);
                    numb = fread(blah, 1, numb, ptr->elf->fp);
#ifdef HAVE_LIBARCHIVE
                } else if (ptr->elf->a) {
                    numb = archive_read_data(ptr->elf->a, blah, numb);
#endif
                } else {
                    /* others */
                }

		if ((ret = transform_string_dyn("+CTCP", blah, numb, NULL)))
			new_free(&blah);
		else
			ret = blah;
		return ret;
	}
}
Exemplo n.º 6
0
static void 	new_key (int meta, unsigned chr, int type, int change, char *stuff)
{
	/*
	 * Create a map first time we bind into it.  We have to do this
	 * Because its possible to do /bind METAX-f when there is not
	 * otherwise any key bound to METAX.
	 */
	if (!keys)
		return;
	if (!keys[meta])
		new_metamap(meta);

	if (KEY(meta, chr))
	{
		if (KEY(meta, chr)->stuff)
			new_free(&(KEY(meta, chr)->stuff));
		if (KEY(meta, chr)->filename)
			new_free(&(KEY(meta, chr)->filename));
		new_free(&(KEY(meta, chr)));
		KEY(meta, chr) = NULL;
	}

	if (type != 0)
	{
		KEY(meta, chr) = (KeyMap *)new_malloc(sizeof(KeyMap));
		KEY(meta, chr)->key_index = type;
		KEY(meta, chr)->changed = change;
/*		KEY(meta, chr)->filename = m_strdup(current_package());*/
		if (stuff)
			KEY(meta, chr)->stuff = m_strdup(stuff);
		else
			KEY(meta, chr)->stuff = NULL;
	}
}
Exemplo n.º 7
0
/*
 * history_match: using wild_match(), this finds the latest match in the
 * history file and returns it as the function result.  Returns null if there
 * is no match.  Note that this sticks a '*' at the end if one is not already
 * there. 
 */
static char *history_match(char *match)
{
    char *ptr;
    char *match_str = NULL;

    if (*(match + strlen(match) - 1) == '*')
	malloc_strcpy(&match_str, match);
    else {
	match_str = new_malloc(strlen(match) + 2);
	strcpy(match_str, match);
	strcat(match_str, "*");
    }
    if (get_int_var(HISTORY_VAR)) {
	if ((last_dir == -1) || (tmp == (History *) NULL))
	    tmp = command_history_head;
	else
	    tmp = tmp->next;
	for (; tmp; tmp = tmp->next) {
	    ptr = tmp->stuff;
	    while (ptr && strchr(get_string_var(CMDCHARS_VAR), *ptr))
		ptr++;

	    if (wild_match(match_str, ptr)) {
		new_free(&match_str);
		last_dir = PREV;
		return (tmp->stuff);
	    }
	}
    }
    last_dir = -1;
    new_free(&match_str);
    return NULL;
}
Exemplo n.º 8
0
void add_new_fset(char *name, char *args)
{
	if (args && *args)
	{
		IrcVariable *tmp = NULL;
		int cnt, loc;
		tmp = (IrcVariable *)find_array_item((Array *)&ext_fset_list, name, &cnt, &loc);
		if (!tmp || cnt >= 0)
		{
			tmp = new_malloc(sizeof(IrcVariable));
			tmp->name = m_strdup(name);
			tmp->type = STR_TYPE_VAR;
			add_to_array((Array *)&ext_fset_list, (Array_item *)tmp);
		}
		malloc_strcpy(&tmp->string, args);
	}
	else 
	{
		IrcVariable *tmp;
		if ((tmp = (IrcVariable *)remove_from_array((Array *)&ext_fset_list, name)))
		{
			new_free(&tmp->name);
			new_free(&tmp->string);
			new_free(&tmp);
		}
	}
}
Exemplo n.º 9
0
static Logfile *	new_logfile (void)
{
	Logfile *log, *ptr;
	int	i;

	log = (Logfile *)new_malloc(sizeof(Logfile));

	/* Move it to the end of the list. */
	for (ptr = logfiles; ptr && ptr->next;)
		ptr = ptr->next;
	if (ptr)
		ptr->next = log;
	else
		logfiles = log;

	log->next = NULL;
	log->refnum = ++logref;
	last_logref = log->refnum;
	log->name = malloc_sprintf(NULL, "%d", log->refnum);
	log->filename = NULL;
	log->log = NULL;
	log->servref = from_server;
	log->type = LOG_TARGETS;
	log->targets = NULL;
	for (i = 0; i < MAX_TARGETS; i++)
		log->refnums[i] = -1;
	mask_setall(&log->mask);
	log->rewrite = NULL;
	log->mangler = 0;
	log->mangle_desc = NULL;
	log->active = 0;
	time(&log->activity);

	return log;
}
Exemplo n.º 10
0
Arquivo: vars.c Projeto: srfrog/epic5
/* BIV stands for "built in variable" */
static int	add_biv (const char *name, int bucket, int type, void (*func) (void *), const char *script, ...)
{
	IrcVariable *var;
	va_list va;
	int numval;
	const char *strval;

	var = (IrcVariable *)new_malloc(sizeof(IrcVariable));
	var->type = type;
	if (script)
		var->script = malloc_strdup(script);
	else
		var->script = NULL;
	var->func = func;

	var->data = new_malloc(sizeof(union builtin_variable));
	var->flags = 0;

	va_start(va, script);
	switch (var->type) {
	    case BOOL_VAR:
	    case CHAR_VAR:
	    case INT_VAR:
		numval = va_arg(va, int);
		var->data->integer = numval;
		break;
	    case STR_VAR:
		strval = va_arg(va, char *);
		if (strval)
			var->data->string = malloc_strdup(strval);
		else
			var->data->string = NULL;
		break;
	}
	va_end(va);

	add_builtin_variable_alias(name, var);
	if (bucket)
	{
		add_to_bucket(var_bucket, name, var);
		return (var_bucket->numitems - 1);
	}
	else
		return -1;
}
Exemplo n.º 11
0
/**
 * ifaces - fetch a list of interfaces/hostnames
 * @callback: called with the list of interfaces
 * @data: app-specific data also passed to callback
 *
 * A callback function is used here because we may
 * block while looking up hostnames.
 **/
int ifaces(iface_cb callback, void *data)
{
    struct thr_comm *c = new_malloc(sizeof(struct thr_comm));

    assert(callback);

    c->thr_ifcb = callback;
    c->thr_data = data;

    return (int)THR_CREATE(ifaces_r, c);
}
Exemplo n.º 12
0
static char *	decipher_evp (const unsigned char *key, int keylen, const unsigned char *ciphertext, int cipherlen, const EVP_CIPHER *type, int *outlen, int ivsize)
{
        unsigned char *outbuf;
	unsigned char	*iv = NULL;
	unsigned long errcode;
	int	outlen2;
        EVP_CIPHER_CTX a;
        EVP_CIPHER_CTX_init(&a);
	EVP_CIPHER_CTX_set_padding(&a, 0);

	if (ivsize > 0)
		iv = new_malloc(ivsize);
	outbuf = new_malloc(cipherlen + 1024);
	if (ivsize > 0)
		memcpy(iv, ciphertext, ivsize);

        EVP_DecryptInit_ex(&a, type, NULL, NULL, iv);
	EVP_CIPHER_CTX_set_key_length(&a, keylen);
	EVP_CIPHER_CTX_set_padding(&a, 0);
        EVP_DecryptInit_ex(&a, NULL, NULL, key, NULL);

        if (EVP_DecryptUpdate(&a, outbuf, outlen, ciphertext, cipherlen) != 1)
		yell("EVP_DecryptUpdate died.");
	if (EVP_DecryptFinal_ex(&a, outbuf + (*outlen), &outlen2) != 1)
		yell("EVP_DecryptFinal_Ex died.");
	*outlen += outlen2;

        EVP_CIPHER_CTX_cleanup(&a);

	ERR_load_crypto_strings();
	while ((errcode = ERR_get_error()))
	{
	    char r[256];
	    ERR_error_string_n(errcode, r, 256);
	    yell("ERROR: %s", r);
	}

	if (ivsize > 0)
		new_free(&iv);
	return outbuf;
}
Exemplo n.º 13
0
Arquivo: files.c Projeto: srfrog/epic5
static char *	Datum_to_string (Datum d)
{
	char *retval;

	if (d.dptr == NULL)
		return NULL;

	retval = new_malloc(d.dsize + 1);
	memcpy(retval, d.dptr, d.dsize);
	retval[d.dsize] = 0;
	return retval;			/* MALLOCED, EH! */
}
Exemplo n.º 14
0
/*
 * new_metamap -- When you "touch" a metamap for the first time,
 * the table for the 256 bindings in that metamap must be created, so
 * you call this function to do that.  You must never call this function
 * unless the metamap does not exist, or it will panic.
 */
static void 	new_metamap (int which)
{
	int j;

	if (keys[which])
		ircpanic("metamap already exists");

	keys[which] = new_malloc(sizeof(MetaMap));

	for (j = 0; j <= 255; j++)
		KEY(which, j) = NULL;
}
Exemplo n.º 15
0
static void
input_do_delete_raw(int n, int do_save_cut)
{
	ScreenInputData *inputdata = screen_get_inputdata(get_current_screen());
	u_char* buf  = inputdata->buffer.buf;
	unsigned pos = inputdata->buffer.pos;
	unsigned max = sizeof(inputdata->buffer.buf);

	/* If n>0, deletes from front
	 * if n<0, deletes from back & moves cursor
	 */
	if (n < 0)
	{
		unsigned limit = inputdata->buffer.minpos;
		/* Number of bytes LEFT from the cursor (prompt excluding) */
		unsigned oldbytes = pos-limit;
		unsigned erasebytes = -n;

		/* Don't delete more than we can */
		if (erasebytes > oldbytes)
			erasebytes = oldbytes;

		/* Move cursor backward */
		pos -= erasebytes;
		input_do_set_cursor_pos(pos);

		/* Then delete from forward */
		n = erasebytes;
	}
	if (n > 0)
	{
		unsigned oldbytes = max-pos;
		unsigned erasebytes = n > oldbytes ? oldbytes : n;
		unsigned newbytes = oldbytes - erasebytes;
		
		if (do_save_cut)
		{
			if (cut_buffer)
				new_free(&cut_buffer);
			cut_buffer = new_malloc(erasebytes+1);
			memcpy(cut_buffer, buf+pos, erasebytes);
			cut_buffer[erasebytes] = '\0';
		}
		
		memmove(buf+pos,
		        buf+pos+erasebytes,
		        newbytes);
		buf[pos+newbytes] = '\0';
	}
	/* Now update the right side from cursor */
	update_input(UPDATE_FROM_CURSOR);
}
Exemplo n.º 16
0
void add_to_a_list(char *thestring, int thetype, char *nick, char *channels, char *reason, int shitlevel)
{
	ShitList *sremove = NULL;
	int scount = 0;
	switch(thetype)
	{
		case SHITLIST_ADD:
		{
			if (!(sremove = nickinshit(nick, thestring)))
			{
				shit_count++;
				sremove = (ShitList *) new_malloc(sizeof(ShitList));
				sremove->level = shitlevel;
				sremove->reason = m_strdup(reason);
				sremove->channels = m_strdup(channels);
				sremove->filter = m_sprintf("%s!%s", nick, thestring);
				add_to_list((List **)&shitlist_list, (List *)sremove);
				sync_whowas_addshit(sremove);
				sync_shitlist(sremove, 1);
				if (shitlevel == PERM_IGNORE)
					ignore_nickname(sremove->filter, IGNORE_ALL, 0);
				bitchsay("Adding %s!%s to Shitlist", nick, thestring);
			}
			else
				bitchsay ("%s!%s already on my Shitlist", nick, thestring);
			break;
		}
		case SHITLIST_REMOVE:
		{
			char *s_str;
			s_str = m_sprintf("%s!%s", nick, thestring);
			while ((sremove = (ShitList *)removewild_from_list((List **)&shitlist_list, s_str)))
			{
				shit_count--;
				scount++;
				if (sremove->level == PERM_IGNORE)
					ignore_nickname(sremove->filter, IGNORE_ALL, IGNORE_REMOVE); 
				sync_whowas_unshit(sremove);
				sync_shitlist(sremove, 0);
				new_free(&sremove->filter);
				new_free(&sremove->reason);
				new_free(&sremove->channels);
				new_free((char **)&sremove);
				bitchsay("Deleting %s!%s from Shitlist", nick, thestring);
			}
			if (!scount)
				bitchsay("Didnt find %s!%s on the Shitlist", nick, thestring);
			new_free(&s_str);
			break;
		}
	}	
}
Exemplo n.º 17
0
char *deserString(const unsigned char **data, long *pCurrBlobSize)
{
    char *  str;
    int     strLen;

    strLen = deserInt( data, pCurrBlobSize );
    Assert( 0 == (*data)[strLen-1] );
    str = (char*)new_malloc( strLen );
    if (NULL==str)
        return NULL;
    deserData( (unsigned char*)str, strLen, data, pCurrBlobSize );
    return str;
}
Exemplo n.º 18
0
static	void	init_io (void)
{
	static	int	first = 1;

	if (first)
	{
		int	c, max_fd = IO_ARRAYLEN;

		io_rec = (MyIO **)new_malloc(sizeof(MyIO *) * max_fd);
		for (c = 0; c < max_fd; c++)
			io_rec[c] = (MyIO *) 0;
		first = 0;
	}
}
Exemplo n.º 19
0
static void	ext256_key (const char *orig, size_t orig_len, char **key, size_t *keylen)
{
	size_t	len;

	if (orig_len < 32)
		len = orig_len;
	else
		len = 32;

	*key = new_malloc(32);
	memset(*key, 0, 32);
	memcpy(*key, orig, len);
	*keylen = 32;
}
Exemplo n.º 20
0
int	add_new_level_alias (int level, const char *name)
{
	const char *name_copy;
	int *	levelnum;
	int	i;

	if ((i = str_to_level(name)) != -1)
		return i;

	name_copy = malloc_strdup(name);
	levelnum = new_malloc(sizeof(int));
	*levelnum = level;
	add_to_bucket(level_bucket, name_copy, levelnum);
	return *levelnum;
}
Exemplo n.º 21
0
/*
 * Given a CTCP SED argument 'str', it attempts to unscramble the text
 * into something more sane.  If the 'key' is not the one used to scramble
 * the text, the results are unpredictable.  This is probably the point.
 *
 * Note that the retval MUST be at least 'BIG_BUFFER_SIZE + 1'.  This is
 * not an oversight -- the retval is passed is to do_ctcp() which requires
 * a big buffer to scratch around (The decrypted text could be a CTCP UTC
 * which could expand to a larger string of text.)
 */
char 	*decrypt_msg (char *str, Crypt *key)
{
    char	*buffer = (char *)new_malloc(BIG_BUFFER_SIZE + 1);
    char	*ptr;

    if ((ptr = do_crypt(str, key, 0)) != NULL)
    {
        strlcpy(buffer, ptr, CRYPT_BUFFER_SIZE + 1);
        new_free(&ptr);
    }
    else
        strlcat(buffer, str, CRYPT_BUFFER_SIZE + 1);

    return buffer;
}
Exemplo n.º 22
0
Flooding *BX_add_name_to_floodlist(char *name, char *host, char *channel, HashEntry *list, unsigned int size)
{
	Flooding *nptr;
	unsigned long hvalue = hash_nickname(name, size);
	nptr = (Flooding *)new_malloc(sizeof(Flooding));
	nptr->next = (Flooding *) list[hvalue].list;
	nptr->name = m_strdup(name);
	nptr->host = m_strdup(host);
	list[hvalue].list = (void *) nptr;
	/* quick tally of nicks in chain in this array spot */
	list[hvalue].links++;
	/* keep stats on hits to this array spot */
	list[hvalue].hits++;
	return nptr;
}
Exemplo n.º 23
0
void add_userhost_to_userlist(char *nick, char *uhost, char *channels, char *passwd, unsigned int flags) 
{
UserList *uptr;
	uptr = new_malloc(sizeof(UserList));
	uptr->nick = m_strdup(nick);
	uptr->host = m_strdup(uhost); 
	uptr->channels = m_strdup(channels);
	if (passwd)
		malloc_strcpy(&uptr->password, passwd);
	uptr->flags = flags;
	uptr->time = now;
	add_userlist(uptr);
	sync_nicklist(uptr, 1);
	user_count++;
}
Exemplo n.º 24
0
void BX_add_name_to_genericlist(char *name, HashEntry *list, unsigned int size)
{
	List *nptr;
	unsigned long hvalue = hash_nickname(name, size);

	nptr = (List *) new_malloc(sizeof(List));
	nptr->next = (List *) list[hvalue].list;
	nptr->name = m_strdup(name);

	/* assign our new linked list into array spot */
	list[hvalue].list = (void *) nptr;
	/* quick tally of nicks in chain in this array spot */
	list[hvalue].links++;
	/* keep stats on hits to this array spot */
	list[hvalue].hits++;
}
Exemplo n.º 25
0
void *epNew(AbstractFile* file)
{
    EngPolInfo *epi = NULL;
    FirstRecord *first_rec;

/*       StrCopy(polishChars, "±êæ³ñ󶼿" ); */
/*       StrCopy(latinChars, "aeclnószz" ); */

    epi = (EngPolInfo *) new_malloc_zero(sizeof(EngPolInfo));
    if (NULL == epi)
        return NULL;
        
    epi->file=file;
    ebufInit(&epi->buffer, 0);      

    if (!pcInit(file, &epi->packContext, 4))
        goto Error;

    epi->recordsCount = fsGetRecordsCount(file);
    first_rec = (FirstRecord *) fsLockRecord(file, 0);
    if (NULL == first_rec)
        goto Error;

    epi->wordsCount = first_rec->wordsCount;
    epi->defLenRecordsCount = first_rec->defLenRecordsCount;
    epi->wordRecordsCount = first_rec->wordRecordsCount;
    epi->defRecordsCount = first_rec->defRecordsCount;
    epi->maxWordLen = first_rec->maxWordLen;
    epi->maxDefLen = first_rec->maxDefLen;
    epi->maxComprDefLen = first_rec->maxComprDefLen;

    epi->curDefData = (unsigned char *) new_malloc(epi->maxDefLen + 2);
    if (NULL == epi->curDefData)
        goto Error;

    epi->wci = wcInit(file, epi->wordsCount, 3, 2, 6,  epi->wordRecordsCount, epi->maxWordLen);
    if (NULL == epi->wci)
        goto Error;

  Exit:
    fsUnlockRecord(file, 0);
    return epi;
  Error:
    epDelete(epi);
    epi = NULL;
    goto Exit;
}
Exemplo n.º 26
0
Arquivo: send.c Projeto: jnbek/TekNap
GetFile *create_send(char *nick, FileStruct *fs)
{
GetFile *gf;
	if (!nick)
		return NULL;
	gf = new_malloc(sizeof(GetFile));
	gf->nick = m_strdup(nick);
	gf->checksum = m_strdup(fs->checksum);
	gf->filename = m_strdup(fs->filename);
	gf->write = -1;
	gf->socket = -1;
	gf->deleted = 0;
	gf->filesize = fs->filesize;
	gf->flags = NAP_UPLOAD;
	gf->addtime = now;
	return gf;
}
Exemplo n.º 27
0
char *ircop_flags_to_str(long flag)
{
int p, i;
char *buffer = new_malloc(BIG_BUFFER_SIZE+1);

	for (i = 0, p = 1; opflags[i]; i++, p <<= 1)
	{
		if (flag & p)
		{
			strmcat(buffer, opflags[i], BIG_BUFFER_SIZE);
			strmcat(buffer, ",", BIG_BUFFER_SIZE);
		}
	}
	if (*buffer)
		chop(buffer, 1);
	return buffer;
}
Exemplo n.º 28
0
/* Makes a malloced duplicate of the hostent returned. */
my_hostent *duphostent(struct hostent *orig)
{
	my_hostent *tmp = new_malloc(sizeof(my_hostent));
    int z;

	tmp->h_name = m_strdup(orig->h_name);
	tmp->h_length = orig->h_length;
	tmp->h_addrtype = orig->h_addrtype;

	for(z=0;z<MAXALIASES && orig->h_aliases[z];z++)
		tmp->h_aliases[z] = m_strdup(orig->h_aliases[z]);

    for(z=0;z<MAXADDRS && orig->h_addr_list[z];z++)
		memcpy(&tmp->h_addr_list[z], orig->h_addr_list[z], sizeof(*orig->h_addr_list));

    return (my_hostent *)tmp;
}
Exemplo n.º 29
0
static void	copy_key (const char *orig, size_t orig_len, char **key, size_t *keylen)
{
#if 0
	size_t	key_len;
	orig_len = strlen(orig);		/* XXX for now */

	if ((key_len = orig_len) < 9)
		key_len = 9;

	*key = new_malloc(key_len);
	memset(*key, 0, key_len);
	strlcpy(*key, orig, key_len);
#else
	*key = malloc_strdup(orig);
#endif
	*keylen = orig_len;
}
Exemplo n.º 30
0
struct epic_loadfile * epic_fopen(char *filename, const char *mode, int do_error)
{
    FILE * doh;
    int    ret;

    struct epic_loadfile *elf;

    elf = (struct epic_loadfile *) new_malloc(sizeof(struct epic_loadfile));

    elf->fp = NULL;
#ifdef HAVE_LIBARCHIVE
    elf->a = NULL;
    elf->entry = NULL;
#endif
    elf->eof = 0;

#ifdef HAVE_LIBARCHIVE
    if (stristr(filename, ".zip")!=-1) {
        ret=archive_fopen(elf, filename, ".zip", do_error);
    } else if (stristr(filename, ".tar")!=-1) {
        ret=archive_fopen(elf, filename, ".tar", do_error);
    }
    else
#endif
	ret = 0;

    if (ret==1)
        return elf;

    if (ret!=-1) { /* archive didnt have loadable data */

        /* Its not a compressed file... Try to open it regular-like. */
        if ((doh = fopen(filename, mode))) {
            elf->fp = doh;
            return elf;
        }
        if (do_error)
            yell("Cannot open file %s: %s", filename, strerror(errno));
    }
    new_free(&elf);

    return NULL;
}