Example #1
0
/* 
 * AICCU! - Aka... let's get connected ;)
 * returns a TIC_Tunnel which can then be
 * used for configuring and keeping it running
 */
struct TIC_Tunnel *get_tunnel(void)
{
	
	struct TIC_sTunnel	*hsTunnel, *t;
	struct TIC_Tunnel	*hTunnel;

	/* Login to the TIC Server */
	if (!tic_Login(g_aiccu->tic, g_aiccu->username, g_aiccu->password, g_aiccu->server)) return NULL;

	/* 
	 * Don't try to list the tunnels when
	 * we already have a tunnel_id configured
	 */
	if (!g_aiccu->tunnel_id)
	{	
		hsTunnel = tic_ListTunnels(g_aiccu->tic);
		if (!hsTunnel)
		{
			dolog(LOG_ERR, "No tunnel available, request one first\n");
			tic_Free_sTunnel(hsTunnel);
			tic_Logout(g_aiccu->tic, "I didn't have any tunnels to select");
			return NULL;
		}
	
		if (hsTunnel->next)
		{
			dolog(LOG_ERR, "Multiple tunnels available, please pick one from the following list and configure the aiccu.conf using it\n");
			for (t = hsTunnel; t; t = t->next)
			{
				dolog(LOG_ERR, "%s %s %s %s\n", t->sId, t->sIPv6, t->sIPv4, t->sPOPId);
			}
			tic_Free_sTunnel(hsTunnel);
			tic_Logout(g_aiccu->tic, "User still needed to select a tunnel");
			return NULL;
		}
		g_aiccu->tunnel_id = strdup(hsTunnel->sId);

		/* Free the info */
		tic_Free_sTunnel(hsTunnel);
	}

	/* Get Tunnel Information */
	hTunnel = tic_GetTunnel(g_aiccu->tic, g_aiccu->tunnel_id);
	if (!hTunnel)
	{
		tic_Logout(g_aiccu->tic, "No such tunnel");
		return NULL;
	}

	/* Logout, TIC is not needed any more */
	tic_Logout(g_aiccu->tic, NULL);

	/* Swee.... sufficient information */
	return hTunnel;
}
Example #2
0
int list_tunnels(void)
{
	struct TIC_sTunnel *hsTunnel, *t;

	if (!tic_Login(g_aiccu->tic, g_aiccu->username, g_aiccu->password, g_aiccu->server)) return 0;

	hsTunnel = tic_ListTunnels(g_aiccu->tic);

	if (!hsTunnel)
	{
		tic_Logout(g_aiccu->tic, "Getting current tunnel listing");
		return 1;
	}

	for (t = hsTunnel; t; t = t->next)
	{
		printf("%s %s %s %s\n", t->sId, t->sIPv6, t->sIPv4, t->sPOPId);
	}

	tic_Free_sTunnel(hsTunnel);
	tic_Logout(g_aiccu->tic, "Getting current tunnel listing");
	return 1;
}
Example #3
0
File: tic.c Project: twikz/maiccu
struct TIC_sTunnel *tic_ListTunnels(struct TIC_conf *tic)
{
	char			buf[1024], buf2[1024];
	struct TIC_sTunnel	*start = NULL, *last = NULL, *tun = NULL;
	int			i;

/* Request a list of Tunnels */
	sock_printf(tic->sock, "tunnel list\n");

	/* Fetch the answer */
	if (sock_getline(tic->sock, tic_buf, sizeof(tic_buf), &tic_filled, buf, sizeof(buf)) == -1)
	{
		return NULL;
	}

	/* 201 (start of list) ? */
	if (buf[0] != '2' || buf[1] != '0' || buf[2] != '1')
	{
		dolog(LOG_ERR, "Couldn't list tunnels: %s.\n", &buf[4]);
		return NULL;
	}

	/* Process all the lines */
	while (sock_getline(tic->sock, tic_buf, sizeof(tic_buf), &tic_filled, buf, sizeof(buf)) != -1)
	{
		/* 202 (end of list) ? */
		if (buf[0] == '2' && buf[1] == '0' && buf[2] == '2') break;
		
		i = countfields(buf);
		if (i != 4)
		{
			dolog(LOG_ERR, "Wrong field format when listing tunnels\n");
			break;
		}

		/* Allocate a new struct */
		tun = (struct TIC_sTunnel *)malloc(sizeof(*tun));
		if (!tun)
		{
			dolog(LOG_ERR, "Memory problem while listing tunnels\n");
			break;
		}
		memset(tun, 0, sizeof(*tun));

		/* Copy the fields into the struct */
		if (!copyfield(buf, 1, buf2, sizeof(buf2))) break;
		tun->sId = strdup(buf2);
		if (!copyfield(buf, 2, buf2, sizeof(buf2))) break;
		tun->sIPv6 = strdup(buf2);
		if (!copyfield(buf, 3, buf2, sizeof(buf2))) break;
		tun->sIPv4 = strdup(buf2);
		if (!copyfield(buf, 4, buf2, sizeof(buf2))) break;
		tun->sPOPId = strdup(buf2);
		
		/* Add it into the list */
		if (last)
		{
			last->next = tun;
			last = tun;
		}
		else
		{
			start = last = tun;
		}
	}

	/* All went okay? */
	if (buf[0] == '2' && buf[1] == '0' && buf[2] == '2')
	{
		return start;
	}

	/* Free the structure, it was broken anyway */
	tic_Free_sTunnel(start);

	dolog(LOG_ERR, "Tunnel list went wrong: %s\n", &buf[4]);
	return NULL;
}