Exemplo n.º 1
0
// Puts the connection in error status and queues an ERROR frame for output.
//  The causalframe should contain the client frame that casued the error,
//  or NULL if there is none. Takes ownership of the error message bytestring.
void connection_send_error_message(connection *c, frame *causalframe, bytestring *msg)
{
  // Set error connection status
  c->status = CONNECTION_STATUS_STOMP_ERROR;

  // Create an error frame containing the message
  frame *errorframe = frame_new();
  frame_set_command(errorframe, CMD_ERROR);

  // Set error message header
  headerbundle *errorheaders = frame_get_headerbundle(errorframe);
  headerbundle_append_header(errorheaders, bytestring_new_from_string("message"), msg);

  // If there was a causal frame, add details from it
  if (causalframe)
  {
    // Original 'receipt' header is included as the error's 'receipt-id' header
    const bytestring *receipt = headerbundle_get_header_value_by_str(frame_get_headerbundle(causalframe), "receipt");
    if (receipt)
    {
      headerbundle_append_header(errorheaders, bytestring_new_from_string("receipt-id"), bytestring_dup(receipt));;
    }
  }

  // Enqueue frame
  if (!frameserializer_enqueue_frame(c->frameserializer, errorframe))
  {
    log_printf(LOG_LEVEL_ERROR, "Outgoing queue is full, dropping error frame.\n");
    connection_close(c);
    return;
  }

  return;
}
static gboolean internal_load_image(CustomCellRendererFlexi *cr, const char *src, const char *mime_type)
{
    GdkPixbufLoader *loader;
    bytestring_t *bs = bytestring_new_from_string(src);
    GError *err = NULL;

    if (bs==NULL)
    {
        internal_render_error(cr,"No image data.");
        return FALSE;
    }

    if (bs->width!=8)
    {
        internal_render_error(cr,"Image data must be octets.");
        bytestring_free(bs);
        return FALSE;
    }

    loader = gdk_pixbuf_loader_new_with_mime_type(mime_type,&err);

    if (!loader)
        goto internal_load_image_fail;

    if (gdk_pixbuf_loader_write(loader,bs->data,bs->len,&err)==FALSE)
        goto internal_load_image_fail;
    
    err=NULL;

    if (gdk_pixbuf_loader_close(loader,&err)==FALSE)
        goto internal_load_image_fail;

    cr->rendered_type  = RENDER_PIXBUF;
    cr->rendered_value = (GdkPixbuf*) gdk_pixbuf_loader_get_pixbuf(loader);

    g_object_ref(cr->rendered_value);

    g_object_unref(loader);

    bytestring_free(bs);
    return TRUE;

internal_load_image_fail:
    if (err!=NULL)
    {
        internal_render_error(cr,err->message);
        g_error_free(err);
    }
    if (bs) bytestring_free(bs);
    return FALSE;
}
Exemplo n.º 3
0
int main()
{
    bytestring_t *key = bytestring_new_from_string("0123456789ABCDEFh");
    bytestring_t *ctx = bytestring_new(8);
    bytestring_t *src = bytestring_new_from_string("5468652071756663h");
    bytestring_t *dst = bytestring_new(8);
    bytestring_t *clr = bytestring_new(8);

    if (crypto_create_key(ctx,0,key)==CRYPTO_OK)
    {
        fprintf(stderr,"Create key succeeded\n");
    }
    else
    {
        fprintf(stderr,"Create key failed\n");
        return -3;
    }

    if (crypto_encrypt(dst,ctx,src,NULL)==CRYPTO_OK)
    {
        fprintf(stderr,"Crypto: %s\n",bytestring_to_alloc_string(dst));
    }
    else
        fprintf(stderr,"Crypto failed\n");

    if (crypto_decrypt(clr,ctx,dst,NULL)==CRYPTO_OK)
    {
        if (bytestring_is_equal(clr,src))
            fprintf(stderr,"Decrypted clear text matches initial text\n");
        else
            fprintf(stderr,"Crypto: %s\n",bytestring_to_alloc_string(clr));
    }
    else
        fprintf(stderr,"Crypto failed\n");

    return 0;
}
Exemplo n.º 4
0
static void internal_bytes_or_string_push(lua_State* L, const char *src)
{
	if (src)
	{
		switch (src[0]) {
			case 't':
				lua_pushstring(L,src+2);
				break;
			case '8':
			case '4':
			case '1':
				lua_push_bytestring(L,bytestring_new_from_string(src));
				break;
			case 0:
				lua_pushnil(L);
				break;
			default:
				log_printf(LOG_ERROR,"Unrecognized attribute format code (0x%02X) in '%s'",src[0],src);
				luaL_error(L,"Internal error. Please report this bug.");
		}
	}
	else
		lua_pushnil(L);
}