[icq-devel] Status flags



Remy Lebeau gambit47 at yahoo.com
Sat Jun 28 06:20:17 CEST 2003


--- Andrew Lytle <alytle at cogeco.ca> wrote:

> Basically what I want to do is take the info
> from the SNAC (0x03, 0x0B):
> TLV(06): User Status DWORD and figure out
> how I'm supposed to interpret the data.

Have a look at the information from the following
page, works pretty well:

User status 
http://iserverd.khstu.ru/oscar/lists.html#user_status

Below is a snippet of code I use in my own C++ project
to translate the status values into human-readible
strings for display (Note: just ignore the custom
classes I wrote for parsing the raw socket data.  You
should get the general jist of it):

#define TLV_STATUS          0x0006

#define STATUSF_WEBAWARE    0x0001
#define STATUSF_SHOWIP      0x0002
#define STATUSF_BIRTH       0x0008
#define STATUSF_UNK         0x0010
#define STATUSF_WEBFRONT    0x0020
#define STATUSF_DCDISABLED  0x0100
#define STATUSF_DCAUTH      0x1000
#define STATUSF_DCCONTACT   0x2000

#define STATUS_ONLINE       0x0000
#define STATUS_AWAY         0x0001
#define STATUS_DND          0x0002
#define STATUS_NA           0x0004
#define STATUS_OCCUPIED     0x0010
#define STATUS_FFC          0x0020
#define STATUS_INVISIBLE    0x0100

//...

switch( tlv.type )
{
    //...
    case TLV_STATUS:
    {
        TIMString flags =
StatusFlagsToString(tlv.ReadWORD());
        TIMString status =
StatusToString(tlv.ReadWORD());
        //...
        break;
    }
    //...
}

typedef struct
{
    IM_USHORT flag;
    IM_STRING desc;
} FlagDesc;

IM_STRING StatusFlagsToString(IM_USHORT flags)
{
    static const FlagDesc arr[] = {
        {STATUSF_WEBAWARE, "Web Aware"},
        {STATUSF_SHOWIP, "Show IP"},
        {STATUSF_BIRTH, "Birthday"},
        {STATUSF_UNK, "Unknown"},
        {STATUSF_WEBFRONT, "Web Front"},
        {STATUSF_DCDISABLED, "DC Disabled"},
        {STATUSF_DCAUTH, "DC Upon Auth"},
        {STATUSF_DCCONTACT, "DC w/ Contacts"}
    };
    static const FlagDescCount =
(sizeof(arr)/sizeof(arr[0]));
    static IMDataManager dm;

    dm.Clear();

    for(IM_BYTE b = 0; b < FlagDescCount; ++b)
    {
        if( flags & arr[b].flag )
        {
            if( dm.pos != 0 )
                dm.WriteRaw(", ", 2);
            dm.WriteString(arr[b].desc);
        }
    }

    return (IM_STRING)dm.data;
}

typedef struct
{
    IM_USHORT status;
    IM_STRING desc;
} StatusDesc;

IM_STRING StatusToString(IM_USHORT status)
{
    static const StatusDesc arr[] = {
        {STATUS_OFFLINE, "Offline"},
        {STATUS_ONLINE, "Online"},
        {STATUS_AWAY, "Away"},
        {STATUS_DND, "DND"},
        {STATUS_NA, "NA"},
        {STATUS_OCCUPIED, "Occupied"},
        {STATUS_FFC, "Free for Chat"},
        {STATUS_INVISIBLE, "Invisible"}
    };
    static const StatusDescCount =
(sizeof(arr)/sizeof(arr[0]));

    for(IM_BYTE b = 0; b < StatusDescCount; ++b)
    {
        if( status == arr[b].status )
            return arr[b].desc;
    }

    return NULL;
}


Gambit

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com



More information about the icq-devel mailing list