Ejemplo n.º 1
0
void net_login(char *email, char *password)
{
	uemail = g_strdup(email);
	upass = g_strdup(password);
	mwin_create();
	
	GInetAddr* addr;
	addr = gnet_inetaddr_new("messenger.hotmail.com", 1863);
	if(addr)
	{
		msn_socket = gnet_tcp_socket_new(addr);
		gnet_inetaddr_delete(addr);
	}
	else
	{
		error_dialog("Failed to resolve messenger.msn.com");
		return;
	}
	
	msn_channel = gnet_tcp_socket_get_io_channel(msn_socket);
	g_io_channel_set_buffer_size(msn_channel,128);
	g_io_channel_set_buffered(msn_channel,1);
	g_io_channel_set_encoding(msn_channel, NULL, NULL);
	g_io_add_watch(msn_channel,G_IO_IN|G_IO_HUP|G_IO_ERR,(GIOFunc)network_receive,NULL);
	
	/* Start off the authentication process */
	net_send("VER 0 MSNP8 MYPROTOCOL CVR0 \r\n");
}
Ejemplo n.º 2
0
GNetXmlRpcClient *gnet_xmlrpc_client_new(const gchar *hostname,
                                         int port)
{
  GNetXmlRpcClientPrivate *client = g_new0(GNetXmlRpcClientPrivate, 1);
  GInetAddr* addr;

  addr = gnet_inetaddr_new (hostname, port);
  if (!addr)
    {
      fprintf (stderr, "Error: Name lookup for %s failed\n", hostname);
      return NULL;
    }

  /* Create the socket */
  client->socket = gnet_tcp_socket_new (addr);
  gnet_inetaddr_delete (addr);
  if (!client->socket)
    {
      fprintf (stderr, "Error: Could not connect to %s:%d\n", hostname, port);
      return NULL;
    }
  
  client->client.gnet_channel = gnet_tcp_socket_get_io_channel (client->socket);
  g_assert (client->client.gnet_channel != NULL);

  client->xmlrpc_string = g_string_new("");
  client->in_header = TRUE;
  client->header_lineno = 0;
  client->message_size = 0;
  client->error = 0;

  return (GNetXmlRpcClient*)client;
}
Ejemplo n.º 3
0
static void discovery_client_dispose(GObject *gobject)
{
    DiscoveryClient *self = DISCOVERY_CLIENT(gobject);

    if (self->broadcast_timer) {
        g_source_remove(self->broadcast_timer);
        self->broadcast_timer = 0;
    }
    if (self->socket_reader) {
        g_source_remove(self->socket_reader);
        self->socket_reader = 0;
    }
    if (self->socket) {
        gnet_udp_socket_delete(self->socket);
        self->socket = NULL;
    }
    if (self->service_name) {
        g_free(self->service_name);
        self->service_name = NULL;
    }
    if (self->buffer) {
        g_free(self->buffer);
        self->buffer = NULL;
    }
    if (self->broadcast) {
        gnet_inetaddr_delete(self->broadcast);
        self->broadcast = NULL;
    }
}
Ejemplo n.º 4
0
void
handle_client(GTcpSocket *client) {
  RequestHeader *request_header;
  GIOChannel *ioclient;
  GInetAddr *addr;
  GIOError error;
  GPtrArray *request_query;

  gchar* name;
  gint port;

  gchar read_buffer[1024];
  gchar write_buffer[1024];

  gsize read_buffer_n;
  gsize write_buffer_n;

  
  ioclient = gnet_tcp_socket_get_io_channel(client);
  g_assert (ioclient);

  addr = gnet_tcp_socket_get_remote_inetaddr(client);
  g_assert (addr);
  name = gnet_inetaddr_get_canonical_name (addr);
  g_assert (name);
  port = gnet_inetaddr_get_port (addr);
  g_print ("Accepted connection from %s:%d\n", name, port);
  g_free(name);
  
  request_query = g_ptr_array_new();

  while ((error = gnet_io_channel_readline(ioclient, 
                                            read_buffer, 
                                            sizeof(read_buffer), 
                                            &read_buffer_n)) == G_IO_ERROR_NONE && (read_buffer_n > 0))
  {
    if(g_strcmp0(read_buffer, BLANK_LINE) == 0) {
      break;
    }else {
      g_ptr_array_add(request_query, g_strdup(read_buffer));
    }
  }

  request_header = voy_request_header_initialize();
  voy_request_header_create(request_query, request_header);
  voy_request_header_print(request_header);
   
  g_stpcpy(write_buffer, "HTTP/1.0 200 OK\r\nContent-type: text/html; charset=utf-8\r\n\r\n<h1>Hello from server!</h1>");
  write_buffer_n = strlen(write_buffer);
  gnet_io_channel_writen(ioclient, write_buffer, write_buffer_n, &write_buffer_n);
  g_ptr_array_free(request_query, TRUE);
  gnet_inetaddr_delete (addr);
  voy_request_header_free(request_header);
}
Ejemplo n.º 5
0
ntl_Net* ntl_net_new(void)
{
    ntl_Net* rv = g_new(ntl_Net, 1);
    gnet_init();
    {
        GInetAddr* a = gnet_inetaddr_new("localhost", 4242);
        rv->sock = gnet_tcp_socket_new(a);
        gnet_inetaddr_delete(a);
    }
    
    return rv;
}
Ejemplo n.º 6
0
Archivo: socks.c Proyecto: GNOME/gnet
/**
 *  gnet_socks_set_server:
 *  @inetaddr: SOCKS server address
 *
 *  Sets the address of the SOCKS server.
 *
 **/
