annotate plugins/fortuneprofile.pl @ 13143:a1d5f154585b

[gaim-migrate @ 15506] SF Patch #1415729 from Evan "I've received a few crash reports in which yahoo_receivefile_connected() crashes in g_strdup_printf() as a result of being passed a NULL string. There are only two arguments to that call... xd->path and xd->host. If either were null for some reason, we couldn't receive a file, anyways, since we need both to do the HTTP GET request. This patch checks against NULL for both and cancels the transfer in the same manner it would be canceled if fed a negative (invalid) source." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Tue, 07 Feb 2006 01:43:27 +0000
parents bc45ab9756b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
1 # FORTUNE PROFILE
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
2 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
3 # Sets your AIM profile to a fortune (with a header and footer of your
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
4 # choice).
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
5 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
6
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
7 # By Sean Egan
12406
bc45ab9756b5 [gaim-migrate @ 14713]
Richard Laager <rlaager@wiktel.com>
parents: 7733
diff changeset
8 # seanegan@gmail.com
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
9 # AIM: SeanEgn
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
10 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
11 # Updated by Nathan Conrad, 31 January 2002
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
12 # Changes:
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
13 # * Fortunes have HTML tabs and newlines
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
14 # AIM: t98502
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
15 # ICQ: 16106363
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
16 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
17 # Updated by Mark Doliner, 15 October 2002
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
18 # Changes:
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
19 # * Modified to work with the changed perl interface of gaim 0.60
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
20 # * Fixed a bug where your info would be set to nothing if you had
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
21 # no pre and no post message
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
22 # AIM: lbdash
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
23 #
6899
6de3b775d5b1 [gaim-migrate @ 7446]
Christian Hammond <chipx86@chipx86.com>
parents: 6593
diff changeset
24 # Updated by Christian Hammond, 20 August 2003
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
25 # Changes:
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
26 # * Modified to work with the changed perl interface of gaim 0.68
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
27 # AIM: ChipX86
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
28
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
29 # Copyright (C) 2001 Sean Egan
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
30
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
31 # This program is free software; you can redistribute it and/or modify
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
32 # it under the terms of the GNU General Public License as published by
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
33 # the Free Software Foundation; either version 2 of the License, or
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
34 # (at your option) any later version.
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
35 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
36 # This program is distributed in the hope that it will be useful,
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
37 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
39 # GNU General Public License for more details.
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
40 #
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
41 # You should have received a copy of the GNU General Public License
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
42 # along with this program; if not, write to the Free Software
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
43 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
44
6529
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
45 use Gaim;
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
46
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
47 %PLUGIN_INFO = (
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
48 perl_api_version => 2,
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
49 name => "Fortune Profile",
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
50 version => "3.4",
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
51 summary => "Sets your AIM profile to a fortune (with a header and footer of your choice).",
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
52 description => "Sets your AIM profile to a fortune (with a header and footer of your choice).",
12406
bc45ab9756b5 [gaim-migrate @ 14713]
Richard Laager <rlaager@wiktel.com>
parents: 7733
diff changeset
53 author => "Sean Egan <seanegan\@gmail.com>",
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
54 url => "http://gaim.sf.net/",
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
55
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
56 load => "plugin_load"
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
57 );
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
58
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
59 sub plugin_init {
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
60 return %PLUGIN_INFO;
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
61 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
62
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
63 sub plugin_load {
6529
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
64 $plugin = shift;
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
65
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
66 $tab = "&nbsp;";
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
67 $tab = $tab . $tab . $tab . $tab;
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
68 $nl = "<BR>";
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
69
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
70 $seconds = 30; # Delay before updating away messages.
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
71 $max = 1020; # Max length of an profile. It should be
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
72 # 1024, but I am being safe
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
73 $pre_message = ""; # This gets added before the fortune
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
74
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
75 $post_message ="";
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
76
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
77 $len = 0;
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
78 if ($pre_message ne "") {
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
79 $len += length( $pre_message . "---$nl" );
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
80 }
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
81 if ($post_message ne "") {
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
82 $len += length("---$nl" . $post_message);
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
83 }
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
84
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
85 # Command to get dynamic message from
6529
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
86 $command = "fortune -sn " . ($max - $len);
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
87
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
88 # output the first message and start the timers...
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
89 # This is done as a timeout to prevent attempts to set the
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
90 # profile before logging in.
6593
540edd51051b [gaim-migrate @ 7117]
Christian Hammond <chipx86@chipx86.com>
parents: 6529
diff changeset
91 Gaim::timeout_add($plugin, $seconds, \&update_away, 0);
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
92 }
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
93
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
94 sub update_away {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
95 # The fortunes are expanded into HTML (the tabs and newlines) which
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
96 # causes the -s option of fortune to be a little bit meaningless. This
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
97 # will loop until it gets a fortune of a good size (after expansion).
6519
7f0fffa1077b [gaim-migrate @ 7036]
Christian Hammond <chipx86@chipx86.com>
parents: 6125
diff changeset
98
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
99 do {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
100 do { #It's a while loop because it doesn't always work for some reason
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
101 $fortune = `$command`;
6125
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
102 if ($? == -1) {
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
103 return;
e8204ffce9f8 [gaim-migrate @ 6599]
Mark Doliner <mark@kingant.net>
parents: 5487
diff changeset
104 }
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
105 } while ($fortune eq "");
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
106 $fortune =~ s/\n/$nl/g;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
107 $fortune =~ s/\t/$tab/g;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
108 } while ((length($fortune) + $len ) > $max);
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
109
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
110 $message = $fortune;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
111 if ($pre_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
112 $message = $pre_message . "---$nl" . $message;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
113 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
114 if ($post_message ne "") {
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
115 $message = $message . "---$nl" . $post_message ;
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
116 }
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
117
6529
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
118 foreach $account (Gaim::accounts()) {
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
119 if ($account->is_connected()) {
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
120 $account->set_user_info($message);
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
121 }
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
122 }
e4e87ffd9f14 [gaim-migrate @ 7046]
Christian Hammond <chipx86@chipx86.com>
parents: 6519
diff changeset
123
6593
540edd51051b [gaim-migrate @ 7117]
Christian Hammond <chipx86@chipx86.com>
parents: 6529
diff changeset
124 Gaim::timeout_add($plugin, $seconds, \&update_away, 0);
3706
8cd8deb4234d [gaim-migrate @ 3839]
Mark Doliner <mark@kingant.net>
parents:
diff changeset
125 }