Exemplo n.º 1
0
int
jabber_connect (void)
{
	int e;

	j_parser = iks_stream_new (IKS_NS_CLIENT, NULL, (iksStreamHook *) on_stream);
	j_user = iks_id_new (iks_parser_stack (j_parser), prefs.jid);
	if (j_user->resource == NULL) {
		char buf[512];
		sprintf (buf, "%s/sozluk", j_user->partial);
		j_user = iks_id_new (iks_parser_stack (j_parser), buf);
	}
	log_event ("Bağlanmayı deniyorum (%s)", j_user->full);
	//iks_set_log_hook (j_parser, (iksLogHook *) on_log);

	authorized = 0;

	e = iks_connect_tcp (j_parser, j_user->server, IKS_JABBER_PORT);
	switch (e) {
		case IKS_OK:
			return 0;
		case IKS_NET_NODNS:
		case IKS_NET_NOCONN:
		default:
			log_event ("jabber bork");
			return -1;
	}
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
  iksid *myjabberid = NULL;
  char *jabberid = NULL;
  char *resource = NULL;
  int state,args;
  int port = 0;
  if(argc > 2) {      
    for (args=1; args < argc; args++) {
      if(!strncmp(argv[args], "-u", sizeof(argv[args]))) {
        jabberid = argv[args+1];
#ifdef DEBUG
        puts((char *) jabberid);
#endif
      }
      else {
        if(!strncmp(argv[args], "-p", sizeof(argv[args]))) {
         	port = atoi(argv[args+1]);
         	if(port == 0)
         	  if(error("can't bind to this port"))
        	    return 1;
#ifdef DEBUG
        	printf("port: %i\n", port);
#endif
        }
        if(!strncmp(argv[args],"-r",sizeof(argv[args]))){
          resource = argv[args+1];
#ifdef DEBUG
          printf("resource: %s\n",resource);
#endif
        }
      }
    }
  }
  /*
   * initialising the struct net of the type netdata 
   */
  struct netdata net;

  /*
   * create a new SAX parser 
   */
  net.parser = iks_sax_new(NULL, tagHook, cdataHook);

  /*
   * check if the parser is valid 
   */
  if(!net.parser)
    error("f**k off damn bastard.");

  /*
   * create a new stream on the parser 
   */
  net.parser = iks_stream_new(IKS_NS_CLIENT, &net, (iksStreamHook *) tagHook);

#ifdef DEBUG
  if(net.parser)
    puts("net.parser initiated.");
#endif

  /*
   * copy the new jabberid to the net struct 
   */
  net.id = create_id(jabberid, &net);

  /*
   * just a boring message.. ;-) 
   */
  printf("Connecting to '%s'...", net.id->server);

  /*
   * try to connect to the remote server 
   */
  if(port == 0)
    state = iks_connect_tcp(net.parser, net.id->server, IKS_JABBER_PORT);
  else
    state = iks_connect_tcp(net.parser, net.id->server, port);

  /*
   * check wether the connection is established or not.
   */
  switch (state) {
    case IKS_OK:
      /*
       * everything is OK! ;-) 
       */
      puts("OK");
      break;
    case IKS_NET_NODNS:
      /*
       * hostname could not be resolved 
       */
      if(error("hostname lookup failed") == 1)
        return 1;
    case IKS_NET_NOSOCK:
      /*
       * socket descriptor cannot be created 
       */
      if(error("socket cannot be created") == 1)
        return 1;
    case IKS_NET_NOCONN:
      /*
       * the connection cannot be established..
       * this could have several sources.
       */
      if(error("connection failed") == 1)
        return 1;
    default:
      /*
       * everything else. 
       */
      if(error("io error") == 1)
        return 1;
  }

  /*
   * setting the resource 
   */
  if(!net.id->resource)
    net.id->resource = RESOURCE;

#ifdef DEBUG
  printf
    ("username: %s\nserver: %s\nresource: %s\npartial: %s\nfull: %s\n",
     net.id->user, net.id->server, net.id->resource, net.id->partial,
     net.id->full);
#endif

  /*
   * disconnect the parser. 
   */
  iks_disconnect(net.parser);
  /*
   * delete the parser.. 
   */
  iks_parser_delete(net.parser);
  return 0;
}