Example #1
0
static void parse_server(struct a_network *net, const char *spec)
{
	char hostspec[1024];
	char *portspec;

	/* snag the hostname */
	snprintf(hostspec, 1024, "%s", spec);

	portspec = strchr(hostspec, '/');
	if (portspec != NULL)
		*portspec = '\0';

	net->host = mowgli_strdup(hostspec);

	/* snag the port */
	portspec = strchr(spec, '/');

	if (portspec == NULL)
		portspec = "/6667";
	portspec++;

	net->use_ssl = false;
	if (portspec[0] == '+') {
		net->use_ssl = true;
		portspec++;
	}

	net->port = atoi(portspec);
	if (net->port < 1 || net->port > 65535) {
		a_log(LERROR, "Invalid port number %d, defaulting to 6667", net->port);
		net->port = 6667;
	}
}
Example #2
0
/*
 * mowgli_object_init
 *
 * Populates the object manager part of an object.
 *
 * Inputs:
 *      - pointer to object manager area
 *      - (optional) name of object
 *      - (optional) class of object
 *      - (optional) custom destructor
 *
 * Outputs:
 *      - none
 *
 * Side Effects:
 *      - none
 */
void
mowgli_object_init(mowgli_object_t *obj, const char *name, mowgli_object_class_t *klass, mowgli_destructor_t des)
{
	return_if_fail(obj != NULL);

	if (name != NULL)
		obj->name = mowgli_strdup(name);

	if (klass != NULL)
	{
		obj->klass = klass;
	}
	else
	{
		mowgli_object_class_t *tmp = mowgli_alloc(sizeof *tmp);
		mowgli_object_class_init(tmp, name, des, TRUE);
		obj->klass = tmp;
	}

	obj->refcount = 1;

	obj->message_handlers.head = NULL;
	obj->message_handlers.tail = NULL;
	obj->message_handlers.count = 0;

	obj->metadata.head = NULL;
	obj->metadata.tail = NULL;
	obj->metadata.count = 0;

	mowgli_object_message_broadcast(obj, "create");
}
Example #3
0
void
mowgli_program_opts_consumer_str(const char *arg, void *userdata)
{
	return_if_fail(arg != NULL);
	return_if_fail(userdata != NULL);

	*(char **) userdata = mowgli_strdup(arg);
}
Example #4
0
File: sigyn.c Project: alyx/sigyn
void parse_commandline_options(int argc, char **argv)
{
    int r;

    mowgli_getopt_option_t long_opts[] = {
      { NULL, 0, NULL, 0, 0 },
    };

    while ((r = mowgli_getopt_long(argc, argv, "c:hvnd:", long_opts, NULL)) != -1)
    {
        switch (r)
        {
	        case 'h':
                printf("usage: sigyn [-hv] [-c config]\n\n"
                " -c <path>   Specify a configuration file for sigyn to use\n"
                " -h          Print this message and exit\n"
                " -d <level>  Run in foreground and print debug (1=all, 2=debug)\n"
                " -v          Print the version information and exit\n"
                " -n          Prevents Sigyn from forking into the background\n");
                exit(EXIT_SUCCESS);
                break;
            case 'v':
                printf("%s by Alyx Wolcott.\n", PACKAGE_STRING);
                exit(EXIT_SUCCESS);
                break;
            case 'c':
                config_file = mowgli_strdup(mowgli_optarg);
                break;
            case 'd':
                me.debug = atoi(mowgli_optarg);
                break;
            case 'n':
                should_fork = false;
                break;
            default:
                printf("\nusage: sigyn [-hv] [-d debug level] [-c config]\n");
                exit(EXIT_SUCCESS);
                break;
        }
    }
    if (config_file == NULL)
        config_file = mowgli_strdup(SYSCONFDIR "/sigyn.conf");
}
Example #5
0
static void netdata_chan_add(struct a_network *net, const char *name)
{
	struct a_net_chan *chan;

	if (!net || !name || mowgli_patricia_retrieve(net->nd.chans, name))
		return;

	chan = mowgli_alloc(sizeof(*chan));
	chan->name = mowgli_strdup(name);
	chan->topic = mowgli_string_create();
	chan->users = create_users_patricia(net);

	mowgli_patricia_add(net->nd.chans, name, chan);
}
Example #6
0
static struct a_network *net_create(const char *name)
{
	struct a_network *net;

