Mercurial > pidgin
comparison src/util.c @ 5872:059d95c67cda
[gaim-migrate @ 6304]
The legendary Header File Cleanup! Files now only include what they need.
This should reduce the number of files that must recompile when a header
file changes. It's a lot nicer. Trust me on it. I also added a couple new
header files. I hope I didn't break TOO much!
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Sat, 14 Jun 2003 23:21:02 +0000 |
| parents | bd0d0e89cac3 |
| children | 964e4f94fc56 |
comparison
equal
deleted
inserted
replaced
| 5871:508adf90fbb9 | 5872:059d95c67cda |
|---|---|
| 17 * along with this program; if not, write to the Free Software | 17 * along with this program; if not, write to the Free Software |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #ifdef HAVE_CONFIG_H | 22 #include "internal.h" |
| 23 #include <config.h> | 23 |
| 24 #endif | 24 #include "conversation.h" |
| 25 | 25 #include "debug.h" |
| 26 #ifndef _WIN32 | |
| 27 #include <unistd.h> | |
| 28 #include <sys/time.h> | |
| 29 #include <sys/wait.h> | |
| 30 #else | |
| 31 #include <direct.h> | |
| 32 #include <io.h> | |
| 33 #endif | |
| 34 | |
| 35 #include <errno.h> | |
| 36 #include <stdio.h> | |
| 37 #include <stdlib.h> | |
| 38 #include <sys/types.h> | |
| 39 #include <sys/stat.h> | |
| 40 #include <string.h> | |
| 41 #include <ctype.h> | |
| 42 #ifdef HAVE_ICONV | |
| 43 #include <iconv.h> | |
| 44 #endif | |
| 45 #include <math.h> | |
| 46 #include "gaim.h" | |
| 47 #include "prpl.h" | 26 #include "prpl.h" |
| 48 #include "prefs.h" | 27 #include "prefs.h" |
| 49 | |
| 50 #ifndef _WIN32 | |
| 51 #include <sys/socket.h> | |
| 52 #include <arpa/inet.h> | |
| 53 #else | |
| 54 #include "win32dep.h" | |
| 55 #endif | |
| 56 | |
| 57 #ifndef MAXPATHLEN | |
| 58 #define MAXPATHLEN 1024 | |
| 59 #endif | |
| 60 | 28 |
| 61 static char home_dir[MAXPATHLEN]; | 29 static char home_dir[MAXPATHLEN]; |
| 62 | 30 |
| 63 char *full_date() | 31 char *full_date() |
| 64 { | 32 { |
| 1005 } | 973 } |
| 1006 | 974 |
| 1007 return fp; | 975 return fp; |
| 1008 } | 976 } |
| 1009 | 977 |
| 1010 /* AIM URI's ARE FUN :-D */ | |
| 1011 const char * | |
| 1012 handle_uri(char *uri) | |
| 1013 { | |
| 1014 const char *username; | |
| 1015 GString *str; | |
| 1016 GList *conn; | |
| 1017 GaimConnection *gc = NULL; | |
| 1018 GaimAccount *account; | |
| 1019 | |
| 1020 gaim_debug(GAIM_DEBUG_INFO, "handle_uri", "Handling URI: %s\n", uri); | |
| 1021 | |
| 1022 /* Well, we'd better check to make sure we have at least one | |
| 1023 AIM account connected. */ | |
| 1024 for (conn = gaim_connections_get_all(); conn != NULL; conn = conn->next) { | |
| 1025 gc = conn->data; | |
| 1026 account = gaim_connection_get_account(gc); | |
| 1027 username = gaim_account_get_username(account); | |
| 1028 | |
| 1029 if (gaim_account_get_protocol(account) == GAIM_PROTO_OSCAR && | |
| 1030 username != NULL && isalpha(*username)) { | |
| 1031 | |
| 1032 break; | |
| 1033 } | |
| 1034 } | |
| 1035 | |
| 1036 if (gc == NULL) | |
| 1037 return _("Not connected to AIM"); | |
| 1038 | |
| 1039 /* aim:goim?screenname=screenname&message=message */ | |
| 1040 if (!g_ascii_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { | |
| 1041 char *who, *what; | |
| 1042 GaimConversation *c; | |
| 1043 uri = uri + strlen("aim:goim?"); | |
| 1044 | |
| 1045 if (!(who = strstr(uri, "screenname="))) { | |
| 1046 return _("No screenname given."); | |
| 1047 } | |
| 1048 /* spaces are encoded as +'s */ | |
| 1049 who = who + strlen("screenname="); | |
| 1050 str = g_string_new(NULL); | |
| 1051 while (*who && (*who != '&')) { | |
| 1052 g_string_append_c(str, *who == '+' ? ' ' : *who); | |
| 1053 who++; | |
| 1054 } | |
| 1055 who = g_strdup(str->str); | |
| 1056 g_string_free(str, TRUE); | |
| 1057 | |
| 1058 what = strstr(uri, "message="); | |
| 1059 if (what) { | |
| 1060 what = what + strlen("message="); | |
| 1061 str = g_string_new(NULL); | |
| 1062 while (*what && (*what != '&' || !g_ascii_strncasecmp(what, "&", 5))) { | |
| 1063 g_string_append_c(str, *what == '+' ? ' ' : *what); | |
| 1064 what++; | |
| 1065 } | |
| 1066 what = g_strdup(str->str); | |
| 1067 g_string_free(str, TRUE); | |
| 1068 } | |
| 1069 | |
| 1070 c = gaim_conversation_new(GAIM_CONV_IM, gc->account, who); | |
| 1071 g_free(who); | |
| 1072 | |
| 1073 if (what) { | |
| 1074 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(c); | |
| 1075 | |
| 1076 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1); | |
| 1077 g_free(what); | |
| 1078 } | |
| 1079 } else if (!g_ascii_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) { | |
| 1080 char *who, *group; | |
| 1081 uri = uri + strlen("aim:addbuddy?"); | |
| 1082 /* spaces are encoded as +'s */ | |
| 1083 | |
| 1084 if (!(who = strstr(uri, "screenname="))) { | |
| 1085 return _("No screenname given."); | |
| 1086 } | |
| 1087 who = who + strlen("screenname="); | |
| 1088 str = g_string_new(NULL); | |
| 1089 while (*who && (*who != '&')) { | |
| 1090 g_string_append_c(str, *who == '+' ? ' ' : *who); | |
| 1091 who++; | |
| 1092 } | |
| 1093 who = g_strdup(str->str); | |
| 1094 g_string_free(str, TRUE); | |
| 1095 | |
| 1096 group = strstr(uri, "group="); | |
| 1097 if (group) { | |
| 1098 group = group + strlen("group="); | |
| 1099 str = g_string_new(NULL); | |
| 1100 while (*group && (*group != '&' || !g_ascii_strncasecmp(group, "&", 5))) { | |
| 1101 g_string_append_c(str, *group == '+' ? ' ' : *group); | |
| 1102 group++; | |
| 1103 } | |
| 1104 group = g_strdup(str->str); | |
| 1105 g_string_free(str, TRUE); | |
| 1106 } | |
| 1107 | |
| 1108 gaim_debug(GAIM_DEBUG_MISC, "handle_uri", "who: %s\n", who); | |
| 1109 show_add_buddy(gc, who, group, NULL); | |
| 1110 g_free(who); | |
| 1111 if (group) | |
| 1112 g_free(group); | |
| 1113 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { | |
| 1114 char *room; | |
| 1115 GHashTable *components; | |
| 1116 int exch = 5; | |
| 1117 | |
| 1118 uri = uri + strlen("aim:gochat?"); | |
| 1119 /* spaces are encoded as +'s */ | |
| 1120 | |
| 1121 if (!(room = strstr(uri, "roomname="))) { | |
| 1122 return _("No roomname given."); | |
| 1123 } | |
| 1124 room = room + strlen("roomname="); | |
| 1125 str = g_string_new(NULL); | |
| 1126 while (*room && (*room != '&')) { | |
| 1127 g_string_append_c(str, *room == '+' ? ' ' : *room); | |
| 1128 room++; | |
| 1129 } | |
| 1130 room = g_strdup(str->str); | |
| 1131 g_string_free(str, TRUE); | |
| 1132 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
| 1133 g_free); | |
| 1134 g_hash_table_replace(components, g_strdup("room"), room); | |
| 1135 g_hash_table_replace(components, g_strdup("exchange"), | |
| 1136 g_strdup_printf("%d", exch)); | |
| 1137 | |
| 1138 serv_join_chat(gc, components); | |
| 1139 g_hash_table_destroy(components); | |
| 1140 } else { | |
| 1141 return _("Invalid AIM URI"); | |
| 1142 } | |
| 1143 | |
| 1144 | |
| 1145 return NULL; | |
| 1146 } | |
| 1147 | |
| 1148 char *gaim_try_conv_to_utf8(const char *str) | 978 char *gaim_try_conv_to_utf8(const char *str) |
| 1149 { | 979 { |
| 1150 int converted; | 980 int converted; |
| 1151 char *utf8; | 981 char *utf8; |
| 1152 | 982 |
