Changeset 2b8473c
- Timestamp:
- 2010-06-05T00:20:12Z (14 years ago)
- Branches:
- master
- Children:
- 7e83e8e4
- Parents:
- 4469e7e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
irc_channel.c
r4469e7e r2b8473c 26 26 #include "bitlbee.h" 27 27 28 static char *set_eval_channel_type( set_t *set, char *value ); 28 29 static gint irc_channel_user_cmp( gconstpointer a_, gconstpointer b_ ); 29 30 static const struct irc_channel_funcs control_channel_funcs; … … 49 50 irc->channels = g_slist_prepend( irc->channels, ic ); 50 51 52 set_add( &ic->set, "type", "control", set_eval_channel_type, ic ); 53 51 54 if( name[0] == '&' ) 52 ic->f = &control_channel_funcs;55 set_setstr( &ic->set, "type", "control" ); 53 56 else /* if( name[0] == '#' ) */ 54 ic->f = &groupchat_stub_funcs; 55 56 if( ic->f->_init ) 57 if( !ic->f->_init( ic ) ) 58 { 59 irc_channel_free( ic ); 60 return NULL; 61 } 57 set_setstr( &ic->set, "type", "chat" ); 62 58 63 59 return ic; … … 98 94 99 95 return 1; 96 } 97 98 static char *set_eval_channel_type( set_t *set, char *value ) 99 { 100 struct irc_channel *ic = set->data; 101 const struct irc_channel_funcs *new; 102 103 if( strcmp( value, "control" ) == 0 ) 104 new = &control_channel_funcs; 105 else if( strcmp( value, "chat" ) == 0 ) 106 new = &groupchat_stub_funcs; 107 else 108 return SET_INVALID; 109 110 /* TODO: Return values. */ 111 if( ic->f && ic->f->_free ) 112 ic->f->_free( ic ); 113 114 ic->f = new; 115 116 if( ic->f && ic->f->_init ) 117 ic->f->_init( ic ); 118 119 return value; 100 120 } 101 121 … … 267 287 } 268 288 289 static char *set_eval_by_account( set_t *set, char *value ); 290 static char *set_eval_fill_by( set_t *set, char *value ); 291 static char *set_eval_by_group( set_t *set, char *value ); 292 269 293 static gboolean control_channel_init( irc_channel_t *ic ) 270 294 { 271 295 struct irc_control_channel *icc; 296 297 set_add( &ic->set, "account", NULL, set_eval_by_account, ic ); 298 set_add( &ic->set, "fill_by", "all", set_eval_fill_by, ic ); 299 set_add( &ic->set, "group", NULL, set_eval_by_group, ic ); 272 300 273 301 ic->data = icc = g_new0( struct irc_control_channel, 1 ); 274 302 icc->type = IRC_CC_TYPE_DEFAULT; 275 303 276 if( ( icc->group = bee_group_by_name( ic->irc->b, ic->name + 1, FALSE ) ) ) 304 if( bee_group_by_name( ic->irc->b, ic->name + 1, FALSE ) ) 305 { 306 set_setstr( &ic->set, "group", ic->name + 1 ); 307 set_setstr( &ic->set, "fill_by", "group" ); 308 } 309 else if( set_setstr( &ic->set, "account", ic->name + 1 ) ) 310 { 311 set_setstr( &ic->set, "fill_by", "account" ); 312 } 313 314 return TRUE; 315 } 316 317 static char *set_eval_by_account( set_t *set, char *value ) 318 { 319 struct irc_channel *ic = set->data; 320 struct irc_control_channel *icc = ic->data; 321 account_t *acc; 322 323 if( !( acc = account_get( ic->irc->b, value ) ) ) 324 return SET_INVALID; 325 326 icc->account = acc; 327 bee_irc_channel_update( ic->irc, ic, NULL ); 328 return g_strdup_printf( "%s(%s)", acc->prpl->name, acc->user ); 329 } 330 331 static char *set_eval_fill_by( set_t *set, char *value ) 332 { 333 struct irc_channel *ic = set->data; 334 struct irc_control_channel *icc = ic->data; 335 336 if( strcmp( value, "all" ) == 0 ) 337 icc->type = IRC_CC_TYPE_DEFAULT; 338 else if( strcmp( value, "rest" ) == 0 ) 339 icc->type = IRC_CC_TYPE_REST; 340 else if( strcmp( value, "group" ) == 0 ) 277 341 icc->type = IRC_CC_TYPE_GROUP; 278 else if( ( icc->account = account_get( ic->irc->b, ic->name + 1 ) ))342 else if( strcmp( value, "account" ) == 0 ) 279 343 icc->type = IRC_CC_TYPE_ACCOUNT; 280 344 else 345 return SET_INVALID; 346 347 return value; 348 } 349 350 static char *set_eval_by_group( set_t *set, char *value ) 351 { 352 struct irc_channel *ic = set->data; 353 struct irc_control_channel *icc = ic->data; 354 355 icc->group = bee_group_by_name( ic->irc->b, value, TRUE ); 281 356 bee_irc_channel_update( ic->irc, ic, NULL ); 357 return g_strdup( icc->group->name ); 358 } 359 360 static gboolean control_channel_free( irc_channel_t *ic ) 361 { 362 struct irc_control_channel *icc = ic->data; 363 364 set_del( &ic->set, "account" ); 365 set_del( &ic->set, "fill_by" ); 366 set_del( &ic->set, "group" ); 367 368 g_free( icc ); 369 ic->data = NULL; 282 370 283 371 return TRUE; … … 292 380 293 381 control_channel_init, 382 control_channel_free, 294 383 }; 295 384
Note: See TracChangeset
for help on using the changeset viewer.