	net = mowgli_alloc(sizeof(*net));
	if (net == NULL)
		return NULL;
	memset(net, 0, sizeof(*net));

	net->name = mowgli_strdup(name);
	net->acct = NULL;

	net->host = NULL;
	net->port = 0;
	net->use_ssl = false;

	/* defaults */
	net->nick = mowgli_strdup(DEFAULT_NICK);
	net->ident = mowgli_strdup(DEFAULT_IDENT);
	net->gecos = mowgli_strdup(DEFAULT_GECOS);

	net->nd.flags = 0;
	net->nd.flags |= NET_MOTD_EMPTY | NET_MOTD_LOCK;
	net->nd.nick = mowgli_strdup(DEFAULT_NICK);
	net->nd.ident = mowgli_strdup(DEFAULT_IDENT);
	net->nd.host = mowgli_strdup("");
	net->nd.gecos = mowgli_strdup(DEFAULT_GECOS);
	net->nd.isupport = irc_isupport_create();
	net->nd.motd = mowgli_string_create();
	net->nd.chans = mowgli_patricia_create(NULL); /* TODO: casemap */
	net->nd.users = mowgli_patricia_create(NULL); /* TODO: casemap */

	net->state = NET_DISCONNECTED;
	net->linebuf = NULL;
	net->clients = mowgli_list_create();