void
gnet_socks_set_server (const GInetAddr* inetaddr)
{
  g_return_if_fail (inetaddr);

  G_LOCK (socks);

  if (socks_server)
    gnet_inetaddr_delete (socks_server);
  socks_server = gnet_inetaddr_clone (inetaddr);

  G_UNLOCK (socks);
}
Ejemplo n.º 7
0
GTcpSocket*
initialize_server(gint server_port) {
  GTcpSocket *server;
  GInetAddr *addr;
  gint port;
  gchar *name;

  server = gnet_tcp_socket_server_new_with_port(server_port);
  
  addr = gnet_tcp_socket_get_local_inetaddr(server);
  g_assert(addr);

  name = gnet_inetaddr_get_canonical_name(addr);
  g_assert(name);

  port = gnet_inetaddr_get_port(addr);
  g_print("Voyager1 started at %s:%d\n\n", name, port);

  gnet_inetaddr_delete (addr);
  g_free(name);

  return server;
}
Ejemplo n.º 8
0
int
main(int argc, char** argv)
{
  gchar* hostname;
  gint port;
  GInetAddr* addr;
  GTcpSocket* socket;
  GIOChannel* iochannel;
  GIOError error = G_IO_ERROR_NONE;
  gchar buffer[1024];
  gsize n;

  gnet_init ();

  /* Parse args */
  if (argc != 3)
    {  
      g_print ("usage: %s <server> <port>\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  hostname = argv[1];
  port = atoi(argv[2]);

  /* Create the address */
  addr = gnet_inetaddr_new (hostname, port);
  if (!addr)
    {
      fprintf (stderr, "Error: Name lookup for %s failed\n", hostname);
      exit (EXIT_FAILURE);
    }

  /* Create the socket */
  socket = gnet_tcp_socket_new (addr);
  gnet_inetaddr_delete (addr);
  if (!socket)
    {
      fprintf (stderr, "Error: Could not connect to %s:%d\n", hostname, port);
      exit (EXIT_FAILURE);
    }

#if 0
  {
    gchar* cname;

    /* Print local address */
    addr = gnet_tcp_socket_get_local_inetaddr (socket);
    g_assert (addr);
    cname = gnet_inetaddr_get_canonical_name (addr);
    g_assert (cname);
    g_print ("Local address: %s:%d\n", cname, gnet_inetaddr_get_port(addr));
    g_free (cname);
    gnet_inetaddr_delete (addr);

    /* Print remote address */
    addr = gnet_tcp_socket_get_remote_inetaddr (socket);
    g_assert (addr);
    cname = gnet_inetaddr_get_canonical_name (addr);
    g_assert (cname);
    g_print ("Remote address: %s:%d\n", cname, gnet_inetaddr_get_port(addr));
    g_free (cname);
    gnet_inetaddr_delete (addr);
  }
#endif

  /* Get the IOChannel */
  iochannel = gnet_tcp_socket_get_io_channel (socket);
  g_assert (iochannel != NULL);

  while (fgets(buffer, sizeof(buffer), stdin) != 0)
    {
      n = strlen(buffer);
      error = gnet_io_channel_writen (iochannel, buffer, n, &n);
      if (error != G_IO_ERROR_NONE) break;

      error = gnet_io_channel_readn (iochannel, buffer, n, &n);
      if (error != G_IO_ERROR_NONE) break;

      if (fwrite(buffer, n, 1, stdout) != 1) {
       fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
      }
    }

  if (error != G_IO_ERROR_NONE) 
    fprintf (stderr, "Error: IO error (%d)\n", error);

  gnet_tcp_socket_delete (socket);

  return 0;
}
Ejemplo n.º 9
0
gboolean network_receive(GIOChannel *source, GIOCondition condition, gpointer data)
{
	/* Primarily, we'll only be reading in a small amount of info */
	if(log_level == 0)
	{
		if((condition&G_IO_HUP)==G_IO_HUP)
		{
			return FALSE;
		}
		if((condition&G_IO_IN) == G_IO_IN)
		{
			GIOError error = G_IO_ERROR_NONE;
			char data = 0;
			unsigned int offset = 0;
			char message[1024] = { '\0' };
			gsize n = 1;
			while(data!='\n')
			{
				error = gnet_io_channel_readn(msn_channel, &data, n, &n); 
				if(n == 0)
				{
					return FALSE;
				}
				if (error != G_IO_ERROR_NONE) 
				{
					error_dialog("Error receiving network data!");
					return FALSE;
				}
				message[offset++] = data;
			}
			printf("Received: %s\n",message);
			/*
				TODO: action to take
			*/
			if(strncmp(message, "VER",3)==0)
			{
				/* Got a response from VER, time to send CVR */
				char *tmp_message = g_strdup_printf("CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "CVR", 3) == 0)
			{
				/* Got a response from CVR, time to send USR */
				char *tmp_message = g_strdup_printf("USR 3 TWN I %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "XFR", 3) == 0)
			{
				/* The tricky part... */
				log_level = 1;

				/*
					Now we close our socket, and point it at the ip given to us in the XFR message

					Sample specimen

					XFR 3 NS 207.46.108.91:1863 0 65.54.239.210:1863

				*/

				char *ip_start = strstr(message, "NS ");
				/* Skip past the "NS " */
				ip_start+=3;

				/* Find the splitter, " 0 " */
				char *ip_end = strstr(ip_start, " 0 ");
				ip_end[0] = '\0';

				char *ip_port_split = strstr(ip_start, ":");
				ip_port_split[0] = '\0';

				/* Voila */
				printf("IP: %s\n",ip_start);
				gnet_tcp_socket_delete(msn_socket);
				
				GInetAddr* addr;
				addr = gnet_inetaddr_new(ip_start, 1863);
				if(addr)
				{
					msn_socket = gnet_tcp_socket_new(addr);
					gnet_inetaddr_delete(addr);
				}
				else
				{
					error_dialog("Failed to resolve messenger.msn.com");
					return;
				}
	
				msn_channel = gnet_tcp_socket_get_io_channel(msn_socket);
				g_io_channel_set_buffer_size(msn_channel,128);
				g_io_channel_set_buffered(msn_channel,1);
				g_io_channel_set_encoding(msn_channel, NULL, NULL);
				g_io_add_watch(msn_channel,G_IO_IN|G_IO_HUP|G_IO_ERR,(GIOFunc)network_receive,NULL);
				printf("Transfered\n");
				net_send("VER 0 MSNP8 MYPROTOCOL CVR0 \r\n");
				return FALSE;
			}
		}
	}
	/* When the primary login stage (jumping connection) is done log_level = 1 */
	else if(log_level == 1)
	{
		if((condition&G_IO_HUP)==G_IO_HUP)
		{
			return FALSE;
		}
		if((condition&G_IO_IN) == G_IO_IN)
		{
			GIOError error = G_IO_ERROR_NONE;
			char data = 0;
			unsigned int offset = 0;
			char message[1024] = { '\0' };
			gsize n = 1;
			while(data!='\n')
			{
				error = gnet_io_channel_readn(msn_channel, &data, n, &n); 
				if(n == 0)
				{
					return FALSE;
				}
				if (error != G_IO_ERROR_NONE) 
				{
					error_dialog("Error receiving network data!");
					return FALSE;
				}
				message[offset++] = data;
			}
			printf("Received: %s\n",message);
			/*
				TODO: action to take
			*/
			if(strncmp(message, "VER",3)==0)
			{
				/* Got a response from VER, time to send CVR */
				char *tmp_message = g_strdup_printf("CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "CVR", 3) == 0)
			{
				/* Got a response from CVR, time to send USR */
				char *tmp_message = g_strdup_printf("USR 3 TWN I %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "USR 3", 5) == 0)
			{
				/* 
					REALLY Tricky part now. OpenSSL - woohoo :( 

					Basically, the MSN protocol uses SSL to autheticate clients; so what happens now is, the MSN server sends us a 'challenge'
					for the SSL login page that we must send to it. So we need to extract that data, and send it to MSN to grab our golden 'ticket'
					which is used in the final login period.
				*/
				
				/* Example: USR 3 TWN S ct=1202475836,rver=5.0.3270.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465196398e0 */
				char *ticket = strstr(message, " ct=")+1;
				printf("Ticket: %s\n",ticket);
				
				char *return_ticket = net_ssl_auth(ticket);
				printf("Got ticket: %s\n",return_ticket);
				char *tmp_message = g_strdup_printf("USR 4 TWN S %s\r\n", return_ticket);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "USR 4", 5) == 0)
			{
				/* Woot I'm in! - We just got our email (useless) AND OUR NICKNAME! DAMN RIGHT BITCHES! */

				char *nick = split(message, ' ', 4);
				char *email = split(message, ' ', 3);
				globals_email = email;
				mwin_change_nick(nick);

				g_free(nick);
				char *tmp_message = g_strdup_printf("SYN 5 0\r\n");
				net_send(tmp_message);
				g_free(tmp_message);
				tmp_message = g_strdup_printf("CHG %d NLN 0\r\n",msg_num++);
				net_send(tmp_message);
				g_free(tmp_message);
				
			}
			else if(strncmp(message, "CHL", 3) == 0)
			{
				/* Got a challenge from MSN, and who am I to refuse? */
				char *challenge = message + 6;
				char *end = strstr(message, "\r\n");
				end[0] = '\0';
				char *chal_string = g_strdup_printf("%s%s",challenge,"Q1P7W2E4J9R8U3S5");
				GMD5* chal_md5 = gnet_md5_new(chal_string,strlen(chal_string));
				g_free(chal_string);
				
				gchar *hash = gnet_md5_get_string(chal_md5);
				gnet_md5_delete(chal_md5);
				
				printf("Challenge reply: %s\n",hash);
				
				char *tmp_message = g_strdup_printf("QRY %d [email protected] 32\r\n%s",msg_num++, hash);
				net_send(tmp_message);
				g_free(tmp_message);	
			}
			else if(strncmp(message,"RNG",3) == 0)
			{
				/* Got an incoming message! */
				printf("Got an incoming message, someone hast double clicked upon us!\n");
				printf("MESSAGE: %s\n",message);
				char *phost = split(message,' ', 2);
				char *host = split(phost,':',0);
				free(phost);
				printf("Host: %s\n",host);
				
				char *session = split(message,' ', 1);
				printf("Session: %s\n",session);
				
				char *auth_str = split(message,' ',4);
				char *email = split(message, ' ', 5);
				char *nick = split(message, ' ', 6);
				nick[strlen(nick)-2]='\0';
			
				printf("Auth: %s\n",auth_str);
				printf("Email: %s\n",email);
				printf("Nick: %s\n", nick);

				conversation_new(host, session, auth_str, email, nick, uemail);
			}
			else if(strncmp(message,"MSG",3) == 0)
			{
				// Got a message, most likely it's gonna be from Hotmail
				// Important thing is, MSG's have a payload size!
				char *nick = split(message,' ',2);
				char *len = split(message,' ',3);
				len[strlen(len)-2] = '\0';
				int length = atoi(len);
				printf("Inbound message length: %d\n",length);

				error = G_IO_ERROR_NONE;
				char incoming_msg[length+1];
				memset(incoming_msg, '\0',length+1);
				gsize n = length;
				error = gnet_io_channel_readn(msn_channel, incoming_msg, n, &n);
				if(error != G_IO_ERROR_NONE)
				{
				   fprintf(stderr, "Error occurred reading message\n");
				   return FALSE;
				}
				printf("Message: %s\n",incoming_msg);
			}
		}
	}
	return TRUE;
}