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