Libskypekit

Thread-safe C library with synchronous API using asynchronous C++ SkypeKit SDK


Project maintained by railsware Hosted on GitHub Pages — Theme by mattgraham

logo

Libskypekit

Libskypekit is thread-safe C library that provides synchronous SkypeKit API for asynchronous C++ SkypeKit SDK.

Description

The goal of Libskypekit is catch all asynchronous callbacks of SkypeKit SDK and push they as events into one queue.

Then regular synchronous application can pull queue, retrieve each event and do own business logic.

Currently implemented events:

Memory management

For each new event Libskypekit dynamically allocates memory for event structure and for event data and then push event into internal events queue. The queue size is only limited by size of operating system available memory. So after processing certain event you are responsible to free event memory otherwise you will have memory leak. See corresponding API call.

Dependencies

Building

Note. Before build libskypekit you must obtain, unpack and compile SkypeKit SDK first!

$ git clone git@github.com:railsware/libskypekit.git
$ cd libskypekit   
$ DEBUG=1 SKYPEKIT_SDK=path/to/compliled/sdk ./build.sh

DEBUG=1 is optional but gives your opportunity to see what is going in library.

Issues on x86_64

When you have error like:

relocation R_X86_64_32S against `vtable for SEClientSession' can not be used when making a shared object; recompile with -fPIC

Try to recompile SDK with -fPIC :

export CC="gcc -fPIC"
export CXX="g++ -fPIC"
./BuildWithCmake.sh

Installation

To install bin, include, lib files into /usr/local just type:

$ sudo ./install.sh

Probably it's better to create package for your OS and install it via package manager.

API

See skypekit.h

Examples

In examples directory you may find out how you may use libevent.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

#include "skypekit.h"

static struct SkypekitSkype* skype;

void terminate() {
  printf("Terminating skype ...\n");

  skypekit_skype_stop(skype);
  skypekit_skype_free(skype);

  exit(0);
}

void check_error(skypekit_error_t error) {
  if (error != SKYPEKIT_OK) {
    printf("Error: %d\n", error);
    exit(0);
  }
}

int main(int argc, char** argv) {
  struct SkypekitEvent* event;
  struct SkypekitAccountStatusData* account_status_data;
  struct SkypekitChatMessageData* chat_message_data;

  const char* keyfile;
  const char* host;
  int port;
  const char* skypename;
  const char* password;

  if (argc < 6)
  {
    printf("usage: %s <keyfile> <host> <port> <skypename> <password>\n", argv[0]);
    return 1;
  };

  keyfile = argv[1];
  host = argv[2];
  port = atoi(argv[3]);
  skypename = argv[4];
  password = argv[5];

  skype = skypekit_skype_new();

  signal(SIGINT, terminate);

  printf("Initializing skype ...\n");
  skypekit_skype_init(skype, keyfile, host, port, NULL);

  printf("Start skype ...\n");
  check_error(skypekit_skype_start(skype));

  printf("Log in to skype ...\n");
  check_error(skypekit_skype_login(skype, skypename, password));

  printf("Start loop ...\n");

  while(1) {
    event = skypekit_get_event(skype);

    if (!event) {
      sleep(5);
      continue;
    }

    switch(event->type) {
      case SKYPEKIT_EVENT_ACCOUNT_STATUS:
        account_status_data = (struct SkypekitAccountStatusData*) event->data;

        if ( account_status_data->status == SKYPEKIT_ACCOUNT_STATUS_LOGGED_IN) {
          printf("Congrats! We are Logged in!\n");
        }

        if ( account_status_data->status == SKYPEKIT_ACCOUNT_STATUS_LOGGED_OUT && 
            account_status_data->reason != 0) {
          printf("Login error: %d\n", account_status_data->reason);
          terminate();
        }

        break;

      case  SKYPEKIT_EVENT_CHAT_MESSAGE:
        chat_message_data = (struct SkypekitChatMessageData*) event->data;

        printf("Message received %p\n", chat_message_data);
        printf("convo_id=%s\n", chat_message_data->convo_id);
        printf("convo_guid=%s\n", chat_message_data->convo_guid);
        printf("author=%s\n", chat_message_data->author);
        printf("author_displayname=%s\n", chat_message_data->author_displayname);
        printf("timestamp=%d\n", chat_message_data->timestamp);
        printf("body_xml=%s\n", chat_message_data->body_xml);

        if (strcmp(chat_message_data->body_xml,"ping") == 0) {
          skypekit_chat_send_message(skype, chat_message_data->convo_id, "pong", 0);
        }

        break;

      default:
        printf("Unknown event type: %d\n", event->type);
        break;
    }

    skypekit_event_free(event);
  }

  return 0;
}

Build it with:

$ ./build_examples.sh

Run ping_pong example:

$ ./bin/skypekit_ping_pong my.pem 127.0.0.1 8963 my_skypename my_password

Author

Contributors

License