aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/twitter/twitter_lib.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index bfcebd2b..01e8f538 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -500,23 +500,30 @@ static xt_status twitter_xt_get_status(struct xt_node *node, struct twitter_xml_
} else {
struct xt_node *urls, *url;
- urls = xt_find_path(node, "entities/urls");
- for (url = urls ? urls->children : NULL; url; url = url->next) {
- /* "short" is a reserved word. :-P */
- struct xt_node *kort = xt_find_node(url->children, "url");
- struct xt_node *disp = xt_find_node(url->children, "display_url");
- char *pos, *new;
-
- if (!kort || !kort->text || !disp || !disp->text ||
- !(pos = strstr(txs->text, kort->text)))
+ urls = xt_find_path(node, "entities");
+ if (urls != NULL)
+ urls = urls->children;
+ for (; urls; urls = urls->next) {
+ if (strcmp(urls->name, "urls") != 0 && strcmp(urls->name, "media") != 0)
continue;
- *pos = '\0';
- new = g_strdup_printf("%s%s <%s>%s", txs->text, kort->text,
- disp->text, pos + strlen(kort->text));
-
- g_free(txs->text);
- txs->text = new;
+ for (url = urls ? urls->children : NULL; url; url = url->next) {
+ /* "short" is a reserved word. :-P */
+ struct xt_node *kort = xt_find_node(url->children, "url");
+ struct xt_node *disp = xt_find_node(url->children, "display_url");
+ char *pos, *new;
+
+ if (!kort || !kort->text || !disp || !disp->text ||
+ !(pos = strstr(txs->text, kort->text)))
+ continue;
+
+ *pos = '\0';
+ new = g_strdup_printf("%s%s <%s>%s", txs->text, kort->text,
+ disp->text, pos + strlen(kort->text));
+
+ g_free(txs->text);
+ txs->text = new;
+ }
}
}
>160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2004 Wilmer van der Gaast and others                *
  \********************************************************************/

/* Stuff to handle, save and search buddies                             */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License with
  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  Suite 330, Boston, MA  02111-1307  USA
*/

#define BITLBEE_CORE
#include "bitlbee.h"

user_t *user_add( irc_t *irc, char *nick )
{
	user_t *u, *lu = NULL;
	char *key;
	
	if( !nick_ok( nick ) )
		return( NULL );
	
	if( user_find( irc, nick ) != NULL )
		return( NULL );
	
	if( ( u = irc->users ) )
	{
		while( u )
		{
			if( nick_cmp( nick, u->nick ) < 0 )
				break;
			
			lu = u;
			u = u->next;
		}
		
		u = g_new0( user_t, 1 );
		if( lu )
		{
			u->next = lu->next;
			lu->next = u;
		}
		else
		{
			u->next = irc->users;
			irc->users = u;
		}
	}
	else
	{
		irc->users = u = g_new0( user_t, 1 );
	}
	
	u->user = u->realname = u->host = u->nick = g_strdup( nick );
	u->is_private = set_getint( irc, "private" );
	
	key = g_strdup( nick );
	nick_lc( key );
	g_hash_table_insert( irc->userhash, key, u );
	
	return( u );
}

int user_del( irc_t *irc, char *nick )
{
	user_t *u, *t;
	char *key;
	gpointer okey, ovalue;
	
	if( !nick_ok( nick ) )
		return( 0 );
	
	u = irc->users;
	t = NULL;
	while( u )
	{
		if( nick_cmp( u->nick, nick ) == 0 )
		{
			/* Get this key now already, since "nick" might be free()d
			   at the time we start playing with the hash... */
			key = g_strdup( nick );
			nick_lc( key );
			
			if( t )
				t->next = u->next;
			else
				irc->users = u->next;
			if( u->online )
				irc_kill( irc, u );
			g_free( u->nick );
			if( u->nick != u->user ) g_free( u->user );
			if( u->nick != u->host ) g_free( u->host );
			if( u->nick != u->realname ) g_free( u->realname );
			if( u->away ) g_free( u->away );
			if( u->handle ) g_free( u->handle );
			if( u->sendbuf ) g_free( u->sendbuf );
			if( u->sendbuf_timer ) g_source_remove( u->sendbuf_timer );
			g_free( u );
			
			if( !g_hash_table_lookup_extended( irc->userhash, key, &okey, &ovalue ) || ovalue != u )
			{
				g_free( key );
				return( 1 );	/* Although this is a severe error, the user is removed from the list... */
			}
			g_hash_table_remove( irc->userhash, key );
			g_free( key );
			g_free( okey );
			
			return( 1 );
		}
		u = (t=u)->next;
	}
	
	return( 0 );
}

user_t *user_find( irc_t *irc, char *nick )
{
	char key[512] = "";
	
	strncpy( key, nick, sizeof( key ) - 1 );
	if( nick_lc( key ) )
		return( g_hash_table_lookup( irc->userhash, key ) );
	else
		return( NULL );
}

user_t *user_findhandle( struct gaim_connection *gc, char *handle )
{
	user_t *u = gc->irc->users;
	
	while( u )
	{
		if( u->gc == gc && u->handle && gc->prpl->cmp_buddynames ( u->handle, handle ) == 0 )
			break;
		u = u->next;
	}
	
	return( u );
}

void user_rename( irc_t *irc, char *oldnick, char *newnick )
{
	user_t *u = user_find( irc, oldnick );
	gpointer okey, ovalue;
	char *key;
	
	if( !u ) return;	/* Should've been checked by the caller... */
	
	g_free( u->nick );
	if( u->nick == u->user ) u->user = NULL;
	if( u->nick == u->host ) u->host = NULL;
	if( u->nick == u->realname ) u->realname = NULL;
	u->nick = g_strdup( newnick );
	if( !u->user ) u->user = u->nick;
	if( !u->host ) u->user = u->host;
	if( !u->realname ) u->user = u->realname;
	
	/* Remove the old reference to this user from the hash and create a
	   new one with the new nick. This is indeed a bit messy. */
	key = g_strdup( oldnick );
	nick_lc( key );
	if( !g_hash_table_lookup_extended( irc->userhash, key, &okey, &ovalue ) || ovalue != u )
	{
		g_free( key );
		return;		/* This really shouldn't happen! */	
	}
	g_hash_table_remove( irc->userhash, key );
	g_free( key );
	g_free( okey );
	
	key = g_strdup( newnick );
	nick_lc( key );
	g_hash_table_insert( irc->userhash, key, u );
	
	/* Also, let's try to keep the linked list nicely sorted. Fear this
	   code. If my teacher would see this, she would cry. ;-) */
	{
		user_t *u1, *lu1;
		
		/* Remove the user from the old position in the chain. */
		if( u == irc->users )
		{
			irc->users = u->next;
		}
		else
		{
			u1 = u;
			for( lu1 = irc->users; lu1->next != u1; lu1 = lu1->next );
			lu1->next = u1->next;
		}
		
		/* Search for the new position. */
		for( lu1 = NULL, u1 = irc->users; u1; u1 = u1->next )
		{
			if( nick_cmp( newnick, u1->nick ) < 0 )
				break;
			
			lu1 = u1;
		}
		
		/* Insert it at this new position. */
		u->next = u1;
		if( lu1 )
			lu1->next = u;
		else
			irc->users = u;
	}
}