Permalink
Browse files

migrating

  • Loading branch information...
1 parent ec7504c commit a9026f2dd4f6b7bf1063b8d7a69a11f4636775a3 geremy committed Apr 17, 2013
View
@@ -1,193 +1,2 @@
-##### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
-##### http://www.pubnub.com/account
-
-## PubNub 3.1 Real-time Cloud Push API - C-libevent
-
-www.pubnub.com - PubNub Real-time Push Service in the Cloud.
-
-PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
-This is a cloud-based service for broadcasting Real-time messages
-to thousands of web and mobile clients simultaneously.
-
-##### PubNub C-libevent Client API Boiler Plate
-
-
-##### Install following libraries
- libevent-2.0.18-stable
- openssl-0.9.8l
- json-c-0.9
-
- Add Pubnub.h to your project
- Include Pubnub.h to your class header
- #include<Pubnub.h>
-
- Make sure your class follow the Pubnub protocol
-
--------------------------------------------------------------------------------
-c-libevent : (Init)
--------------------------------------------------------------------------------
-```C
- //Initialize pubnub state
- Pubnub_overload1(
- "demo", // PUBLISH_KEY
- "demo", // SUBSCRIBE_KEY
- "", // SECRET_KEY
- "", // CIPHER_KEY (cipher key is optional)
- false // SSL_ON?
- );
-```
-
--------------------------------------------------------------------------------
-c-libevent : (Publish)
--------------------------------------------------------------------------------
-```C
- // Create callback function for publish
- static void publish_callback(json_object *obj)
- {
- printf("\n OUTPUT Message:::%s", json_object_to_json_string(obj));
- write(1, json_object_to_json_string(obj), strlen(json_object_to_json_string(obj)));
- }
- // WAS startup configuration
- #ifdef _WIN32
- WSADATA WSAData;
- WSAStartup(0x101, &WSAData);
- #else
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
- return (1);
- #endif
- // Initialize pubnub state
- Pubnub_overload1("demo","demo","","",false);
- // Create object of structure struct_publish
- struct_publish args = {
- .channel = "hello_world",
- .message="{\"Name\":\"Happy Birthday To You\"}",
- .cb= publish_callback,
- .type = 1
- };
- // Publish Message (string)
- publish( &args );
- // Publish json_object array
- json_object *my_array = json_object_new_array();
- json_object_array_add(my_array, json_object_new_string("hello"));
- struct struct_publish args2 = {
- .channel = "hello_world",
- .message = my_array,
- .cb = publish_callback,
- .type = 2
- };
- // Publish Message (array of json object)
- publish(&args2);
- // Publish json_object
- json_object * my_object = json_object_new_object();
- json_object_object_add(my_object, "some_val", json_object_new_string("hello"));
- struct struct_publish args1 = {
- .channel = "hello_world",
- .message = my_object,
- .cb = publish_callback,
- .type = 3
- };
- // Publish Message (json object)
- publish(&args1);
-```
-
--------------------------------------------------------------------------------
-c-libevent : (Subscribe)
--------------------------------------------------------------------------------
-```C
- // Create callback function for subscribe
- static void subscribe_callback(json_object *obj)
- {
- printf("\n OUTPUT Message:::%s", json_object_to_json_string(obj));
- write(1, json_object_to_json_string(obj), strlen(json_object_to_json_string(obj)));
- }
- // WAS startup configuration
- #ifdef _WIN32
- WSADATA WSAData;
- WSAStartup(0x101, &WSAData);
- #else
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
- return (1);
- #endif
- // Initialize pubnub state
- Pubnub_overload1("demo","demo","","",false);
- // Create object of structure struct_subscribe
- struct_subscribe args = {
- .channel = "hello_world",
- .cb= subscribe_callback
- };
- //call subscribe() method
- subscribe(&args);
-```
-
--------------------------------------------------------------------------------
-c-libevent : (History)
--------------------------------------------------------------------------------
-```C
- // Create callback function for history
- static void history_callback(json_object *obj)
- {
- printf("\n OUTPUT Message:::%s", json_object_to_json_string(obj));
- write(1, json_object_to_json_string(obj), strlen(json_object_to_json_string(obj)));
- }
- // WAS startup configuration
- #ifdef _WIN32
- WSADATA WSAData;
- WSAStartup(0x101, &WSAData);
- #else
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
- return (1);
- #endif
- // Initialize pubnub state
- Pubnub_overload1("demo","demo","demo","",false);
- // Create object of structure struct_history
- struct_history args = {
- .channel = "hello_world",
- .limit=2,
- .cb= history_callback
- };
- //call subscribe() method
- history(args);
-```
-
--------------------------------------------------------------------------------
-c-libevent : (Time)
--------------------------------------------------------------------------------
-```C
- //Get the time
- // WAS startup configuration
- #ifdef _WIN32
- WSADATA WSAData;
- WSAStartup(0x101, &WSAData);
- #else
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
- return (1);
- #endif
- // Initialize pubnub state
- Pubnub_overload1("demo","demo","","",false);
- // call gettime() function
- double time = getTime();
- // Display result
- printf("Time:::%lf",time);
-```
-
--------------------------------------------------------------------------------
-c-libevent : (UUID)
--------------------------------------------------------------------------------
-```C
- // Get UUID
- // WAS startup configuration
- #ifdef _WIN32
- WSADATA WSAData;
- WSAStartup(0x101, &WSAData);
- #else
- if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
- return (1);
- #endif
- // Initialize pubnub state
- Pubnub_overload1("demo","demo","","",false);
- // call uuid()
- char * str_uuid;
- str_uuid = uuid();
- // Display result
- printf("UUID:::%s",str_uuid);
-```
+##The latest PubNub for C/C++ files can be found at:
+https://github.com/pubnub/c
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,73 +0,0 @@
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <event2/event.h>
-#include <event2/buffer.h>
-#include <event2/http.h>
-#include <event2/http_struct.h>
-#include "Pubnub.h"
-
-void context_free(struct request_context *ctx) {
-
- evhttp_connection_free(ctx->cn);
- event_base_free(ctx->base);
-
- if (ctx->buffer)
- evbuffer_free(ctx->buffer);
-
- evhttp_uri_free(ctx->uri);
-
- free(ctx);
-}
-struct evbuffer *request_url(
- char *host,
- short port,
- char *url,
- void *callback
-
-) {
- struct request_context *ctx = 0;
- ctx = calloc(1, sizeof(*ctx));
- if (!ctx)
- return 0;
-
- ctx->uri = evhttp_uri_parse(host);
- if (!ctx->uri)
- return 0;
- printf("\n\n");
- ctx->base = event_base_new();
- if (!ctx->base)
- return 0;
-
- ctx->buffer = evbuffer_new();
-
- if (ctx->cn == NULL)
- {
- if (ctx->cn)
- evhttp_connection_free(ctx->cn);
- ctx->cn = evhttp_connection_base_new(ctx->base, NULL,
- evhttp_uri_get_host(ctx->uri),
- evhttp_uri_get_port(ctx->uri) != -1 ? evhttp_uri_get_port(ctx->uri) : 80);
-
- }
- ctx->req = evhttp_request_new(callback, ctx);
-
- evhttp_add_header(ctx->req->output_headers, "Host", evhttp_uri_get_host(ctx->uri));
- evhttp_add_header(ctx->req->output_headers,"V", "3.1");
- evhttp_add_header(ctx->req->output_headers,"User-Agent", "C-LibEvent");
- evhttp_add_header(ctx->req->output_headers,"Accept-Encoding", "gzip");
-
- evhttp_connection_set_timeout(ctx->cn,-1);
- evhttp_make_request(ctx->cn, ctx->req, EVHTTP_REQ_GET, url);
- event_base_loop(ctx->base ,EVLOOP_NONBLOCK);
- event_base_dispatch(ctx->base);
-
- struct evbuffer *retData = 0;
- if (ctx->ok)
- {
- retData = ctx->buffer;
- ctx->buffer = 0;
- }
- context_free(ctx);
- return retData;
-}
Oops, something went wrong.

0 comments on commit a9026f2

Please sign in to comment.