	return net;
}
Example #7
0
static void
read_data(mowgli_eventloop_t *eventloop, mowgli_eventloop_io_t *io, mowgli_eventloop_io_dir_t dir, void *userdata)
{
	mowgli_eventloop_pollable_t *pollable = mowgli_eventloop_io_pollable(io);
	mowgli_dns_t *dns = userdata;
	char buf[2048];
	char *ch;
	int ret;

	return_if_fail(pollable->fd == STDIN_FILENO);

	if ((ret = read(pollable->fd, buf, sizeof(buf))) < 0)
	{
		perror("read");
		mowgli_pollable_destroy(eventloop, io);
		return;
	}
	else if (ret == 0)
	{
		return;
	}

	buf[--ret] = '\0';

	ch = strtok(buf, " ");

	while (ch != NULL)
	{
		dns_query *dnsquery = mowgli_alloc(sizeof(dns_query));
		mowgli_dns_query_t *query = &dnsquery->query;

		printf("Domain input: %s\n", ch);
		printf("End domain input\n");

		query->callback = resolve_cb;
		query->ptr = dnsquery;
		dnsquery->domain = mowgli_strdup(ch);

		if (*ch == '+')
		{
			int type;
			void *addrptr;
			struct sockaddr_storage addr;

			if (strchr(++ch, ':') != NULL)
			{
				struct sockaddr_in6 *saddr = (struct sockaddr_in6 *) &addr;
				type = AF_INET6;
				addrptr = &saddr->sin6_addr;
			}
			else
			{
				struct sockaddr_in *saddr = (struct sockaddr_in *) &addr;
				type = AF_INET;
				addrptr = &saddr->sin_addr;
			}

			addr.ss_family = type;

			if ((ret = inet_pton(type, ch, addrptr)) != 1)
			{
				if (ret == -1)
					perror("inet_pton");
				else
					printf("Invalid address %s\n", ch);

				return;
			}

			mowgli_dns_gethost_byaddr(dns, &addr, query);
		}
		else
		{
			mowgli_dns_gethost_byname(dns, ch, query, MOWGLI_DNS_T_A);
		}

		dnsquery->domain = mowgli_strdup(ch);
		ch = strtok(NULL, " ");
	}
}
Example #8
0
static mowgli_config_file_t *mowgli_config_file_parse(const char *filename, char *confdata)
{
	mowgli_config_file_t *cf, *subcf, *lastcf;
	mowgli_config_file_entry_t **pprevce, *ce, *upce;
	char *p, *val;
	char c;

	cf = mowgli_alloc(sizeof *cf);
	cf->filename = mowgli_strdup(filename);
	cf->curline = 1;
	cf->mem = confdata;
	lastcf = cf;
	pprevce = &cf->entries;
	upce = NULL;
	p = confdata;
	while (*p != '\0')
	{
		skip_ws(&p, cf);
		if (*p == '\0' || CF_ERRORED(cf))
			break;
		if (*p == '}')
		{
			if (upce == NULL)
			{
				mowgli_config_file_error(cf, "Extraneous closing brace");
				break;
			}
			ce = upce;
			ce->sectlinenum = cf->curline;
			pprevce = &ce->next;
			upce = ce->prevlevel;
			p++;
			skip_ws(&p, cf);
			if (CF_ERRORED(cf))
				break;
			if (*p != ';')
			{
				mowgli_config_file_error(cf, "Missing semicolon after closing brace for section ending at line %d", ce->sectlinenum);
				break;
			}
			ce = NULL;
			p++;
			continue;
		}
		val = get_value(&p, cf, &c);
		if (CF_ERRORED(cf))
			break;
		if (val == NULL)
		{
			mowgli_config_file_error(cf, "Unexpected character trying to read variable name");
			break;
		}
		ce = mowgli_alloc(sizeof *ce);
		ce->fileptr = cf;
		ce->varlinenum = cf->curline;
		ce->varname = val;
		ce->prevlevel = upce;
		*pprevce = ce;
		pprevce = &ce->next;
		if (c == '\0' && (*p == '{' || *p == ';'))
			c = *p++;
		if (c == '{')
		{
			pprevce = &ce->entries;
			upce = ce;
			ce = NULL;
		}
		else if (c == ';')
		{
			ce = NULL;
		}
		else if (c != '\0')
		{
			mowgli_config_file_error(cf, "Unexpected characters after unquoted string %s", ce->varname);
			break;
		}
		else
		{
			val = get_value(&p, cf, &c);
			if (CF_ERRORED(cf))
				break;
			if (val == NULL)
			{
				mowgli_config_file_error(cf, "Unexpected character trying to read value for %s", ce->varname);
				break;
			}
			ce->vardata = val;
			if (c == '\0' && (*p == '{' || *p == ';'))
				c = *p++;
			if (c == '{')
			{
				pprevce = &ce->entries;
				upce = ce;
				ce = NULL;
			}
			else if (c == ';')
			{
				if (upce == NULL && !strcasecmp(ce->varname, "include"))
				{
					subcf = mowgli_config_file_load_internal(cf, ce->vardata);
					if (subcf == NULL)
					{
						mowgli_config_file_error(cf, "Error in file included from here");
						break;
					}
					lastcf->next = subcf;
					while (lastcf->next != NULL)
						lastcf = lastcf->next;
				}
				ce = NULL;
			}
			else
			{
				mowgli_config_file_error(cf, "Unexpected characters after value %s %s", ce->varname, ce->vardata);
				break;
			}
		}
	}
	if (!CF_ERRORED(cf) && upce != NULL)
	{
		mowgli_config_file_error(cf, "One or more sections not closed");
		ce = upce;
		while (ce->prevlevel != NULL)
			ce = ce->prevlevel;
		if (ce->vardata != NULL)
			mowgli_config_file_error(cf, "First unclosed section is %s %s at line %d",
					ce->varname, ce->vardata, ce->varlinenum);
		else
			mowgli_config_file_error(cf, "First unclosed section is %s at line %d",
					ce->varname, ce->varlinenum);
	}
	if (CF_ERRORED(cf))
	{
		mowgli_config_file_free(cf);
		cf = NULL;
	}
	return cf;
}
Example #9
0
static void mowgli_strput(char **p, const char *s)
{
	if (*p)
		mowgli_free(*p);
	*p = mowgli_strdup(s);
}