Changes in protocols/nogaim.c [3e57660:1b221e0]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/nogaim.c
r3e57660 r1b221e0 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 10Wilmer van der Gaast and others *4 * Copyright 2002-2006 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 );42 41 43 42 GSList *connections; … … 99 98 void register_protocol (struct prpl *p) 100 99 { 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); 100 protocols = g_list_append(protocols, p); 114 101 } 115 102 … … 133 120 extern void byahoo_initmodule(); 134 121 extern void jabber_initmodule(); 122 extern void twitter_initmodule(); 135 123 136 124 #ifdef WITH_MSN … … 148 136 #ifdef WITH_JABBER 149 137 jabber_initmodule(); 138 #endif 139 140 #ifdef WITH_TWITTER 141 twitter_initmodule(); 150 142 #endif 151 143 … … 281 273 ic->flags |= OPT_LOGGED_IN; 282 274 283 /* Necessary to send initial presence status, even if we're not away. */ 284 imc_away_send_update( ic ); 275 /* Also necessary when we're not away, at least for some of the 276 protocols. */ 277 imc_set_away( ic, u->away ); 285 278 286 279 /* Apparently we're connected successfully, so reset the … … 384 377 /* list.c */ 385 378 386 void imcb_add_buddy( struct im_connection *ic, c onst char *handle, constchar *group )379 void imcb_add_buddy( struct im_connection *ic, char *handle, char *group ) 387 380 { 388 381 user_t *u; … … 458 451 } 459 452 460 void imcb_rename_buddy( struct im_connection *ic, c onst char *handle, constchar *realname )453 void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname ) 461 454 { 462 455 user_t *u = user_findhandle( ic, handle ); 463 char *set;464 456 465 457 if( !u || !realname ) return; … … 474 466 imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); 475 467 } 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 ) 468 } 469 470 void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group ) 496 471 { 497 472 user_t *u; … … 503 478 /* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM 504 479 modules to suggest a nickname for a handle. */ 505 void imcb_buddy_nick_hint( struct im_connection *ic, c onst char *handle, constchar *nick )480 void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) 506 481 { 507 482 user_t *u = user_findhandle( ic, handle ); … … 648 623 oo = u->online; 649 624 650 g_free( u->away ); 651 g_free( u->status_msg ); 652 u->away = u->status_msg = NULL; 625 if( u->away ) 626 { 627 g_free( u->away ); 628 u->away = NULL; 629 } 653 630 654 631 if( ( flags & OPT_LOGGED_IN ) && !u->online ) … … 688 665 } 689 666 } 690 else 691 { 692 u->status_msg = g_strdup( message ); 693 } 667 /* else waste_any_state_information_for_now(); */ 694 668 695 669 /* LISPy... */ … … 716 690 } 717 691 718 void imcb_buddy_msg( struct im_connection *ic, c onst char *handle, char *msg, uint32_t flags, time_t sent_at )692 void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at ) 719 693 { 720 694 irc_t *irc = ic->irc; 721 char *wrapped , *ts;695 char *wrapped; 722 696 user_t *u; 723 697 … … 761 735 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) ) 762 736 strip_html( msg ); 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 737 771 738 wrapped = word_wrap( msg, 425 ); 772 739 irc_msgfrom( irc, u->nick, wrapped ); 773 740 g_free( wrapped ); 774 g_free( ts );775 741 } 776 742 … … 857 823 } 858 824 859 void imcb_chat_msg( struct groupchat *c, c onst char *who, char *msg, uint32_t flags, time_t sent_at )825 void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at ) 860 826 { 861 827 struct im_connection *ic = c->ic; … … 876 842 if( c && u ) 877 843 { 878 char *ts = format_timestamp( ic->irc, sent_at ); 879 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped ); 880 g_free( ts ); 844 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped ); 881 845 } 882 846 else … … 931 895 /* buddy_chat.c */ 932 896 933 void imcb_chat_add_buddy( struct groupchat *b, c onst char *handle )897 void imcb_chat_add_buddy( struct groupchat *b, char *handle ) 934 898 { 935 899 user_t *u = user_findhandle( b->ic, handle ); … … 966 930 967 931 /* This function is one BIG hack... :-( EREWRITE */ 968 void imcb_chat_remove_buddy( struct groupchat *b, c onst char *handle, constchar *reason )932 void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason ) 969 933 { 970 934 user_t *u; … … 1072 1036 } 1073 1037 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 } 1038 1039 1162 1040 1163 1041 /* The plan is to not allow straight calls to prpl functions anymore, but do … … 1197 1075 } 1198 1076 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; 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 ); 1223 1122 } 1224 1123 … … 1235 1134 }; 1236 1135 1237 static char *imc_away_ state_find( GList *gcm, char *away, char **message)1136 static char *imc_away_alias_find( GList *gcm, char *away ) 1238 1137 { 1239 1138 GList *m; 1240 1139 int i, j; 1241 1140 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 message1246 contains no data unless it adds something to what1247 we have in state already. */1248 if( strlen( m->data ) == strlen( away ) )1249 *message = NULL;1250 1251 return m->data;1252 }1253 1254 1141 for( i = 0; *imc_away_alias_list[i]; i ++ ) 1255 1142 { 1256 int keep_message;1257 1258 1143 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1259 1144 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] );1262 1145 break; 1263 }1264 1146 1265 1147 if( !imc_away_alias_list[i][j] ) /* If we reach the end, this row */ … … 1269 1151 for( j = 0; imc_away_alias_list[i][j]; j ++ ) 1270 1152 { 1271 for( m = gcm; m; m = m->next ) 1153 m = gcm; 1154 while( m ) 1155 { 1272 1156 if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) 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; 1157 return( imc_away_alias_list[i][j] ); 1158 m = m->next; 1159 } 1160 } 1161 } 1162 1163 return( NULL ); 1287 1164 } 1288 1165
Note: See TracChangeset
for help on using the changeset viewer.