Mercurial > pidgin.yaz
comparison libpurple/protocols/mxit/profile.c @ 28903:69aa4660401a
Initial addition of the MXit protocol plugin, provided by the MXit folks
themselves.
author | John Bailey <rekkanoryo@rekkanoryo.org> |
---|---|
date | Sun, 08 Nov 2009 23:55:56 +0000 |
parents | |
children | 259bbfb423d4 |
comparison
equal
deleted
inserted
replaced
28901:13e668ef158d | 28903:69aa4660401a |
---|---|
1 /* | |
2 * MXit Protocol libPurple Plugin | |
3 * | |
4 * -- user profile's -- | |
5 * | |
6 * Andrew Victor <libpurple@mxit.com> | |
7 * | |
8 * (C) Copyright 2009 MXit Lifestyle (Pty) Ltd. | |
9 * <http://www.mxitlifestyle.com> | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
24 */ | |
25 | |
26 #include <ctype.h> | |
27 #include <string.h> | |
28 | |
29 #include "purple.h" | |
30 | |
31 #include "mxit.h" | |
32 #include "profile.h" | |
33 #include "roster.h" | |
34 | |
35 | |
36 /*------------------------------------------------------------------------ | |
37 * Returns true if it is a valid date. | |
38 * | |
39 * @param bday Date-of-Birth string | |
40 * @return TRUE if valid, else FALSE | |
41 */ | |
42 gboolean validateDate( const char* bday ) | |
43 { | |
44 struct tm* tm; | |
45 time_t t; | |
46 int cur_year; | |
47 int max_days[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | |
48 char date[16]; | |
49 int year; | |
50 int month; | |
51 int day; | |
52 | |
53 /* validate length */ | |
54 if ( strlen( bday ) != 10 ) { | |
55 return FALSE; | |
56 } | |
57 | |
58 /* validate the format */ | |
59 if ( ( !isdigit( bday[0] ) ) || ( !isdigit( bday[1] ) ) || ( !isdigit( bday[2] ) ) || ( !isdigit( bday[3] ) ) || /* year */ | |
60 ( bday[4] != '-' ) || | |
61 ( !isdigit( bday[5] ) ) || ( !isdigit( bday[6] ) ) || /* month */ | |
62 ( bday[7] != '-' ) || | |
63 ( !isdigit( bday[8] ) ) || ( !isdigit( bday[9] ) ) ) { /* day */ | |
64 return FALSE; | |
65 } | |
66 | |
67 /* convert */ | |
68 t = time( NULL ); | |
69 tm = gmtime( &t ); | |
70 cur_year = tm->tm_year + 1900; | |
71 memcpy( date, bday, 10 ); | |
72 date[4] = '\0'; | |
73 date[7] = '\0'; | |
74 date[10] = '\0'; | |
75 year = atoi( &date[0] ); | |
76 month = atoi( &date[5] ); | |
77 day = atoi( &date[8] ); | |
78 | |
79 /* validate month */ | |
80 if ( ( month < 1 ) || ( month > 12 ) ) { | |
81 return FALSE; | |
82 } | |
83 | |
84 /* validate day */ | |
85 if ( ( day < 1 ) || ( day > max_days[month] ) ) { | |
86 return FALSE; | |
87 } | |
88 | |
89 /* validate year */ | |
90 if ( ( year < ( cur_year - 100 ) ) || ( year >= cur_year ) ) { | |
91 /* you are either tooo old or tooo young to join mxit... sorry */ | |
92 return FALSE; | |
93 } | |
94 | |
95 /* special case leap-year */ | |
96 if ( ( year % 4 != 0 ) && ( month == 2 ) && ( day == 29 ) ) { | |
97 /* cannot have 29 days in February in non leap-years! */ | |
98 return FALSE; | |
99 } | |
100 | |
101 return TRUE; | |
102 } | |
103 | |
104 | |
105 /*------------------------------------------------------------------------ | |
106 * Display the profile information. | |
107 * | |
108 * @param session The MXit session object | |
109 * @param username The username who's profile information this is | |
110 * @param profile The profile | |
111 */ | |
112 void mxit_show_profile( struct MXitSession* session, const char* username, struct MXitProfile* profile ) | |
113 { | |
114 PurpleNotifyUserInfo* info = purple_notify_user_info_new(); | |
115 struct contact* contact = NULL; | |
116 PurpleBuddy* buddy; | |
117 | |
118 buddy = purple_find_buddy( session->acc, username ); | |
119 if ( buddy ) { | |
120 purple_notify_user_info_add_pair( info, _( "Alias" ), buddy->alias ); | |
121 purple_notify_user_info_add_section_break( info ); | |
122 contact = buddy->proto_data; | |
123 } | |
124 | |
125 purple_notify_user_info_add_pair( info, _( "Nick Name" ), profile->nickname ); | |
126 purple_notify_user_info_add_pair( info, _( "Birthday" ), profile->birthday ); | |
127 purple_notify_user_info_add_pair( info, _( "Gender" ), profile->male ? _( "Male" ) : _( "Female" ) ); | |
128 purple_notify_user_info_add_pair( info, _( "Hidden Number" ), profile->hidden ? _( "Yes" ) : _( "No" ) ); | |
129 | |
130 purple_notify_user_info_add_section_break( info ); | |
131 | |
132 /* optional information */ | |
133 purple_notify_user_info_add_pair( info, _( "Title" ), profile->title ); | |
134 purple_notify_user_info_add_pair( info, _( "First Name" ), profile->firstname ); | |
135 purple_notify_user_info_add_pair( info, _( "Last Name" ), profile->lastname ); | |
136 purple_notify_user_info_add_pair( info, _( "Email" ), profile->email ); | |
137 | |
138 purple_notify_user_info_add_section_break( info ); | |
139 | |
140 if ( contact ) { | |
141 /* presence */ | |
142 purple_notify_user_info_add_pair( info, _( "Status" ), mxit_convert_presence_to_name( contact->presence ) ); | |
143 | |
144 /* mood */ | |
145 if ( contact->mood != MXIT_MOOD_NONE ) | |
146 purple_notify_user_info_add_pair( info, _( "Mood" ), mxit_convert_mood_to_name( contact->mood ) ); | |
147 else | |
148 purple_notify_user_info_add_pair( info, _( "Mood" ), _( "None" ) ); | |
149 | |
150 /* status message */ | |
151 if ( contact->statusMsg ) | |
152 purple_notify_user_info_add_pair( info, _( "Status Message" ), contact->statusMsg ); | |
153 | |
154 /* subscription type */ | |
155 purple_notify_user_info_add_pair( info, _( "Subscription" ), mxit_convert_subtype_to_name( contact->subtype ) ); | |
156 } | |
157 | |
158 purple_notify_userinfo( session->con, username, info, NULL, NULL ); | |
159 purple_notify_user_info_destroy( info ); | |
160 } |