Changes in protocols/nogaim.c [1b221e0:3e57660]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
r1b221e0 r3e57660 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 06Wilmer van der Gaast and others *4 * Copyright 2002-2010 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 39 39 40 40 static int remove_chat_buddy_silent( struct groupchat *b, const char *handle ); 41 static char *format_timestamp( irc_t *irc, time_t msg_ts ); 41 42 42 43 GSList *connections; … … 98 99 void register_protocol (struct prpl *p) 99 100 { 100 protocols = g_list_append(protocols, p); 101 int i; 102 gboolean refused = global.conf->protocols != NULL; 103 104 for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++) 105 { 106 if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0) 107 refused = FALSE; 108 } 109 110 if (refused) 111 log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name); 112 else 113 protocols = g_list_append(protocols, p); 101 114 } 102 115 … … 120 133 extern void byahoo_initmodule(); 121 134 extern void jabber_initmodule(); 122 extern void twitter_initmodule();123 135 124 136 #ifdef WITH_MSN … … 136 148 #ifdef WITH_JABBER 137 149 jabber_initmodule(); 138 #endif139 140 #ifdef WITH_TWITTER141 twitter_initmodule();142 150 #endif 143 151 … … 273 281 ic->flags |= OPT_LOGGED_IN; 274 282 275 /* Also necessary when we're not away, at least for some of the 276 protocols. */ 277 imc_set_away( ic, u->away ); 283 /* Necessary to send initial presence status, even if we're not away. */ 284 imc_away_send_update( ic ); 278 285 279 286 /* Apparently we're connected successfully, so reset the … … 377 384 /* list.c */ 378 385 379 void imcb_add_buddy( struct im_connection *ic, c har *handle,char *group )386 void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group ) 380 387 { 381 388 user_t *u; … … 451 458 } 452 459 453 void imcb_rename_buddy( struct im_connection *ic, c har *handle,char *realname )460 void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname ) 454 461 { 455 462 user_t *u = user_findhandle( ic, handle ); 463 char *set; 456 464 457 465 if( !u || !realname ) return; … … 466 474 imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); 467 475 } 468 } 469 470 void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group ) 476 477 set = set_getstr( &ic->acc->set, "nick_source" ); 478 if( strcmp( set, "handle" ) != 0 ) 479 { 480 char *name = g_strdup( realname ); 481 482 if( strcmp( set, "first_name" ) == 0 ) 483 { 484 int i; 485 for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {} 486 name[i] = '\0'; 487 } 488 489 imcb_buddy_nick_hint( ic, handle, name ); 490 491 g_free( name ); 492 } 493 } 494 495 void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group ) 471 496 { 472 497 user_t *u; … … 478 503 /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM 479 504 modules to suggest a nickname for a handle. */ 480 void imcb_buddy_nick_hint( struct im_connection *ic, c har *handle,char *nick )505 void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick ) 481 506 { 482 507 user_t *u = user_findhandle( ic, handle ); … … 623 648 oo = u->online; 624 649 625 if( u->away ) 626 { 627 g_free( u->away ); 628 u->away = NULL; 629 } 650 g_free( u->away ); 651 g_free( u->status_msg ); 652 u->away = u->status_msg = NULL; 630 653 631 654 if( ( flags & OPT_LOGGED_IN ) && !u->online ) … … 665 688 } 666 689 } 667 /* else waste_any_state_information_for_now(); */ 690 else 691 { 692 u->status_msg = g_strdup( message ); 693 } 668 694 669 695 /* LISPy... */ … … 690 716 } 691 717 692 void imcb_buddy_msg( struct im_connection *ic, c har *handle, char *msg, uint32_t flags, time_t sent_at )718 void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at ) 693 719 { 694 720 irc_t *irc = ic->irc; 695 char *wrapped ;721 char *wrapped, *ts; 696 722 user_t *u; 697 723 … … 735 761 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 736 762 strip_html( msg ); 737 763 764 if( ( ts = format_timestamp( irc, sent_at ) ) ) 765 { 766 char *new = g_strconcat( ts, msg, NULL ); 767 g_free( ts ); 768 ts = msg = new; 769 } 770 738 771 wrapped = word_wrap( msg, 425 ); 739 772 irc_msgfrom( irc, u->nick, wrapped ); 740 773 g_free( wrapped ); 774 g_free( ts ); 741 775 } 742 776 … … 823 857 } 824 858 825 void imcb_chat_msg( struct groupchat *c, c har *who, char *msg, uint32_t flags, time_t sent_at )859 void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at ) 826 860 { 827 861 struct im_connection *ic = c->ic; … … 842 876 if( c && u ) 843 877 { 844 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); 878 char *ts = format_timestamp( ic->irc, sent_at ); 879 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped ); 880 g_free( ts ); 845 881 } 846 882 else … … 895 931 /* buddy_chat.c */ 896 932 897 void imcb_chat_add_buddy( struct groupchat *b, c har *handle )933 void imcb_chat_add_buddy( struct groupchat *b, const char *handle ) 898 934 { 899 935 user_t *u = user_findhandle( b->ic, handle ); … … 930 966 931 967 /* This function is one BIG hack... :-( EREWRITE */ 932 void imcb_chat_remove_buddy( struct groupchat *b, c har *handle,char *reason )968 void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason ) 933 969 { 934 970 user_t *u; … … 1036 1072 } 1037 1073 1038 1039 1074 char *set_eval_timezone( set_t *set, char *value ) 1075 { 1076 char *s; 1077 1078 if( strcmp( value, "local" ) == 0 || 1079 strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 ) 1080 return value; 1081 1082 /* Otherwise: +/- at the beginning optional, then one or more numbers, 1083 possibly followed by a colon and more numbers. Don't bother bound- 1084 checking them since users are free to shoot themselves in the foot. */ 1085 s = value; 1086 if( *s == '+' || *s == '-' ) 1087 s ++; 1088 1089 /* \d+ */ 1090 if( !isdigit( *s ) ) 1091 return SET_INVALID; 1092 while( *s && isdigit( *s ) ) s ++; 1093 1094 /* EOS? */ 1095 if( *s == '\0' ) 1096 return value; 1097 1098 /* Otherwise, colon */ 1099 if( *s != ':' ) 1100 return SET_INVALID; 1101 s ++; 1102 1103 /* \d+ */ 1104 if( !isdigit( *s ) ) 1105 return SET_INVALID; 1106 while( *s && isdigit( *s ) ) s ++; 1107 1108 /* EOS */ 1109 return *s == '\0' ? value : SET_INVALID; 1110 } 1111 1112 static char *format_timestamp( irc_t *irc, time_t msg_ts ) 1113 { 1114 time_t now_ts = time( NULL ); 1115 struct tm now, msg; 1116 char *set; 1117 1118 /* If the timestamp is <= 0 or less than a minute ago, discard it as 1119 it doesn't seem to add to much useful info and/or might be noise. */ 1120 if( msg_ts <= 0 || msg_ts > now_ts - 60 ) 1121 return NULL; 1122 1123 set = set_getstr( &irc->set, "timezone" ); 1124 if( strcmp( set, "local" ) == 0 ) 1125 { 1126 localtime_r( &now_ts, &now ); 1127 localtime_r( &msg_ts, &msg ); 1128 } 1129 else 1130 { 1131 int hr, min = 0, sign = 60; 1132 1133 if( set[0] == '-' ) 1134 { 1135 sign *= -1; 1136 set ++; 1137 } 1138 else if( set[0] == '+' ) 1139 { 1140 set ++; 1141 } 1142 1143 if( sscanf( set, "%d:%d", &hr, &min ) >= 1 ) 1144 { 1145 msg_ts += sign * ( hr * 60 + min ); 1146 now_ts += sign * ( hr * 60 + min ); 1147 } 1148 1149 gmtime_r( &now_ts, &now ); 1150 gmtime_r( &msg_ts, &msg ); 1151 } 1152 1153 if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday ) 1154 return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ", 1155 msg.tm_hour, msg.tm_min, msg.tm_sec ); 1156 else 1157 return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d " 1158 "%02d:%02d:%02d\x02]\x02 ", 1159 msg.tm_year + 1900, msg.tm_mon, msg.tm_mday, 1160 msg.tm_hour, msg.tm_min, msg.tm_sec ); 1161 } 1040 1162 1041 1163 /* The plan is to not allow straight calls to prpl functions anymore, but do … … 1075 1197 } 1076 1198 1077 static char *imc_away_alias_find( GList *gcm, char *away ); 1078 1079 int imc_set_away( struct im_connection *ic, char *away ) 1080 { 1081 GList *m, *ms; 1082 char *s; 1083 1084 if( !away ) away = ""; 1085 ms = m = ic->acc->prpl->away_states( ic ); 1086 1087 while( m ) 1088 { 1089 if( *away ) 1090 { 1091 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) 1092 break; 1093 } 1094 else 1095 { 1096 if( g_strcasecmp( m->data, "Available" ) == 0 ) 1097 break; 1098 if( g_strcasecmp( m->data, "Online" ) == 0 ) 1099 break; 1100 } 1101 m = m->next; 1102 } 1103 1104 if( m ) 1105 { 1106 ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); 1107 } 1108 else 1109 { 1110 s = imc_away_alias_find( ms, away ); 1111 if( s ) 1112 { 1113 ic->acc->prpl->set_away( ic, s, away ); 1114 if( set_getbool( &ic->irc->set, "debug" ) ) 1115 imcb_log( ic, "Setting away state to %s", s ); 1116 } 1117 else 1118 ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); 1119 } 1120 1121 return( 1 ); 1199 static char *imc_away_state_find( GList *gcm, char *away, char **message ); 1200 1201 int imc_away_send_update( struct im_connection *ic ) 1202 { 1203 char *away, *msg = NULL; 1204 1205 away = set_getstr( &ic->acc->set, "away" ) ? 1206 : set_getstr( &ic->irc->set, "away" ); 1207 if( away && *away ) 1208 { 1209 GList *m = ic->acc->prpl->away_states( ic ); 1210 msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; 1211 away = imc_away_state_find( m, away, &msg ) ? : m->data; 1212 } 1213 else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE ) 1214 { 1215 away = NULL; 1216 msg = set_getstr( &ic->acc->set, "status" ) ? 1217 : set_getstr( &ic->irc->set, "status" ); 1218 } 1219 1220 ic->acc->prpl->set_away( ic, away, msg ); 1221 1222 return 1; 1122 1223 } 1123 1224 … … 1134 1235 }; 1135 1236 1136 static char *imc_away_ alias_find( GList *gcm, char *away)1237 static char *imc_away_state_find( GList *gcm, char *away, char **message ) 1137 1238 { 1138 1239 GList *m; 1139 1240 int i, j; 1140 1241 1242 for( m = gcm; m; m = m->next ) 1243 if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) 1244 { 1245 /* At least the Yahoo! module works better if message 1246 contains no data unless it adds something to what 1247 we have in state already. */ 1248 if( strlen( m->data ) == strlen( away ) ) 1249 *message = NULL; 1250 1251 return m->data; 1252 } 1253 1141 1254 for( i = 0; *imc_away_alias_list[i]; i ++ ) 1142 1255 { 1256 int keep_message; 1257 1143 1258 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1144 1259 if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) 1260 { 1261 keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] ); 1145 1262 break; 1263 } 1146 1264 1147 1265 if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ … … 1151 1269 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1152 1270 { 1153 m = gcm; 1154 while( m ) 1155 { 1271 for( m = gcm; m; m = m->next ) 1156 1272 if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) 1157 return( imc_away_alias_list[i][j] ); 1158 m = m->next; 1159 } 1160 } 1161 } 1162 1163 return( NULL ); 1273 { 1274 if( !keep_message ) 1275 *message = NULL; 1276 1277 return imc_away_alias_list[i][j]; 1278 } 1279 } 1280 1281 /* No need to look further, apparently this state doesn't 1282 have any good alias for this protocol. */ 1283 break; 1284 } 1285 1286 return NULL; 1164 1287 } 1165 1288
Note: See TracChangeset
for help on using the changeset viewer.