Пример #1
0
void
msn_user_update(MsnUser *user)
{
	GaimConnection *gc;

	gc = user->userlist->session->account->gc;

	if (user->online)
		serv_got_update(gc, user->passport, TRUE, 0, 0, user->idle, user->status);
	else
		serv_got_update(gc, user->passport, FALSE, 0, 0, 0, 0);
}
Пример #2
0
void jabber_presence_fake_to_self(JabberStream *js, const char *away_state, const char *msg) {
	char *my_base_jid;

	if(!js->user)
		return;

	my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);

	if(gaim_find_buddy(js->gc->account, my_base_jid)) {
		JabberBuddy *jb;
		JabberBuddyResource *jbr;
		if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) {
			int state = 0;
			if(away_state) {
				if(!strcmp(away_state, _("Away")) ||
						(msg && *msg && !strcmp(away_state, GAIM_AWAY_CUSTOM)))
					state = JABBER_STATE_AWAY;
				else if(!strcmp(away_state, _("Chatty")))
					state = JABBER_STATE_CHAT;
				else if(!strcmp(away_state, _("Extended Away")))
					state = JABBER_STATE_XA;
				else if(!strcmp(away_state, _("Do Not Disturb")))
					state = JABBER_STATE_DND;
			}
		       
			if (away_state && !strcmp(away_state, "unavailable")) {
				jabber_buddy_remove_resource(jb, js->user->resource);
			} else {
				jabber_buddy_track_resource(jb, js->user->resource, 0, state, (msg && *msg) ? msg : NULL);
			}
			if((jbr = jabber_buddy_find_resource(jb, NULL)))
				serv_got_update(js->gc, my_base_jid, TRUE, 0, 0, 0, jbr->state);
			else
				serv_got_update(js->gc, my_base_jid, FALSE, 0, 0, 0, 0);
		}
	}
	g_free(my_base_jid);
}
Пример #3
0
static void
sippy_recv_cb(gpointer data, gint source, GaimInputCondition condition)
{
  GaimConnection *gc = data;
  int len;
  int command;
  static char buf[4096];
  static char bufFrom[4096];
  static char bufTo[4096];
  
  len = read( FD_GAG_TO_GAIM, &command, sizeof(command ) );
  if ( len == -1 )
  {
     int err = errno;
     gaim_debug(GAIM_DEBUG_INFO,"sippy","err=%d\n",err);  
     /* something really bad happened */
     resip_assert(0);
  }
  if ( len == 0 )
  {
     /* not ready */
     return;
  }
  resip_assert( len == sizeof(command) );
  
  switch ( command )
  {
     case SIMPLE_IM:
     {	
        gaim_debug(GAIM_DEBUG_INFO,"sippy","got an IM messages from gag\n");  

        sippy_get_string( bufTo, sizeof(bufTo) );
        sippy_get_string( bufFrom, sizeof(bufFrom) );
        sippy_get_string( buf, sizeof(buf) );

        gaim_debug(GAIM_DEBUG_INFO,"sippy","got an IM from=%s to=%s data=%s\n",bufFrom,bufTo,buf);  

        serv_got_im(gc,bufFrom,buf,0,time(NULL)); 
     }
     break;
     
     case SIMPLE_LOGIN_STATUS:
     {
        unsigned char success;
        int sipCode;
        
        /* bool success, int sipCode, data message */
        sippy_get_bool( &success );
        sippy_get_int( &sipCode );
        sippy_get_string( buf, sizeof(buf) );  
 
        gaim_debug(GAIM_DEBUG_INFO,"sippy","got a LOGIN_STATUS status=%d msg=%s\n",sipCode,buf);
	if (gaim_connection_get_state(gc) != GAIM_CONNECTED)
	{
          if (success)
          {
            gaim_connection_update_progress(gc,_("Connecting"),1,2);
            gaim_connection_set_state(gc, GAIM_CONNECTED);
          }
          else
          {
            gaim_connection_error(gc, _(buf));
          }
	}
     }
     break;
     
     case SIMPLE_PRESENCE: /* uri aor, bool  available, Data status */
     { 
        unsigned char open;
	int lastReportedUCStatus;
        
        gaim_debug(GAIM_DEBUG_INFO,"sippy","got a PRES messages from gag\n");

        sippy_get_string( bufFrom, sizeof(bufFrom) );
        sippy_get_bool( &open );
        sippy_get_string( buf, sizeof(buf) );
        
        gaim_debug(GAIM_DEBUG_INFO,"sippy","got a PRES messages from gag from=%s open=%d, msg=%s\n",bufFrom,open,buf);

        {
	  struct simple_connection_cache *sc_cache = gc->proto_data;
	  struct simple_friend_cache *sf;
	  
	  sf = g_hash_table_lookup(sc_cache->friends,bufFrom);
	  if (!sf) {
	    sf = simple_friend_cache_new();
	    g_hash_table_insert(sc_cache->friends,g_strdup(bufFrom),sf);
	  }
          if (sf->status_string)
	  {
	    g_free(sf->status_string);
	  } 
	  sf->status_string = g_strdup(buf);

	  lastReportedUCStatus = (sf->status_int ^= 2);
	} 

	/* AFAICT, there is a half-done change to the use of
	 * the last argument to serv_got_update that is messing
	 * up Yahoo as well as us. The code above the prpl abstraction
	 * claims the integer is ours to do with as we please, but they
	 * use the lowest order bit to mean available or not.
	 *
	 * Other code looks for changes to this integer - if it has
	 * not changed it shortcuts all the GUI updates. So...
	 * We're going to game gaim for now by toggling the second
	 * lowest order bit each time we call this function.
         *
         * TODO: This was true in the gaim 0.71 code - need to review to
         * see if this is still appropriate.
	 */

        serv_got_update(gc, bufFrom, (int)open, 0, 0, 0, lastReportedUCStatus);

     }
     break;
     
     case SIMPLE_HELLO: /* bool ok */
     {
        unsigned char ok;
        sippy_get_bool( &ok ); 
        gaim_debug(GAIM_DEBUG_INFO,"sippy","got a HELLO ok=%d\n",ok);
     }
     
     case SIMPLE_ERROR:
     { 
        gaim_debug(GAIM_DEBUG_INFO,"sippy","got an ERROR messages from gag\n");
        sippy_get_string( buf, sizeof(buf) );
        gaim_debug(GAIM_DEBUG_INFO,"sippy","gag ERROR %s\n",buf);
        gaim_request_action(gc, _("SIP Error"), _("SIP Error"), buf, 
                             0, NULL, 1, _("Okay"), 0);
     }
     break;
     
     default:
        resip_assert(0);
  }
}
Пример #4
0
int toc_callback(int fd)
{
        char *buf;
	char *c;
	char **args = NULL;
	char *dup,*raw;
        char *l;
	int numargs =0;

        buf = malloc(BUF_LONG);

        if (wait_reply(buf, BUF_LONG) < 0) {
                toc_signoff();
		toc_debug_printf("need to do proper sign off on this\n");
		toc_msg_printf(TOC_CONNECT_MSGS,"Connection Closed");
		return -1;
        }
                         
        dup = strdup(buf+sizeof(struct sflap_hdr));
	raw = rindex(dup,':'); 
	c=strtok(buf+sizeof(struct sflap_hdr),":");	/* Ditch the first part */
	if (!strcasecmp(c,"UPDATE_BUDDY")) {
		char *uc, *t;
		int logged, evil, idle, type = 0;
		long signon;
		time_t time_idle;

		numargs = 7;
		args = (char **) malloc(sizeof(char *)*numargs);
		use_handler(TOC_RAW_HANDLE,TOC_UPDATE_BUDDY,raw);
		c = strtok(NULL,":"); /* c is name */
		args[0] = strdup(c);
		
		l = strtok(NULL,":"); /* l is T/F logged status */
       		args[1] = strdup(l);
	
		t = strtok(NULL, ":");
		args[2] = strdup(t);
		sscanf(t, "%d", &evil);
		
		t = strtok(NULL, ":");
		args[3] = strdup(t);		
		sscanf(t, "%ld", &signon);

		t = strtok(NULL, ":");
		args[4] = strdup(t);		
		sscanf(t, "%d", &idle);
		
                uc = strtok(NULL, ":");
		args[5] = strdup(uc);

		if (!strncasecmp(l,"T",1))
			logged = 1;
		else
			logged = 0;


		if (uc[0] == 'A')
			type |= UC_AOL;
		
		switch(uc[1]) {
		case 'A':
			type |= UC_ADMIN;
			break;
		case 'U':
			type |= UC_UNCONFIRMED;
			break;
		case 'O':
			type |= UC_NORMAL;
			break;
		default:
			break;
		}

                switch(uc[2]) {
		case 'U':
			type |= UC_UNAVAILABLE;
			break;
		default:
			break;
		}

                if (idle) {
                        time(&time_idle);
                        time_idle -= idle*60;
                } else
                        time_idle = 0;
		
		serv_got_update(c, logged, evil, signon, time_idle, type); 
		args[6] = NULL;
		use_handler(TOC_HANDLE,TOC_UPDATE_BUDDY,args);
	} else if (!strcasecmp(c, "ERROR")) {
		use_handler(TOC_RAW_HANDLE,TOC_ERROR,raw);
		c = strtok(NULL,":");
		translate_toc_error_code(c);
		args = (char **) malloc(sizeof(char *)*1 + 1);
		numargs = 1;
		args[0] = strdup(c);
		use_handler(TOC_HANDLE,TOC_ERROR,args);
		toc_debug_printf("ERROR: %s",c);
	} else if (!strcasecmp(c, "NICK")) {
		use_handler(TOC_RAW_HANDLE,TOC_NICK,raw);
		c = strtok(NULL,":");
		snprintf(aim_username, sizeof(aim_username), "%s", c);
		numargs = 2;
		args = (char **) malloc(sizeof(char *)*numargs);
		args[0] = strdup(c);
		args[1] = NULL;
		use_handler(TOC_HANDLE,TOC_NICK,args);	
	} else if (!strcasecmp(c, "IM_IN")) {
		char *away, *message;
                int a = 0;
		use_handler(TOC_RAW_HANDLE,TOC_IM_IN,raw);
		c = strtok(NULL,":");
		away = strtok(NULL,":");

		message = away;

                while(*message && (*message != ':'))
                        message++;

                message++;

		if (!strncasecmp(away, "T", 1))
			a = 1;

		if ( serv_got_im(c, message,a) > 0 ) {
			numargs = 3;
			args = (char **) malloc(sizeof(char *)*numargs);		
			args[0] = strdup(c);
			args[1] = strdup(message);
			args[2] = NULL;
			use_handler(TOC_HANDLE,TOC_IM_IN,args);
		}
	} else if (!strcasecmp(c, "GOTO_URL")) {
		char *name;
		char *url;

		char tmp[256];
		
		use_handler(TOC_RAW_HANDLE,TOC_GOTO_URL,raw);
		name = strtok(NULL, ":");
		url = strtok(NULL, ":");


		snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", toc_addy, aim_port, url);
/*		fprintf(stdout, "Name: %s\n%s\n", name, url);
		printf("%s", grab_url(tmp));*/

		numargs = 2;
		args = (char **) malloc(sizeof(char *)*numargs);
		args[0] = strdup(tmp);
		args[1] = NULL;
		use_handler(TOC_HANDLE,TOC_GOTO_URL,args);
		/* statusprintf("GOTO_URL: %s","tmp"); */
        } else if (!strcasecmp(c, "EVILED")) {
                int lev;
		char *name = NULL;
		char *levc;

		use_handler(TOC_RAW_HANDLE,TOC_EVILED,raw);
		levc = strtok(NULL, ":");
                sscanf(levc, "%d", &lev);
                name = strtok(NULL, ":");

                toc_debug_printf("evil: %s | %d\n", name, lev);

		numargs = 3;
		my_evil = lev;
		args = (char **) malloc(sizeof(char *)*numargs);		
		if ( name != NULL )
			args[0] = strdup(name);
		else 
			args[0] = NULL;
		args[1] = strdup(levc);
		args[2] = NULL;
		use_handler(TOC_HANDLE,TOC_EVILED,args);
		
        } else if (!strcasecmp(c, "CHAT_JOIN")) {
                char *name,*idc;
                int id;
		
                use_handler(TOC_RAW_HANDLE,TOC_CHAT_JOIN,raw);
		idc = strtok(NULL, ":");
		sscanf(idc, "%d", &id);
                name = strtok(NULL, ":");
                serv_got_joined_chat(id, name); 
		numargs = 3;
		args = (char **) malloc(sizeof(char *)*numargs);		
		args[0] = strdup(idc);
		args[1] = strdup(name);
		args[2] = NULL;
		use_handler(TOC_HANDLE,TOC_CHAT_JOIN,args);		
	} else if (!strcasecmp(c, "DIR_STATUS")) {
		char *status;
		use_handler(TOC_RAW_HANDLE,TOC_DIR_STATUS,raw);
		status = strtok(NULL,":");
		numargs = 2;
		args = (char **) malloc(sizeof(char *)*numargs);		
		args[0] = strdup(status);
		args[1] = NULL;		
		use_handler(TOC_HANDLE,TOC_DIR_STATUS,args);		
	} else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) {
		int id;
		char *in,*idc;
		char *buddy;
                LLE t;
		struct buddy_chat *b = NULL;
	
		use_handler(TOC_RAW_HANDLE,TOC_CHAT_UPDATE_BUDDY,raw);		
		idc = strtok(NULL, ":");
		sscanf(idc, "%d", &id);

		in = strtok(NULL, ":");

		for ( TLL(buddy_chats,t) ) {
			b = (struct buddy_chat *)t->data;
			if (id == b->id)
				break;	
                        b = NULL;
		}
		
		if (!b)
			return -2;

		
		if (!strcasecmp(in, "T")) {
			while((buddy = strtok(NULL, ":")) != NULL) {
				/* 
				 * Fuxin aim causes a problem here
				 */
				AddToLL(b->in_room, buddy,NULL);
				if ( b->init_chat ) {
					args = (char **) malloc(sizeof(char *)*3);
					args[0] = strdup(b->name);
					args[1] = strdup(buddy);		
					args[2] = NULL;					
					use_handler(TOC_HANDLE,TOC_BUDDY_JOIN_CHAT,args);
					free(args[0]); free(args[1]); free(args); args = NULL;
				}
			}
			/*
			 * init_chat is so that the user doenst get flooded 
			 * with user joined chat when he first joins a chat
			 */
			b->init_chat = 1;				
		} else {
			while((buddy = strtok(NULL, ":")) != NULL) {
				RemoveFromLLByKey(b->in_room, buddy);
				/* 
				 * Since we might get multiple leave/joins at once 
				 * we allocate & deallocate here 
				 */
				args = (char **) malloc(sizeof(char *)*3);
				args[0] = strdup(b->name);
				args[1] = strdup(buddy);		
				args[2] = NULL;					
				use_handler(TOC_HANDLE,TOC_BUDDY_LEFT_CHAT,args);
				free(args[0]); free(args[1]); free(args); args = NULL;
			}
		}
	} else if (!strcasecmp(c, "CHAT_LEFT")) {
Пример #5
0
static gboolean
_parse_data(TrepiaSession *session, char *buf)
{
	GHashTable *info;
	GaimAccount *account;
	TrepiaMessageType type = 0;
	TrepiaProfile *profile = NULL;
	int ret;
	char *buffer;
	GaimBuddy *b;
	int id = 0;
	const char *value;
	char *username;
	int *int_p;
	GMainContext *ctx;

	account = gaim_connection_get_account(session->gc);

	ret = __parse_message(buf, &type, &info);

	if (ret == 1)
		return TRUE;

	if (info != NULL) {
		switch (type) {
			case TREPIA_USER_LIST:
				gaim_connection_update_progress(session->gc,
						_("Retrieving buddy list"), 2, TREPIA_CONNECT_STEPS);

				gaim_connection_set_state(session->gc, GAIM_CONNECTED);
				serv_finish_login(session->gc);
				break;

			case TREPIA_MSG_INCOMING: /* Incoming Message */
				id = atoi(g_hash_table_lookup(info, "a"));

				profile = g_hash_table_lookup(session->user_profiles, &id);
				serv_got_im(session->gc,
							trepia_profile_get_login(profile),
							(char *)g_hash_table_lookup(info, "b"),
							0, time(NULL));
				break;

			case TREPIA_MEMBER_UPDATE:
				profile = trepia_profile_new();

				if ((value = g_hash_table_lookup(info, "a")) != NULL) {
					id = atoi(value);
					trepia_profile_set_id(profile, id);
				}

				if ((value = g_hash_table_lookup(info, "b")) != NULL)
					trepia_profile_set_login_time(profile, atoi(value));

				if ((value = g_hash_table_lookup(info, "c")) != NULL)
					trepia_profile_set_type(profile, atoi(value));
				else
					trepia_profile_set_type(profile, 2);

				session->pending_users = g_list_append(session->pending_users,
													   profile);


#if 0
				if (trepia_profile_get_type(profile) == 1) {
					buffer = g_strdup_printf(
						"<D>"
						"<a>%d</a>"
						"<b>1</b>"
						"</D>",
						id);
				}
				else {
#endif
					buffer = g_strdup_printf(
						"<D>"
						"<a>%d</a>"
						"<b>1</b>"
						"</D>"
						"<D>"
						"<a>%d</a>"
						"<b>2</b>"
						"</D>",
						id,
						id);
#if 0
				}
#endif

				if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
					gaim_connection_error(session->gc, _("Write error"));
					g_free(buffer);
					return 1;
				}

				g_free(buffer);
				break;

			case TREPIA_MEMBER_PROFILE:
				if ((value = g_hash_table_lookup(info, "a")) != NULL) {
					GList *l;

					id = atoi(value);

					for (l = session->pending_users; l != NULL; l = l->next) {
						profile = l->data;

						if (trepia_profile_get_id(profile) == id)
							break;

						profile = NULL;
					}
				}
				else
					break;

				if (profile == NULL) {
					profile = g_hash_table_lookup(session->user_profiles, &id);

					if (profile == NULL)
						break;
				}

				/* Age */
				if ((value = g_hash_table_lookup(info, "m")) != NULL)
					trepia_profile_set_age(profile, atoi(value));

				/* ICQ */
				if ((value = g_hash_table_lookup(info, "i")) != NULL)
					trepia_profile_set_icq(profile, atoi(value));

				/* Sex */
				if ((value = g_hash_table_lookup(info, "n")) != NULL)
					trepia_profile_set_sex(profile, *value);

				/* Location */
				if ((value = g_hash_table_lookup(info, "p")) != NULL)
					trepia_profile_set_location(profile, value);

				/* First Name */
				if ((value = g_hash_table_lookup(info, "g")) != NULL)
					trepia_profile_set_first_name(profile, value);

				/* Last Name */
				if ((value = g_hash_table_lookup(info, "h")) != NULL)
					trepia_profile_set_last_name(profile, value);

				/* Profile */
				if ((value = g_hash_table_lookup(info, "o")) != NULL)
					trepia_profile_set_profile(profile, value);

				/* E-mail */
				if ((value = g_hash_table_lookup(info, "e")) != NULL)
					trepia_profile_set_email(profile, value);

				/* AIM */
				if ((value = g_hash_table_lookup(info, "j")) != NULL)
					trepia_profile_set_aim(profile, value);

				/* MSN */
				if ((value = g_hash_table_lookup(info, "k")) != NULL)
					trepia_profile_set_msn(profile, value);

				/* Yahoo */
				if ((value = g_hash_table_lookup(info, "l")) != NULL)
					trepia_profile_set_yahoo(profile, value);

				/* Homepage */
				if ((value = g_hash_table_lookup(info, "f")) != NULL)
					trepia_profile_set_homepage(profile, value);

				/* Country */
				if ((value = g_hash_table_lookup(info, "r")) != NULL)
					trepia_profile_set_country(profile, value);

				/* State */
				if ((value = g_hash_table_lookup(info, "s")) != NULL)
					trepia_profile_set_state(profile, value);

				/* City */
				if ((value = g_hash_table_lookup(info, "t")) != NULL)
					trepia_profile_set_city(profile, value);

				/* Languages */
				if ((value = g_hash_table_lookup(info, "u")) != NULL)
					trepia_profile_set_languages(profile, value);

				/* School */
				if ((value = g_hash_table_lookup(info, "v")) != NULL)
					trepia_profile_set_school(profile, value);

				/* Company */
				if ((value = g_hash_table_lookup(info, "w")) != NULL)
					trepia_profile_set_company(profile, value);

				/* Login Name */
				if ((value = g_hash_table_lookup(info, "d")) != NULL) {
					trepia_profile_set_login(profile, value);
					username = g_strdup(value);
				}
				else if ((value = trepia_profile_get_login(profile)) != NULL) {
					username = g_strdup(value);
				}
				else {
					username = g_strdup_printf("%d", id);
					trepia_profile_set_login(profile, username);
				}

				b = gaim_find_buddy(account, username);

				if (b == NULL) {
					GaimGroup *g;

					g = gaim_find_group(_("Local Users"));

					if (g == NULL) {
						g = gaim_group_new(_("Local Users"));
						gaim_blist_add_group(g, NULL);
					}

					b = gaim_buddy_new(account, username, NULL);

					gaim_blist_add_buddy(b, NULL, g, NULL);
				}

				profile->buddy = b;

				b->proto_data = profile;

				session->pending_users = g_list_remove(session->pending_users,
													   profile);

				int_p = g_new0(int, 1);
				*int_p = id;
				g_hash_table_insert(session->user_profiles, int_p, profile);

				serv_got_update(session->gc,
								username, TRUE, 0,
								trepia_profile_get_login_time(profile), 0, 0);

				/* Buddy Icon */
				if ((value = g_hash_table_lookup(info, "q")) != NULL) {
					char *icon;
					int icon_len;

					gaim_base64_decode(value, &icon, &icon_len);

					gaim_buddy_icons_set_for_user(session->gc->account,
							username, icon, icon_len);

					g_free(icon);

					serv_got_update(session->gc, username, TRUE, 0, 0, 0, 0);
				}

				/*
				 * XXX
				 * This does nothing when using a non-gtk event loop.
				 * What is it supposed to accomplish anyway?
				 */
				ctx = g_main_context_default();

				while (g_main_context_pending(ctx))
					g_main_context_iteration(ctx, FALSE);

				g_free(username);

				break;

			case TREPIA_MEMBER_OFFLINE:
				if ((value = g_hash_table_lookup(info, "a")) != NULL)
					id = atoi(value);
				else
					break;

				profile = g_hash_table_lookup(session->user_profiles, &id);

				if (profile == NULL)
					break;

				g_hash_table_remove(session->user_profiles, &id);

				b = profile->buddy;

				if (b != NULL)
					serv_got_update(session->gc,
									trepia_profile_get_login(profile),
									FALSE, 0, 0, 0, 0);

				gaim_blist_remove_buddy(b);

				break;

			default:
				break;
		}

		g_hash_table_destroy(info);
	}
	else {