int main(void)
{
  burrow_st *burrow;
  client_st client;
  client.message_count = 0;
  client.return_code = 0;
  client.account = "account";
  client.queue = "queue";
  client.messages = (linked list of messages)
  client.current_message = client.messages;

  burrow = burrow_create("http");
  burrow_set_backend_option("server", "burrow.example.com");
  burrow_set_backend_option("port", "1234");

  burrow_set_context(burrow, &client);
  burrow_set_complete_fn(burrow, &_complete);
  burrow_set_log_fn(burrow, &_log);

  /* Insert the first one here to kick the loop off. This only sets start state,
     it doesn't run the loop. */
  message = client.current_messages;
  burrow_create_message(burrow, client.account, client.queue,
    client.current_message->message, NULL, client.current_message->body);

  /* This runs until there are no more tasks. */
  burrow_process(burrow);

  return client->return_code;
}
예제 #2
0
int main(int argc, char **argv)
{
  burrow_st *burrow;
  client_st client;
  msg_st *msg;
  int use_http = 0;

  argc--;
  argv++;

  if (strcmp(argv[0], "http") == 0) {
    use_http = 1;
    argc--;
    argv++;
  }

  if (argc < 4 || argc % 2 != 0)
    return -1;

  client.account = argv[0];
  client.queue = argv[1];
  argc -= 2;
  argv += 2;

  client.messages = NULL;
  client.message_count = 0;

  while (argc) {
    msg = malloc(sizeof(msg_st));
    if (!msg)
      return -2;

    msg->msg_id = argv[0];
    msg->body = (uint8_t *)argv[1];
    msg->body_size = strlen(argv[1]);
    msg->next = client.messages;
    client.messages = msg;
    client.message_count++;

    argc -= 2;
    argv += 2;
  }

  client.return_code = 0;
  client.current_message = client.messages;

  if (use_http == 0) {
    burrow = burrow_create(NULL, "dummy");
    printf("burrow = %p\n", burrow);
  } else {
    burrow = burrow_create(NULL, "http");
    printf("burrow = %p\n", burrow);
    burrow_backend_set_option(burrow, "server", "localhost");
    burrow_backend_set_option(burrow, "port", "8080");
  }

  burrow_set_context(burrow, &client);
  burrow_set_log_fn(burrow, &_log);
  burrow_set_message_fn(burrow, &_message);

  (void) _complete;
  /* Insert the first one here to kick the loop off. This only sets start state,
     it doesn't run the loop. */
  burrow_set_complete_fn(burrow, &_complete);
  msg = client.current_message;
  printf("Calling create_message(%s,%s,%s,\"%s\",..)\n\n", client.account,
	 client.queue, msg->msg_id, msg->body);
  burrow_create_message(burrow, client.account, client.queue,
  			msg->msg_id, msg->body, msg->body_size, NULL);

  /* This runs until there are no more tasks. */
  burrow_process(burrow);

  printf("Ok, now let us see what messages the server has\n");
  /* Now see what the server has */
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_result_t result;
  do {
    result = burrow_process(burrow);
  } while (result != BURROW_OK);

  /* Now get the first message */
  {
    printf("Now we will get the first message\n");
    burrow_filters_st *filters = burrow_filters_create(0,0);

    burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
    burrow_get_message(burrow, client.account, client.queue, 
		       client.messages->msg_id,
		       filters
		       );
    burrow_process(burrow);
  }

  /*
  burrow_destroy(burrow);
  if (use_http == 0) {
    burrow = burrow_create(NULL, "dummy");
    printf("burrow = %p\n", burrow);
  } else {
    burrow = burrow_create(NULL, "http");
    printf("burrow = %p\n", burrow);
    burrow_backend_set_option(burrow, "server", "localhost");
    burrow_backend_set_option(burrow, "port", "8080");
  }
  */

  /* Now update the first message to hide for a couple seconds */
  uint32_t seconds = 3;
  printf("Now we will update the first message to hide it for %d seconds\n",seconds);
  burrow_filters_st *filters = burrow_filters_create(0,0);
  burrow_attributes_st *attributes = burrow_attributes_create(0,0);
  burrow_attributes_set_hide(attributes, seconds);
  burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
  burrow_update_message(burrow, client.account, client.queue, 
			client.messages->msg_id,
			attributes,
			filters
			);
  burrow_process(burrow);

  printf("Get all messages, one should be missing\n");
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_process(burrow);
  printf("Now sleep until the messages should reappear\n");
  sleep(seconds + 1);

  printf("Now get all messages again\n");
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_process(burrow);
  
  printf("Ok, now let us delete one message\n");
  burrow_filters_free(filters);
  filters = burrow_filters_create(0,0);
  burrow_filters_set_detail(filters, BURROW_DETAIL_ALL);
  burrow_delete_message(burrow, client.account, client.queue, client.messages->msg_id,
			NULL);
  burrow_process(burrow);

  printf("Get all messages, one should be missing\n");
  burrow_get_messages(burrow, client.account, client.queue, NULL);
  burrow_process(burrow);

  printf("Get list of accounts\n");
  burrow_set_account_fn(burrow, &_account);
  burrow_get_accounts(burrow, NULL);
  burrow_process(burrow);

  printf("finishing up\n");

  burrow_destroy(burrow);
  exit(0);

  return client.return_code;
}
예제 #3
0
int main(int argc, char **argv)
{
  burrow_st *burrow;
  client_st client;
  msg_st *msg;
  int use_http = 0;

  argc--;
  argv++;

  if (strcmp(argv[0], "http") == 0) {
    use_http = 1;
    argc--;
    argv++;
  }

  if (argc < 4 || argc % 2 != 0)
    return -1;

  client.account = argv[0];
  client.queue = argv[1];
  argc -= 2;
  argv += 2;

  client.messages = NULL;
  client.message_count = 0;

  while (argc) {
    msg = malloc(sizeof(msg_st));
    if (!msg)
      return -2;

    msg->msg_id = argv[0];
    msg->body = (uint8_t *)argv[1];
    msg->body_size = strlen(argv[1]);
    msg->next = client.messages;
    client.messages = msg;
    client.message_count++;

    argc -= 2;
    argv += 2;
  }

  client.return_code = 0;
  client.current_message = client.messages;

  if (use_http == 0) {
    burrow = burrow_create(NULL, "dummy");
    printf("burrow = %p\n", burrow);
  } else {
    burrow = burrow_create(NULL, "http");
    printf("burrow = %p\n", burrow);
    burrow_backend_set_option(burrow, "server", "localhost");
    burrow_backend_set_option(burrow, "port", "8080");
  }

  burrow_set_context(burrow, &client);
  burrow_set_complete_fn(burrow, &_complete);
  burrow_set_log_fn(burrow, &_log);

  /* Insert the first one here to kick the loop off. This only sets start state,
     it doesn't run the loop. */
  msg = client.current_message;
  burrow_create_message(burrow, client.account, client.queue,
    msg->msg_id, msg->body, msg->body_size, NULL);

  /* This runs until there are no more tasks. */
  burrow_process(burrow);
  burrow_destroy(burrow);

  return client.return_code;
}