Mercurial > pidgin.yaz
comparison src/plugin.c @ 10682:c604c88a7530
[gaim-migrate @ 12228]
This is the changes I made to plugin loading to oldstatus a few days ago.
Luckily plugin.c is compiled before gtkstatusbox.c, so I can at least
test that this compiles. It's basically the same code as oldstatus,
so hopefully it'll work. Here's the commit message from that commit:
sf patch #1118347, from Richard Laager, with changes by me
This changes how plugins are loaded. Here's the run-down:
1. If a plugin is loaded, the plugin's full file name + path is
stored in prefs.xml
2. When we attempt to load any saved plugins, we first try to load
the plugin using the full path name.
3. If that fails, we strip the plugin's path and just use the base
name. When doing this, if the plugin is a .so or .dll we also
strip the plugin's extension.
This change will hopefully allow people to use the same prefs.xml
on Windows and "lunix" and have their list of loaded plugins
not get cleared.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 11 Mar 2005 03:54:23 +0000 |
parents | 1a97d5e88d12 |
children | b7f0bc436179 |
comparison
equal
deleted
inserted
replaced
10681:d29fae081061 | 10682:c604c88a7530 |
---|---|
79 | 79 |
80 return (strncmp(filename + len, ext, extlen) == 0); | 80 return (strncmp(filename + len, ext, extlen) == 0); |
81 } | 81 } |
82 | 82 |
83 static gboolean | 83 static gboolean |
84 is_native(const char *filename) | |
85 { | |
86 const char *last_period; | |
87 | |
88 last_period = strrchr(filename, '.'); | |
89 if (last_period == NULL) | |
90 return FALSE; | |
91 | |
92 return !(strcmp(last_period, GAIM_PLUGIN_EXT_WIN32) & | |
93 strcmp(last_period, GAIM_PLUGIN_EXT_HPUX) & | |
94 strcmp(last_period, GAIM_PLUGIN_EXT_UNIX)); | |
95 } | |
96 | |
97 static char * | |
98 gaim_plugin_get_basename(const char *filename) | |
99 { | |
100 const char *basename; | |
101 const char *last_period; | |
102 | |
103 basename = strrchr(filename, G_DIR_SEPARATOR); | |
104 if (basename != NULL) | |
105 basename++; | |
106 else | |
107 basename = filename; | |
108 | |
109 if (is_native(basename) && | |
110 ((last_period = strrchr(basename, '.')) != NULL)) | |
111 return g_strndup(basename, (last_period - basename)); | |
112 | |
113 return g_strdup(basename); | |
114 } | |
115 | |
116 static gboolean | |
84 loader_supports_file(GaimPlugin *loader, const char *filename) | 117 loader_supports_file(GaimPlugin *loader, const char *filename) |
85 { | 118 { |
86 GList *exts; | 119 GList *exts; |
87 | 120 |
88 for (exts = GAIM_PLUGIN_LOADER_INFO(loader)->exts; exts != NULL; exts = exts->next) { | 121 for (exts = GAIM_PLUGIN_LOADER_INFO(loader)->exts; exts != NULL; exts = exts->next) { |
841 | 874 |
842 files = gaim_prefs_get_string_list(key); | 875 files = gaim_prefs_get_string_list(key); |
843 | 876 |
844 for (f = files; f; f = f->next) | 877 for (f = files; f; f = f->next) |
845 { | 878 { |
846 char *filename = g_path_get_basename(f->data); | 879 char *filename; |
847 GaimPlugin *plugin = NULL; | 880 char *basename; |
848 | 881 GaimPlugin *plugin; |
849 if (filename != NULL) | 882 |
850 { | 883 if (f->data == NULL) |
851 if ((plugin = gaim_plugins_find_with_basename(filename)) != NULL) | 884 continue; |
852 { | 885 |
853 gaim_debug_info("plugins", "Loading saved plugin %s\n", | 886 filename = f->data; |
854 filename); | 887 /* |
855 gaim_plugin_load(plugin); | 888 * We don't know if the filename uses Windows or Unix path |
856 } | 889 * separators (because people might be sharing a prefs.xml |
857 else | 890 * file across systems), so we find the last occurrence |
858 { | 891 * of either. |
859 gaim_debug_error("plugins", "Unable to find saved plugin %s\n", | 892 */ |
860 filename); | 893 basename = strrchr(filename, '/'); |
861 } | 894 if ((basename == NULL) || (basename < strrchr(filename, '\\'))) |
862 | 895 basename = strrchr(filename, '\\'); |
863 g_free(filename); | 896 if (basename != NULL) |
897 basename++; | |
898 | |
899 if ((plugin = gaim_plugins_find_with_filename(filename)) != NULL) | |
900 { | |
901 gaim_debug_info("plugins", "Loading saved plugin %s\n", | |
902 plugin->path); | |
903 gaim_plugin_load(plugin); | |
904 } | |
905 else if ((plugin = gaim_plugins_find_with_basename(basename)) != NULL) | |
906 { | |
907 gaim_debug_info("plugins", "Loading saved plugin %s\n", | |
908 plugin->path); | |
909 gaim_plugin_load(plugin); | |
910 } | |
911 else | |
912 { | |
913 gaim_debug_error("plugins", "Unable to find saved plugin %s\n", | |
914 filename); | |
864 } | 915 } |
865 | 916 |
866 g_free(f->data); | 917 g_free(f->data); |
867 } | 918 } |
868 | 919 |
1119 GaimPlugin * | 1170 GaimPlugin * |
1120 gaim_plugins_find_with_basename(const char *basename) | 1171 gaim_plugins_find_with_basename(const char *basename) |
1121 { | 1172 { |
1122 GaimPlugin *plugin; | 1173 GaimPlugin *plugin; |
1123 GList *l; | 1174 GList *l; |
1175 char *basename_no_ext; | |
1176 char *tmp; | |
1124 | 1177 |
1125 g_return_val_if_fail(basename != NULL, NULL); | 1178 g_return_val_if_fail(basename != NULL, NULL); |
1126 | 1179 |
1180 basename_no_ext = gaim_plugin_get_basename(basename); | |
1181 | |
1127 for (l = plugins; l != NULL; l = l->next) | 1182 for (l = plugins; l != NULL; l = l->next) |
1128 { | 1183 { |
1129 char *tmp; | |
1130 | |
1131 plugin = (GaimPlugin *)l->data; | 1184 plugin = (GaimPlugin *)l->data; |
1132 | 1185 |
1133 if (plugin->path != NULL) { | 1186 if (plugin->path != NULL) { |
1134 tmp = g_path_get_basename(plugin->path); | 1187 tmp = gaim_plugin_get_basename(plugin->path); |
1135 if (!strcmp(tmp, basename)) { | 1188 if (!strcmp(tmp, basename_no_ext)) |
1189 { | |
1136 g_free(tmp); | 1190 g_free(tmp); |
1191 g_free(basename_no_ext); | |
1137 return plugin; | 1192 return plugin; |
1138 } | 1193 } |
1139 g_free(tmp); | 1194 g_free(tmp); |
1140 } | 1195 } |
1141 } | 1196 } |
1142 | 1197 |
1198 g_free(basename_no_ext); | |
1199 | |
1143 return NULL; | 1200 return NULL; |
1144 } | 1201 } |
1145 | 1202 |
1146 GaimPlugin * | 1203 GaimPlugin * |
1147 gaim_plugins_find_with_id(const char *id) | 1204 gaim_plugins_find_with_id(const char *id) |