Beispiel #1
0
/**
 * Document-method: MessagePack::Unpacker#initialize
 *
 * call-seq:
 *   MessagePack::Unpacker.new(stream = nil)
 *
 * Creates instance of MessagePack::Unpacker.
 *
 * You can specify a _stream_ for input stream.
 * It is required to implement *sysread* or *readpartial* method.
 *
 * With the input stream, buffers will be feeded into the deserializer automatically.
 *
 * Without the input stream, use *feed* method manually. Or you can manage the buffer manually
 * with *execute*, *finished?*, *data* and *reset* methods.
 */
static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self)
{
	VALUE stream;
	switch(argc) {
	case 0:
		stream = Qnil;
		break;
	case 1:
		stream = argv[0];
		break;
	default:
		rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
	}

	UNPACKER(self, mp);
	template_init(mp);
	mp->user.finished = 0;
	mp->user.offset = 0;
	mp->user.buffer.size = 0;
	mp->user.buffer.free = 0;
	mp->user.buffer.ptr = NULL;
	mp->user.stream = stream;
	mp->user.streambuf = rb_str_buf_new(MSGPACK_UNPACKER_BUFFER_RESERVE_SIZE);
	mp->user.stream_append_method = append_method_of(stream);
	return self;
}
Beispiel #2
0
bool msgpack_unpack_next(msgpack_unpacked* result,
		const char* data, size_t len, size_t* off)
{
	msgpack_unpacked_destroy(result);

	size_t noff = 0;
	if(off != NULL) { noff = *off; }

	if(len <= noff) {
		return false;
	}

	msgpack_zone* z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);

	template_context ctx;
	template_init(&ctx);

	ctx.user.z = z;
	ctx.user.referenced = false;

	int e = template_execute(&ctx, data, len, &noff);
	if(e <= 0) {
		msgpack_zone_free(z);
		return false;
	}

	if(off != NULL) { *off = noff; }

	result->zone = z;
	result->data = template_data(&ctx);

	return true;
}
Beispiel #3
0
void msgpack_unpacker_reset(msgpack_unpacker* mpac)
{
    template_init(CTX_CAST(mpac->ctx));

    /* Fluent Bit: refer to unpack.h for more details about this field */
    mpac->last_parsed = mpac->parsed;

    // don't reset referenced flag
    mpac->parsed = 0;
}
Beispiel #4
0
msgpack_unpack_return
msgpack_unpack_next(msgpack_unpacked* result,
        const char* data, size_t len, size_t* off)
{
    size_t noff = 0;
    msgpack_unpacked_destroy(result);

    if(off != NULL) { noff = *off; }

    if(len <= noff) {
        return MSGPACK_UNPACK_CONTINUE;
    }

    if (!result->zone) {
        result->zone = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
    }

    if (!result->zone) {
        return MSGPACK_UNPACK_NOMEM_ERROR;
    }
    else {
        int e;
        template_context ctx;
        template_init(&ctx);

        ctx.user.z = result->zone;
        ctx.user.referenced = false;

        e = template_execute(&ctx, data, len, &noff);
        if(e < 0) {
            msgpack_zone_free(result->zone);
            result->zone = NULL;
            return MSGPACK_UNPACK_PARSE_ERROR;
        }


        if(e == 0) {
            return MSGPACK_UNPACK_CONTINUE;
        }

        if(off != NULL) { *off = noff; }

        result->data = template_data(&ctx);

        return MSGPACK_UNPACK_SUCCESS;
    }
}
Beispiel #5
0
bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size)
{
    char* buffer;
    void* ctx;
    msgpack_zone* z;

    if(initial_buffer_size < COUNTER_SIZE) {
        initial_buffer_size = COUNTER_SIZE;
    }

    buffer = (char*)malloc(initial_buffer_size);
    if(buffer == NULL) {
        return false;
    }

    ctx = malloc(sizeof(template_context));
    if(ctx == NULL) {
        free(buffer);
        return false;
    }

    z = msgpack_zone_new(MSGPACK_ZONE_CHUNK_SIZE);
    if(z == NULL) {
        free(ctx);
        free(buffer);
        return false;
    }

    mpac->buffer = buffer;
    mpac->used = COUNTER_SIZE;
    mpac->free = initial_buffer_size - mpac->used;
    mpac->off = COUNTER_SIZE;
    mpac->parsed = 0;
    mpac->last_parsed = 0;
    mpac->initial_buffer_size = initial_buffer_size;
    mpac->z = z;
    mpac->ctx = ctx;

    init_count(mpac->buffer);

    template_init(CTX_CAST(mpac->ctx));
    CTX_CAST(mpac->ctx)->user.z = mpac->z;
    CTX_CAST(mpac->ctx)->user.referenced = false;

    return true;
}
Beispiel #6
0
msgpack_unpack_return
msgpack_unpack(const char* data, size_t len, size_t* off,
               msgpack_zone* result_zone, msgpack_object* result)
{
    size_t noff = 0;
    if(off != NULL) {
        noff = *off;
    }

    if(len <= noff) {
        // FIXME
        return MSGPACK_UNPACK_CONTINUE;
    }

    template_context ctx;
    template_init(&ctx);

    ctx.user.z = result_zone;
    ctx.user.referenced = false;

    int e = template_execute(&ctx, data, len, &noff);
    if(e < 0) {
        return MSGPACK_UNPACK_PARSE_ERROR;
    }

    if(off != NULL) {
        *off = noff;
    }

    if(e == 0) {
        return MSGPACK_UNPACK_CONTINUE;
    }

    *result = template_data(&ctx);

    if(noff < len) {
        return MSGPACK_UNPACK_EXTRA_BYTES;
    }

    return MSGPACK_UNPACK_SUCCESS;
}
Beispiel #7
0
int
main(void)
{
	unsigned int    logged_in = 0;
	char           *username, *password = { NULL };
	cookie_t *cookies = cookies_init();
	cookie_t *our_cookie = cookie(COOKIE_NAME);
	char *template_path = "templates/portal";	
	cookie_t *c = NULL; 
	
	// Check for session cookie
	if (our_cookie) { // && cookie_valid(our_cookie)) {
		logged_in = 1;
		c = our_cookie;
		c->expires = 3600;
	} else {
	// New connection or expired...
		get_params();
		username = param("username");
		password = param("password");
		logged_in = CheckUserCredentials(username, password);
		if (logged_in) {
			c = cookie_create(username, password);
			c->expires = 3600;
		} else
			WebBork("HERE");
	}

	cookie_add(cookies, c);

	content_type_cookies("text/html", cookies);
	template_t    **t = template_init();
	template_input(t, "USERNAME", username);
	template_output(template_path, t);
	template_free(t);

	exit(EXIT_SUCCESS);
}
Beispiel #8
0
void msgpack_unpacker_reset(msgpack_unpacker* mpac)
{
    template_init(CTX_CAST(mpac->ctx));
    // don't reset referenced flag
    mpac->parsed = 0;
}
Beispiel #9
0
int main (int argc, char *argv[]) {
    /* set up i18n */
    bindtextdomain (PACKAGE, LOCALEDIR);
    setlocale (LC_ALL, "");
    textdomain (PACKAGE);

    GError* error = NULL;
    GOptionContext* context = g_option_context_new ("files");
    g_option_context_add_main_entries (context, entries, PACKAGE);
    g_option_context_parse (context, &argc, &argv, &error);
    if (error) g_error("%s\n", error->message);

    /* initialize GTK */
    g_thread_init (NULL);
    gdk_threads_init ();
    gtk_init (&argc, &argv);
    GError* ui_error = NULL;
    GtkBuilder* builder = gtk_builder_new ();
    gchar* ui = g_build_filename (DATADIR, "ui", "gummi.glade", NULL);
    
    // exit program when gummi.glade can not be located:
    if (!g_file_test (ui, G_FILE_TEST_EXISTS)) {
        printf("Could not locate Glade interface file at:\n%s\n", ui);
        return 0;
    }
    
    gtk_builder_add_from_file (builder, ui, &ui_error);
    if (ui_error) {
        g_error ("%s\n", ui_error->message);
    }
    gtk_builder_set_translation_domain (builder, PACKAGE);
    g_free (ui);

    /* Initialize logging */
    slog_init (debug);
    slog (L_INFO, PACKAGE_NAME" version: "PACKAGE_VERSION"\n");

    /* Initialize configuration */
    gchar* configname = g_build_filename (g_get_user_config_dir (), "gummi",
                                  "gummi.cfg", NULL);
    config_init (configname);
    config_load ();
    g_free (configname);

    /* Initialize signals */
    gummi_signals_register ();

    /* Initialize Classes */
    gchar* snippetsname = g_build_filename (g_get_user_config_dir (), "gummi",
            "snippets.cfg", NULL);

    // why do we not load this from environment, like gui-main does? -A
    GuMotion* motion = motion_init ();
    GuIOFunc* io = iofunctions_init();
    GuLatex* latex = latex_init (); 
    GuBiblio* biblio = biblio_init (builder);
    GuTemplate* templ = template_init (builder);
    GuTabmanager* tabm = tabmanager_init ();
    GuProject* proj = project_init ();

    GuSnippets* snippets = snippets_init (snippetsname);
    gummi = gummi_init (motion, io, latex, biblio, templ, snippets, tabm, proj);
    slog (L_DEBUG, "Gummi created!\n");
    g_free (snippetsname);

    /* Initialize GUI */
    gui = gui_init (builder);
    
    slog_set_gui_parent (gui->mainwindow);
    slog (L_DEBUG, "GummiGui created!\n");

    /* Start compile thread */
    if (external_exists (config_get_value("typesetter"))) {
        typesetter_setup ();
        motion_start_compile_thread (motion);
    }
    else {
        infoscreengui_enable (gui->infoscreengui, "program_error");
        slog (L_ERROR, "Could not locate the typesetter program\n");
    }

    /* Install acceleration group to mainwindow */
    gtk_window_add_accel_group (gui->mainwindow, snippets->accel_group);

    if (argc != 2)
        tabmanager_create_tab (A_DEFAULT, NULL, NULL);
    else {
        if (!g_file_test(argv[1], G_FILE_TEST_EXISTS)) {
            slog(L_ERROR, "Failed to open file '%s': No such file or "
                    "directory\n", argv[1]);
            exit(1);
        }
        tabmanager_create_tab (A_LOAD, argv[1], NULL);
    }
        
    if (config_get_value ("autosaving")) iofunctions_start_autosave ();

    gui_main (builder);
    config_save ();
    config_clean_up ();
    return 0;
}
int main(int argc, char *argv[])
{
    /* won't actually be called - just here to make linker happy */
    template_init();
    return 0;
}