logger example

 

Logger example simply puts every event into a file called log.txt.

 

plugin.cpp

#include <windows.h>

#include <stdio.h>

#include <time.h>

#include <islprontoapi/islpronto_plugin.h>



void connection_info(FILE *f, ISLProntoConnectionInfo info)

{

 if(info) {

#define INFO(_x) \

         if(ISLProntoStringCxx value = ISLPronto->ConnectionInfoGetKey(info, _x)) \

                 fwprintf(f, L"%s = [%s]\n", L#_x, value.AsWide());



         INFO(ISLPRONTO_CONNECTION_INFO_ID);

         INFO(ISLPRONTO_CONNECTION_INFO_SERVER);

         INFO(ISLPRONTO_CONNECTION_INFO_USERNAME);

         INFO(ISLPRONTO_CONNECTION_INFO_DESCRIPTION);



#undef INFO

 }

}



void client(void *, int event_type, ISLProntoClientInfo info)

{

 if(FILE *f = _wfopen(L"log.txt", L"a, ccs=UTF-16LE")) {

         {

                 time_t now = time(0);

                 const wchar_t *t = L"unknown event";

                 switch(event_type) {

                         case ISLPRONTO_CLIENT_EVENT_NEW:

                                 t = L"new client";

                                 break;

                         case ISLPRONTO_CLIENT_EVENT_UPDATE:

                                 t = L"client info update";

                                 break;

                         case ISLPRONTO_CLIENT_EVENT_GONE:

                                 t = L"client is gone";

                                 break;

                 }

                 fwprintf(f, L"%sEVENT = %s\n", _wctime(&now), t);

         }



#define INFO(_x) \

 if(ISLProntoStringCxx value = ISLPronto->ClientInfoGetKey(info, _x)) \

         fwprintf(f, L"%s = [%s]\n", L#_x, value.AsWide());



         connection_info(f, ISLPronto->ClientInfoAccessConnectionInfo(info));

         INFO(ISLPRONTO_CLIENT_INFO_ID); // do not use as primary key, it's unique only until reboot of ISL Conference Proxy

         INFO(ISLPRONTO_CLIENT_INFO_NAME);

         INFO(ISLPRONTO_CLIENT_INFO_EMAIL);

         INFO(ISLPRONTO_CLIENT_INFO_TIME);

         INFO(ISLPRONTO_CLIENT_INFO_URL);

         INFO(ISLPRONTO_CLIENT_INFO_REFERRER);

         INFO(ISLPRONTO_CLIENT_INFO_BROWSER);

         INFO(ISLPRONTO_CLIENT_INFO_GEO_COUNTRY_CODE);

         INFO(ISLPRONTO_CLIENT_INFO_GEO_COUNTRY);

         INFO(ISLPRONTO_CLIENT_INFO_GEO_CITY);

         INFO(ISLPRONTO_CLIENT_INFO_IP);

         INFO(ISLPRONTO_CLIENT_INFO_INTERNAL_IP);

         INFO(ISLPRONTO_CLIENT_INFO_REVERSE_DNS);

         INFO(ISLPRONTO_CLIENT_INFO_CHAT_ID); // use this as primary key, because it is always unique



         if(ISLProntoCustomFields fields = ISLPronto->ClientInfoGetCustomFields(info)) {

                 for(int i=0; i<ISLPronto->CustomFieldsCount(fields); ++i) {

                         if(ISLProntoStringCxx key = ISLPronto->CustomFieldsGetKey(fields, i)) {

                                 if(ISLProntoStringCxx value = ISLPronto->CustomFieldsGetValue(fields, i))

                                         fwprintf(f, L"custom field [%s]=[%s]\n", key.AsWide(), value.AsWide());

                         }

                 }

                 // if you know the key name, you can use:

                 //{

                 //        ISLProntoStringCxx key = ISLPronto->StringFromUtf8("f1");

                 //        if(ISLProntoStringCxx value = ISLPronto->CustomFieldsGetKeyValue(fields, key.Get()))

                 //                fwprintf(f, L"custom field [f1]=[%s]\n", value.AsWide());

                 //}

                 ISLPronto->FreeCustomFields(fields);

         }



#undef INFO



         fwprintf(f, L"--\n");

         fclose(f);

 }

}



void user(void *, int event_type, ISLProntoUserInfo info)

{

 if(FILE *f = _wfopen(L"log.txt", L"a, ccs=UTF-16LE")) {

         {

                 time_t now = time(0);

                 const wchar_t *t = L"unknown event";

                 switch(event_type) {

                         case ISLPRONTO_USER_EVENT_NEW:

                                 t = L"new user";

                                 break;

                         case ISLPRONTO_USER_EVENT_UPDATE:

                                 t = L"user info update";

                                 break;

                         case ISLPRONTO_USER_EVENT_GONE:

                                 t = L"user is gone";

                                 break;

                 }

                 fwprintf(f, L"%sEVENT = %s\n", _wctime(&now), t);

         }



         {

                 const wchar_t *t = L"unknown";

                 switch(ISLPronto->UserInfoGetStatus(info)) {

                         case ISLPRONTO_USER_STATUS_AVAILABLE: t = L"available"; break;

                         case ISLPRONTO_USER_STATUS_BUSY: t = L"busy"; break;

                         case ISLPRONTO_USER_STATUS_UNAVAILABLE: t = L"unavailable"; break;

                 }

                 fwprintf(f, L"status: %s\n", t);

         }



         fwprintf(f, L"myself: %d\n", ISLPronto->UserInfoIsMyself(info));



#define INFO(_x) \

 if(ISLProntoStringCxx value = ISLPronto->UserInfoGetKey(info, _x)) \

         fwprintf(f, L"%s = [%s]\n", L#_x, value.AsWide());



         connection_info(f, ISLPronto->UserInfoAccessConnectionInfo(info));

         INFO(ISLPRONTO_USER_INFO_ID); // do not use as primary key, it's unique only until reboot of ISL Conference Proxy

         INFO(ISLPRONTO_USER_INFO_MYSELF);

         INFO(ISLPRONTO_USER_INFO_NAME);

         INFO(ISLPRONTO_USER_INFO_EMAIL);

         INFO(ISLPRONTO_USER_INFO_PHOTO);

         INFO(ISLPRONTO_USER_INFO_GEO_COUNTRY_CODE);

         INFO(ISLPRONTO_USER_INFO_GEO_COUNTRY);

         INFO(ISLPRONTO_USER_INFO_GEO_CITY);



         if(ISLProntoStringSet s = ISLPronto->UserInfoGetChatMembership(info)) {

                 for(ISLProntoStringCxx id; id = ISLPronto->StringSetIterateGet(s); ISLPronto->StringSetIterateAdvance(s))

                         fwprintf(f, L"member of chat [%s]\n", id.AsWide());

                 ISLPronto->FreeStringSet(s);

         }



         if(ISLProntoStringSet s = ISLPronto->UserInfoGetFilterMembership(info)) {

                 // if you know the name of the filter:

                 //{

                 //        ISLProntoStringCxx key = ISLPronto->StringFromUtf8("sales");

                 //        if(ISLPronto->StringSetContains(s, key.Get())) {

                 //                ...

                 //        }

                 //}



                 for(ISLProntoStringCxx id; id = ISLPronto->StringSetIterateGet(s); ISLPronto->StringSetIterateAdvance(s))

                         fwprintf(f, L"member of filter [%s]\n", id.AsWide());

                 ISLPronto->FreeStringSet(s);

         }



#undef INFO



         fwprintf(f, L"--\n");

         fclose(f);

 }

}



void chat(void *, ISLProntoChatInfo info)

{

 if(FILE *f = _wfopen(L"log.txt", L"a, ccs=UTF-16LE")) {

         {

                 time_t now = time(0);

                 fwprintf(f, L"%sEVENT = chat update\n", _wctime(&now));

         }



         fwprintf(f, L"I am in chat = %d\n", ISLPronto->ChatInfoIAmMember(info));

         fwprintf(f, L"I am only one in chat = %d\n", ISLPronto->ChatInfoIAmOnlyOneInChat(info));



#define INFO(_x) \

 if(ISLProntoStringCxx value = ISLPronto->ChatInfoGetKey(info, _x)) \

         fwprintf(f, L"%s = [%s]\n", L#_x, value.AsWide());



         connection_info(f, ISLPronto->ChatInfoAccessConnectionInfo(info));

         INFO(ISLPRONTO_CHAT_INFO_ID); // use this as primary key, because it is always unique



         if(ISLProntoStringSet s = ISLPronto->ChatInfoGetMemberClients(info)) {

                 for(ISLProntoStringCxx id; id = ISLPronto->StringSetIterateGet(s); ISLPronto->StringSetIterateAdvance(s))

                         fwprintf(f, L"member client [%s]\n", id.AsWide());

                 ISLPronto->FreeStringSet(s);

         }



         if(ISLProntoStringSet s = ISLPronto->ChatInfoGetMemberUsers(info)) {

                 for(ISLProntoStringCxx id; id = ISLPronto->StringSetIterateGet(s); ISLPronto->StringSetIterateAdvance(s))

                         fwprintf(f, L"member user [%s]\n", id.AsWide());

                 ISLPronto->FreeStringSet(s);

         }



#undef INFO



         fwprintf(f, L"--\n");

         fclose(f);

 }

}



void message(void *, ISLProntoMessageInfo info)

{

 if(FILE *f = _wfopen(L"log.txt", L"a, ccs=UTF-16LE")) {

         {

                 time_t now = time(0);

                 fwprintf(f, L"%sEVENT = message\n", _wctime(&now));

         }



         {

                 const wchar_t *t = L"?";

                 switch(ISLPronto->MessageInfoGetType(info)) {

                         case ISLPRONTO_MESSAGE_TYPE_SUPPORTER_COMMENT: t = L"supporter comment"; break;

                         case ISLPRONTO_MESSAGE_TYPE_SUPPORTER: t = L"supporter"; break;

                         case ISLPRONTO_MESSAGE_TYPE_CLIENT: t = L"client"; break;

                         case ISLPRONTO_MESSAGE_TYPE_SYSTEM: t = L"system"; break;

                         case ISLPRONTO_MESSAGE_TYPE_RESET_CHAT: t = L"reset chat"; break;

                         case ISLPRONTO_MESSAGE_TYPE_RESET_CHAT_DONE: t = L"reset chat done"; break;

                 }

                 fwprintf(f, L"message type = %s\n", t);

         }



         fwprintf(f, L"replay message = %d\n", ISLPronto->MessageInfoIsReplay(info));



#define INFO(_x) \

 if(ISLProntoStringCxx value = ISLPronto->MessageInfoGetKey(info, _x)) \

         fwprintf(f, L"%s = [%s]\n", L#_x, value.AsWide());



         if(ISLProntoConnectionInfo cinfo = ISLPronto->MessageInfoAccessConnectionInfo(info)) {

                 if(ISLProntoStringCxx value = ISLPronto->ConnectionInfoGetKey(cinfo, ISLPRONTO_CONNECTION_INFO_ID))

                         fwprintf(f, L"connection id = %s\n", value.AsWide());

         }



         if(ISLProntoUserInfo cinfo = ISLPronto->MessageInfoAccessUserInfo(info)) {

                 if(ISLProntoStringCxx value = ISLPronto->UserInfoGetKey(cinfo, ISLPRONTO_USER_INFO_ID))

                         fwprintf(f, L"user id = %s\n", value.AsWide());

         }



         if(ISLProntoClientInfo cinfo = ISLPronto->MessageInfoAccessClientInfo(info)) {

                 if(ISLProntoStringCxx value = ISLPronto->ClientInfoGetKey(cinfo, ISLPRONTO_CLIENT_INFO_ID))

                         fwprintf(f, L"client id = %s\n", value.AsWide());

         }



         INFO(ISLPRONTO_MESSAGE_INFO_TIME);

         INFO(ISLPRONTO_MESSAGE_INFO_RAWHTML);

         INFO(ISLPRONTO_MESSAGE_INFO_TEXT);



#undef INFO



         fwprintf(f, L"--\n");

         fclose(f);

 }

}



void ISLProntoPluginStart()

{

 // uncomment if you wish to debug the plugin

 //ISLPronto->AttachDebugger();

 ISLPronto->RegisterClientEventHandler(client, 0);

 ISLPronto->RegisterUserEventHandler(user, 0);

 ISLPronto->RegisterChatEventHandler(chat, 0);

 ISLPronto->RegisterMessageEventHandler(message, 0);

}

ISLPRONTO_PLUGIN(ISLProntoPluginStart)

Was this article helpful?