Remove all the pin support for now.
This commit is contained in:
@@ -166,81 +166,10 @@ static void cosmo_handle_message(cosmo *instance, json_t *event) {
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
}
|
||||
|
||||
static void cosmo_handle_pin(cosmo *instance, json_t *event) {
|
||||
json_t *subject = json_object_get(event, "subject");
|
||||
if (!subject) {
|
||||
fprintf(stderr, "pin event without subject\n");
|
||||
return;
|
||||
}
|
||||
|
||||
json_t *id = json_object_get(event, "id");
|
||||
if (!id) {
|
||||
fprintf(stderr, "pin event without id\n");
|
||||
return;
|
||||
}
|
||||
assert(!pthread_mutex_lock(&instance->lock));
|
||||
json_t *subscription = cosmo_find_subscription(instance, subject);
|
||||
if (!subscription) {
|
||||
fprintf(stderr, "pin from unknown subject\n");
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
return;
|
||||
}
|
||||
json_t *pins = json_object_get(subscription, "pins");
|
||||
size_t index;
|
||||
json_t *pin;
|
||||
json_array_foreach(pins, index, pin) {
|
||||
if (json_equal(id, json_object_get(pin, "id"))) {
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
return;
|
||||
}
|
||||
}
|
||||
printf("new pin: %s\n", json_string_value(id));
|
||||
json_array_append(pins, event);
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
}
|
||||
|
||||
static void cosmo_handle_unpin(cosmo *instance, json_t *event) {
|
||||
fprintf(stderr, "unpin event\n");
|
||||
json_t *subject = json_object_get(event, "subject");
|
||||
if (!subject) {
|
||||
fprintf(stderr, "unpin event without subject\n");
|
||||
return;
|
||||
}
|
||||
|
||||
json_t *id = json_object_get(event, "id");
|
||||
if (!id) {
|
||||
fprintf(stderr, "unpin event without id\n");
|
||||
return;
|
||||
}
|
||||
|
||||
assert(!pthread_mutex_lock(&instance->lock));
|
||||
json_t *subscription = cosmo_find_subscription(instance, subject);
|
||||
if (!subscription) {
|
||||
fprintf(stderr, "unpin from unknown subject\n");
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
return;
|
||||
}
|
||||
json_t *pins = json_object_get(subscription, "pins");
|
||||
size_t index;
|
||||
json_t *pin;
|
||||
json_array_foreach(pins, index, pin) {
|
||||
if (json_equal(id, json_object_get(pin, "id"))) {
|
||||
printf("deleted pin: %s\n", json_string_value(id));
|
||||
json_array_remove(pins, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
}
|
||||
|
||||
static void cosmo_handle_event(cosmo *instance, json_t *event) {
|
||||
const char *event_type = json_string_value(json_object_get(event, "event_type"));
|
||||
if (strcmp(event_type, "message") == 0) {
|
||||
cosmo_handle_message(instance, event);
|
||||
} else if (strcmp(event_type, "pin") == 0) {
|
||||
cosmo_handle_pin(instance, event);
|
||||
} else if (strcmp(event_type, "unpin") == 0) {
|
||||
cosmo_handle_unpin(instance, event);
|
||||
} else {
|
||||
fprintf(stderr, "unknown event type: %s\n", event_type);
|
||||
}
|
||||
@@ -424,7 +353,7 @@ void cosmo_subscribe(cosmo *instance, json_t *subject, const json_int_t messages
|
||||
assert(!pthread_mutex_lock(&instance->lock));
|
||||
json_t *subscription = cosmo_find_subscription(instance, subject);
|
||||
if (!subscription) {
|
||||
json_array_append_new(instance->subscriptions, json_pack("{sOs[]s[]}", "subject", subject, "messages", "pins"));
|
||||
json_array_append_new(instance->subscriptions, json_pack("{sOs[]}", "subject", subject, "messages"));
|
||||
}
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
|
||||
@@ -488,20 +417,6 @@ json_t *cosmo_get_last_message(cosmo *instance, json_t *subject) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
json_t *cosmo_get_pins(cosmo *instance, json_t *subject) {
|
||||
assert(!pthread_mutex_lock(&instance->lock));
|
||||
json_t *subscription = cosmo_find_subscription(instance, subject);
|
||||
if (!subscription) {
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
return NULL;
|
||||
}
|
||||
json_t *pins = json_object_get(subscription, "pins");
|
||||
json_t *ret = json_deep_copy(pins);
|
||||
assert(!pthread_mutex_unlock(&instance->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
cosmo *cosmo_create(const char *base_url, const char *client_id) {
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
srandomdev();
|
||||
|
||||
Reference in New Issue
Block a user