Exemplo n.º 1
0
int main(int argc, char **argv)
{
	line_ctx ctx;
	
	if (argc != 2) {
		printf("Usage: %s <filename>\n", argv[0]);
		return 1;
	}

	memset(&ctx, 0, sizeof(ctx));


	lwc_intern_string("class", SLEN("class"), &ctx.attr_class);
	lwc_intern_string("id", SLEN("id"), &ctx.attr_id);
	
	assert(css__parse_testfile(argv[1], handle_line, &ctx) == true);
	
	/* and run final test */
	if (ctx.tree != NULL)
		run_test(&ctx, ctx.exp, ctx.expused);

	free(ctx.exp);
	
	lwc_string_unref(ctx.attr_class);
	lwc_string_unref(ctx.attr_id);
	
	lwc_iterate_strings(printing_lwc_iterator, NULL);
	
	assert(fail_because_lwc_leaked == false);
	
	printf("PASS\n");
	return 0;
}
Exemplo n.º 2
0
/* Initialise the document */
dom_exception _dom_document_initialise(dom_document *doc,
                                       dom_events_default_action_fetcher daf)
{
    dom_exception err;
    dom_string *name;

    err = dom_string_create((const uint8_t *) "#document",
                            SLEN("#document"), &name);
    if (err != DOM_NO_ERR)
        return err;

    doc->nodelists = NULL;

    err = _dom_node_initialise(&doc->base, doc, DOM_DOCUMENT_NODE,
                               name, NULL, NULL, NULL);
    dom_string_unref(name);
    if (err != DOM_NO_ERR)
        return err;

    list_init(&doc->pending_nodes);

    doc->id_name = NULL;
    doc->quirks = DOM_DOCUMENT_QUIRKS_MODE_NONE;

    err = dom_string_create_interned((const uint8_t *) "class",
                                     SLEN("class"), &doc->class_string);
    if (err != DOM_NO_ERR)
        return err;

    /* We should not pass a NULL when all things hook up */
    return _dom_document_event_internal_initialise(doc, &doc->dei, daf);
}
Exemplo n.º 3
0
static nserror mimesniff__compute_image(lwc_string *official_type,
		const uint8_t *data, size_t len, lwc_string **effective_type)
{
#define SIG(t, s) { (const uint8_t *) s, SLEN(s), t }
	static const struct it_s {
		const uint8_t *sig;
		size_t len;
		lwc_string **type;
	} image_types[] = {
		SIG(&image_gif,                "GIF87a"),
		SIG(&image_gif,                "GIF89a"),
		SIG(&image_png,                "\x89PNG\r\n\x1a\n"),
		SIG(&image_jpeg,               "\xff\xd8\xff"),
		SIG(&image_bmp,                "BM"),
		SIG(&image_vnd_microsoft_icon, "\x00\x00\x01\x00"),
		{ NULL, 0, NULL }
	};
#undef SIG

	const struct it_s *it;

	if (data == NULL) {
		lwc_string_unref(official_type);
		return NSERROR_NEED_DATA;
	}

	for (it = image_types; it->sig != NULL; it++) {
		if (it->len <= len && memcmp(data, it->sig, it->len) == 0) {
			lwc_string_unref(official_type);
			*effective_type = lwc_string_ref(*it->type);
			return NSERROR_OK;
		}
	}

	/* WebP has a signature that doesn't fit into the above table */
	if (SLEN("RIFF????WEBPVP") <= len && 
			memcmp(data, "RIFF", SLEN("RIFF")) == 0 && 
			memcmp(data + SLEN("RIFF????"), 
					"WEBPVP", SLEN("WEBPVP")) == 0 ) {
		lwc_string_unref(official_type);
		*effective_type = lwc_string_ref(image_webp);
		return NSERROR_OK;
	}

	*effective_type = official_type;

	return NSERROR_OK;
}
Exemplo n.º 4
0
static GtkImage *
nsgtk_theme_searchimage_default(nsgtk_search_buttons tbbutton,
		GtkIconSize iconsize)
{
	char *imagefile;
	GtkImage *image;
	switch(tbbutton) {

	case (SEARCH_BACK_BUTTON):
		return GTK_IMAGE(gtk_image_new_from_stock("gtk-go-back", iconsize));
	case (SEARCH_FORWARD_BUTTON):
		return GTK_IMAGE(gtk_image_new_from_stock("gtk-go-forward",
							  iconsize));
	case (SEARCH_CLOSE_BUTTON):
		return GTK_IMAGE(gtk_image_new_from_stock("gtk-close", iconsize));
	default: {
		size_t len = SLEN("themes/Alpha.png") +
			strlen(res_dir_location) + 1;
		imagefile = malloc(len);
		if (imagefile == NULL) {
			warn_user(messages_get("NoMemory"), 0);
			return NULL;
		}
		snprintf(imagefile, len, "%sthemes/Alpha.png",
			 res_dir_location);
		image = GTK_IMAGE(
			gtk_image_new_from_file(imagefile));
		free(imagefile);
		return image;
	}
	}
}
Exemplo n.º 5
0
END_HANDLER

COMBO_CHANGED(comboSearch, search_provider)	
{
	nsgtk_scaffolding *current = scaf_list;
	char *name;

	/* refresh web search prefs from file */
	search_web_provider_details(nsoption_charp(search_provider));

	/* retrieve ico */
	search_web_retrieve_ico(false);

	/* callback may handle changing gui */
	if (search_web_ico() != NULL)
		gui_window_set_search_ico(search_web_ico());

	/* set entry */
	name = search_web_provider_name();
	if (name == NULL) {
		warn_user(messages_get("NoMemory"), 0);
		continue;
	}
	char content[strlen(name) + SLEN("Search ") + 1];
	sprintf(content, "Search %s", name);
	free(name);
	while (current) {
		nsgtk_scaffolding_set_websearch(current, content);
		current = nsgtk_scaffolding_iterate(current);
	}
}
Exemplo n.º 6
0
static bool theme_install_read(const char *data, unsigned long len)
{
	char *filename, *newfilename;
	size_t namelen;
	int handle = g_file_open_tmp("nsgtkthemeXXXXXX", &filename, NULL);
	if (handle == -1) {
		warn_user(messages_get("gtkFileError"),
			  "temporary theme file");
		return false;
	}
	ssize_t written = write(handle, data, len);
	close(handle);
	if ((unsigned)written != len)
		return false;

	/* get name of theme; set as dirname */
	namelen = SLEN("themes/") + strlen(res_dir_location) + 1;
	char dirname[namelen];
	snprintf(dirname, namelen, "%sthemes/", res_dir_location);

	/* save individual files in theme */
	newfilename = container_extract_theme(filename, dirname);
	g_free(filename);
	if (newfilename == NULL)
		return false;
	nsgtk_theme_add(newfilename);
	free(newfilename);

	return true;
}
Exemplo n.º 7
0
/**
 * Create a nsurl from a path using amiga file handling.
 *
 * Perform the necessary operations on a path to generate a nsurl.
 *
 * @param[in] path The path to convert.
 * @param[out] url_out pointer to recive the nsurl, The returned url
 *                     must be unreferenced by the caller.
 * @return NSERROR_OK and the url is placed in \a url or error code on
 *         faliure.
 */
static nserror amiga_path_to_nsurl(const char *path, struct nsurl **url_out)
{
	char *colon = NULL;
	char *r = NULL;
	char newpath[1024 + strlen(path)];
	BPTR lock = 0;
	nserror ret;

	if((lock = Lock(path, SHARED_LOCK))) {
		DevNameFromLock(lock, newpath, sizeof newpath, DN_FULLPATH);
		UnLock(lock);
	}
	else strlcpy(newpath, path, sizeof newpath);

	r = malloc(strlen(newpath) + SLEN("file:///") + 1);
	if (r == NULL) {
		return NSERROR_NOMEM;
	}

	if((colon = strchr(newpath, ':'))) *colon = '/';

	strcpy(r, "file:///");
	strcat(r, newpath);

	ret = nsurl_create(r, url_out);
	free(r);

	return ret;
}
Exemplo n.º 8
0
static void nsgtk_options_theme_combo(void) {
/* populate theme combo from themelist file */
	GtkBox *box = GTK_BOX(glade_xml_get_widget(gladeFile, "themehbox"));
	char buf[50];
	combotheme = gtk_combo_box_new_text();
	size_t len = SLEN("themelist") + strlen(res_dir_location) + 1;
	char themefile[len];
	if ((combotheme == NULL) || (box == NULL)) {
		warn_user(messages_get("NoMemory"), 0);
		return;
	}
	snprintf(themefile, len, "%sthemelist", res_dir_location);
	FILE *fp = fopen((const char *)themefile, "r");
	if (fp == NULL) {
		LOG(("Failed opening themes file"));
		warn_user("FileError", (const char *) themefile);
		return;
	}
	while (fgets(buf, sizeof(buf), fp) != NULL) {
		/* Ignore blank lines */
		if (buf[0] == '\0')
			continue;
		
		/* Remove trailing \n */
		buf[strlen(buf) - 1] = '\0';
		
		gtk_combo_box_append_text(GTK_COMBO_BOX(combotheme), buf);
	}
	fclose(fp);
	gtk_combo_box_set_active(GTK_COMBO_BOX(combotheme), 
			option_current_theme);
	gtk_box_pack_start(box, combotheme, FALSE, TRUE, 0);
	gtk_widget_show(combotheme);		
}
Exemplo n.º 9
0
static void nsgtk_download_store_update_item (struct gui_download_window *dl)
{
	gchar *info = nsgtk_download_info_to_string(dl);
	char *human = human_friendly_bytesize(dl->speed);
	char speed[strlen(human) + SLEN("/s") + 1];
	sprintf(speed, "%s/s", human);
	gchar *time = nsgtk_download_time_to_string(dl->time_remaining);
	gboolean pulse = dl->status == NSGTK_DOWNLOAD_WORKING;

	/* Updates iter (which is needed to set and get data) with the dl row */
	gtk_tree_model_get_iter(GTK_TREE_MODEL(nsgtk_download_store),
				&nsgtk_download_iter,
				gtk_tree_row_reference_get_path(dl->row));

	gtk_list_store_set(nsgtk_download_store, &nsgtk_download_iter,
			   NSGTK_DOWNLOAD_PULSE, pulse ? dl->progress : -1,
			   NSGTK_DOWNLOAD_PROGRESS, pulse ? 0 : dl->progress,
			   NSGTK_DOWNLOAD_INFO, info,
			   NSGTK_DOWNLOAD_SPEED, dl->speed == 0 ? "-" : speed,
			   NSGTK_DOWNLOAD_REMAINING, time,
			   NSGTK_DOWNLOAD, dl,
			   -1);

	g_free(info);
	g_free(time);
}
Exemplo n.º 10
0
static inline void move_chars(struct part *p, int x, int y, int nx, int ny)
{
	if (LEN(y) - x <= 0) return;
	copy_chars(p, nx, ny, LEN(y) - x, &POS(x, y));
	SLEN(y, x);
	move_links(p, x, y, nx, ny);
}
Exemplo n.º 11
0
void fetch_rsrc_register(void)
{
	lwc_string *scheme;
	int err;

	err = find_app_resources();

	if (err < B_OK) {
		warn_user("Resources", strerror(err));
		return;
	}

	if (lwc_intern_string("rsrc", SLEN("rsrc"), &scheme) != lwc_error_ok) {
		die("Failed to initialise the fetch module "
				"(couldn't intern \"rsrc\").");
	}

	fetch_add_fetcher(scheme,
		fetch_rsrc_initialise,
		fetch_rsrc_can_fetch,
		fetch_rsrc_setup,
		fetch_rsrc_start,
		fetch_rsrc_abort,
		fetch_rsrc_free,
		fetch_rsrc_poll,
		fetch_rsrc_finalise);
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: d5h/gah
const char *
typestr(unsigned t, size_t n)
{
  static char buf[SLEN(n) + 4];
  char *p = buf + sizeof buf - 1;

  *p = '\0';
  if (! (t & (T_GROUP | T_BITFIELD)) && 1 < n)
    *--p = t & T_LSBFIRST ? 'l' : 'm';

  do
    *--p = '0' + n % 10;
  while (n /= 10);

  if (t & T_GROUP)
    *--p = 's';
  else if (t & T_BITFIELD)
    *--p = 'b';
  else if (t & T_TWOSCOMP)
    *--p = 't', *--p = 's';
  else if (t & T_ONESCOMP)
    *--p = 'o', *--p = 's';
  else if (t & T_SIGNMAG)
    *--p = 'm', *--p = 's';
  else
    *--p = 'u';

  return p;
}
Exemplo n.º 13
0
static int
debug_un(char *str, size_t len, const struct sockaddr_un *sun)
{
	return snprintf(str, len, "sun_len=%u, sun_family=%u, sun_path=%*s",
	    SLEN(sun), sun->sun_family, (int)sizeof(sun->sun_path),
	    sun->sun_path);
}
Exemplo n.º 14
0
void nsgtk_theme_add(const char *themename)
{
	size_t len;
	GtkWidget *notification, *label;
	len = SLEN("themelist") + strlen(res_dir_location) + 1;
	char themefile[len];
	snprintf(themefile, len, "%s%s", res_dir_location, "themelist");
	/* conduct verification here; no adding duplicates to list */
	if (nsgtk_theme_verify(themename) == false) {
		warn_user(messages_get("gtkThemeDup"), 0);
		return;
	}
	FILE *fp = fopen(themefile, "a");
	if (fp == NULL) {
		warn_user(messages_get("gtkFileError"), themefile);
		return;
	}
	fprintf(fp, "%s\n", themename);
	fclose(fp);

	/* notification that theme was added successfully */
	notification = gtk_dialog_new_with_buttons(messages_get("gtkThemeAdd"),
			NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK,
			GTK_RESPONSE_NONE, NULL);
	if (notification == NULL) {
		warn_user(messages_get("NoMemory"), 0);
		return;
	}
	len = SLEN("\t\t\t\t\t\t") + strlen(messages_get("gtkThemeAdd")) + 1;
	char labelcontent[len];
	snprintf(labelcontent, len, "\t\t\t%s\t\t\t",
		 messages_get("gtkThemeAdd"));
	label = gtk_label_new(labelcontent);
	if (label == NULL) {
		warn_user(messages_get("NoMemory"), 0);
		return;
	}
	g_signal_connect_swapped(notification, "response",
				 G_CALLBACK(gtk_widget_destroy), notification);
	gtk_container_add(GTK_CONTAINER(nsgtk_dialog_get_action_area(GTK_DIALOG(notification))), label);
	gtk_widget_show_all(notification);

	/* update combo */
	if (wndPreferences != NULL) {
		nsgtk_options_combo_theme_add(themename);
	}
}
Exemplo n.º 15
0
static int
debug_in(char *str, size_t len, const struct sockaddr_in *sin)
{
	return snprintf(str, len, "sin_len=%u, sin_family=%u, sin_port=%u, "
	    "sin_addr.s_addr=%08x",
	    SLEN(sin), sin->sin_family, sin->sin_port,
	    sin->sin_addr.s_addr);
}
Exemplo n.º 16
0
/*
 * stringLength - get length of string
 */
static int stringLength( char _ISFAR *str )
{
#if defined( __NT__ ) && !defined( __DEC__ )
    if( str == NULL ) {
        return( SLEN( str ) );
    } else {
        int len;
        len = MultiByteToWideChar( CP_OEMCP, MB_ERR_INVALID_CHARS, str, -1, NULL, 0 );
        if( len == 0 || len == ERROR_NO_UNICODE_TRANSLATION ) {
            return( SLEN( str ) );
        }
        return( len * sizeof( WCHAR ) );
    }
#else
    return( SLEN( str ) );
#endif

} /* stringLength */
Exemplo n.º 17
0
/**
 * Dispatch a DOMNodeInsertedIntoDocument/DOMNodeRemovedFromDocument event
 *
 * \param doc      The document object
 * \param et       The EventTarget object
 * \param type     "DOMNodeInserted" or "DOMNodeRemoved"
 * \param success  Whether this event's default action get called
 * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
 */
dom_exception __dom_dispatch_node_change_document_event(dom_document *doc,
		dom_event_target *et, dom_mutation_type change, bool *success)
{
	struct dom_mutation_event *evt;
	dom_string *type = NULL;
	dom_exception err;

	err = _dom_mutation_event_create(doc, &evt);
	if (err != DOM_NO_ERR)
		return err;

	if (change == DOM_MUTATION_ADDITION) {
		err = dom_string_create(
				(const uint8_t *) 
					"DOMNodeInsertedIntoDocument", 
				SLEN("DOMNodeInsertedIntoDocument"), &type);
		if (err != DOM_NO_ERR)
			goto cleanup;
	} else if (change == DOM_MUTATION_REMOVAL) {
		err = dom_string_create(
				(const uint8_t *) "DOMNodeRemovedFromDocument", 
				SLEN("DOMNodeRemovedFromDocument"), &type);
		if (err != DOM_NO_ERR)
			goto cleanup;
	} else {
		assert("Should never be here" == NULL);
	}

	/* Initialise the event with corresponding parameters */
	err = dom_mutation_event_init(evt, type, true, false, NULL,
			NULL, NULL, NULL, change);
	dom_string_unref(type);
	if (err != DOM_NO_ERR)
		goto cleanup;

	err = dom_event_target_dispatch_event(et, evt, success);
	if (err != DOM_NO_ERR)
		goto cleanup;
	
cleanup:
	_dom_mutation_event_destroy(evt);

	return err;
}
Exemplo n.º 18
0
END_HANDLER

BUTTON_CLICKED(buttonaddtheme)
{
	char *filename, *directory;
	size_t len;
	GtkWidget *fc = gtk_file_chooser_dialog_new(
			messages_get("gtkAddThemeTitle"),
			GTK_WINDOW(wndPreferences),
			GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
			GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
	len = SLEN("themes") + strlen(res_dir_location) + 1;
	char themesfolder[len];
	snprintf(themesfolder, len, "%sthemes", res_dir_location);
	gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), 
			themesfolder);
	gint res = gtk_dialog_run(GTK_DIALOG(fc));
	if (res == GTK_RESPONSE_ACCEPT) {
		filename = gtk_file_chooser_get_current_folder(
				GTK_FILE_CHOOSER(fc));
		if (strcmp(filename, themesfolder) != 0) {
			directory = strrchr(filename, '/');
			*directory = '\0';
			if (strcmp(filename, themesfolder) != 0) {
				warn_user(messages_get(
						"gtkThemeFolderInstructions"), 
						0);
				gtk_widget_destroy(GTK_WIDGET(fc));
				if (filename != NULL)
					g_free(filename);
				return FALSE;
			} else {
				directory++;
			}
		} else {
			if (filename != NULL)
				g_free(filename);
			filename = gtk_file_chooser_get_filename(
					GTK_FILE_CHOOSER(fc));
			if (strcmp(filename, themesfolder) == 0) {
				warn_user(messages_get("gtkThemeFolderSub"),
						0);
				gtk_widget_destroy(GTK_WIDGET(fc));
				g_free(filename);
				return FALSE;
			}
			directory = strrchr(filename, '/') + 1;
		}
		gtk_widget_destroy(GTK_WIDGET(fc));
		nsgtk_theme_add(directory);
		if (filename != NULL)
			g_free(filename);
	}
}
Exemplo n.º 19
0
void fetch_init(void)
{
	fetch_curl_register();
	fetch_data_register();
	fetch_file_register();
	fetch_resource_register();
	fetch_about_register();
	fetch_active = false;

	if (lwc_intern_string("http", SLEN("http"), &fetch_http_lwc) !=
			lwc_error_ok) {
		die("Failed to initialise the fetch module "
				"(couldn't intern \"http\").");
	}

	if (lwc_intern_string("https", SLEN("https"), &fetch_https_lwc) !=
			lwc_error_ok) {
		die("Failed to initialise the fetch module "
				"(couldn't intern \"https\").");
	}
}
Exemplo n.º 20
0
static int
debug_dl(char *str, size_t len, const struct sockaddr_dl *sdl)
{
	const uint8_t *s = (const void *)sdl->sdl_data;

	return snprintf(str, len, "sdl_len=%u, sdl_family=%u, sdl_index=%u, "
	    "sdl_type=%u, sdl_nlen=%u, sdl_alen=%u, sdl_slen=%u, sdl_data="
	    "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
	    SLEN(sdl), sdl->sdl_family, sdl->sdl_index,
	    sdl->sdl_type, sdl->sdl_nlen, sdl->sdl_alen, sdl->sdl_slen,
	    s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
	    s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb]);
}
Exemplo n.º 21
0
Arquivo: main.c Projeto: d5h/gah
const char *
nstr(size_t n)
{
  static char buf[SLEN(n) + 2];
  char *p = buf + sizeof buf - 1;

  *p = '\0';
  do
    *--p = '0' + n % 10;
  while (n /= 10);

  return p;
}
Exemplo n.º 22
0
nserror nsgtk_viewsource(GtkWindow *parent, struct browser_window *bw)
{
	nserror ret;
	struct hlcache_handle *hlcontent;
	const char *source_data;
	unsigned long source_size;
	char *ndata = NULL;
	size_t ndata_len;
	char *filename;
	char *title;

	hlcontent = browser_window_get_content(bw);
	if (hlcontent == NULL) {
		return NSERROR_BAD_PARAMETER;
	}

	if (content_get_type(hlcontent) != CONTENT_HTML) {
		return NSERROR_BAD_CONTENT;
	}

	source_data = content_get_source_data(hlcontent, &source_size);

	ret = nsurl_nice(browser_window_get_url(bw), &filename, false);
	if (ret != NSERROR_OK) {
		filename = strdup(messages_get("SaveSource"));
		if (filename == NULL) {
			return NSERROR_NOMEM;
		}
	}

	title = malloc(strlen(nsurl_access(browser_window_get_url(bw))) + SLEN("Source of  - NetSurf") + 1);
	if (title == NULL) {
		free(filename);
		return NSERROR_NOMEM;
	}
	sprintf(title, "Source of %s - NetSurf", nsurl_access(browser_window_get_url(bw)));

	ret = utf8_from_enc(source_data,
			    content_get_encoding(hlcontent, CONTENT_ENCODING_NORMAL),
			    source_size,
			    &ndata,
			    &ndata_len);
	if (ret == NSERROR_OK) {
		ret = nsgtk_viewdata(title, filename, ndata, ndata_len);
	}

	free(filename);
	free(title);

	return ret;
}
Exemplo n.º 23
0
static int
debug_in6(char *str, size_t len, const struct sockaddr_in6 *sin6)
{
	const uint8_t *s = sin6->sin6_addr.s6_addr;

	return snprintf(str, len, "sin6_len=%u, sin6_family=%u, sin6_port=%u, "
	    "sin6_flowinfo=%u, "
	    "sin6_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:"
	    "%02x:%02x:%02x:%02x:%02x:%02x, sin6_scope_id=%u",
	    SLEN(sin6), sin6->sin6_family, sin6->sin6_port,
	    sin6->sin6_flowinfo, s[0x0], s[0x1], s[0x2], s[0x3], s[0x4], s[0x5],
	    s[0x6], s[0x7], s[0x8], s[0x9], s[0xa], s[0xb], s[0xc], s[0xd],
	    s[0xe], s[0xf], sin6->sin6_scope_id);
}
Exemplo n.º 24
0
static int
debug_at(char *str, size_t len, const struct sockaddr_at *sat)
{
	return snprintf(str, len, "sat_len=%u, sat_family=%u, sat_port=%u, "
	    "sat_addr.s_net=%u, sat_addr.s_node=%u, "
	    "sat_range.r_netrange.nr_phase=%u, "
	    "sat_range.r_netrange.nr_firstnet=%u, "
	    "sat_range.r_netrange.nr_lastnet=%u",
	    SLEN(sat), sat->sat_family, sat->sat_port,
	    sat->sat_addr.s_net, sat->sat_addr.s_node,
	    sat->sat_range.r_netrange.nr_phase,
	    sat->sat_range.r_netrange.nr_firstnet,
	    sat->sat_range.r_netrange.nr_lastnet);
}
Exemplo n.º 25
0
Arquivo: perl.c Projeto: mdbarr/vcsi
SV* perl_sv(VCSI_CONTEXT vc,
	    VCSI_OBJECT x) {
  
  /* basic type handling */
  if(TYPEP(x,LNGNUM))
    return newSViv(LNGN(x));
  else if(TYPEP(x,FLTNUM))
    return newSVnv(FLTN(x));
  else if(TYPEP(x,STRING))
    return newSVpvn(STR(x),SLEN(x));
  
  /* everything else */
  return Nullsv;
}
Exemplo n.º 26
0
/** Duplicate su_localinfo structure.
 */
su_localinfo_t *su_copylocalinfo(su_localinfo_t const *li0)
{
  size_t n;
  su_localinfo_t *li, *retval = NULL, **lli = &retval;

# define SLEN(s) ((s) ? strlen(s) + 1 : 0)

  for (; li0 ; li0 = li0->li_next) {
    n = sizeof(*li0) + li0->li_addrlen + SLEN(li0->li_ifname);
    if (!(li = calloc(1, n))) {
      su_freelocalinfo(retval);
      return NULL;
    }
    *lli = li;
    lli = &li->li_next;
    li->li_flags = li0->li_flags;
    li->li_family = li0->li_family;
    li->li_index = li0->li_index;
    li->li_scope = li0->li_scope;
    li->li_addrlen = li0->li_addrlen;
    li->li_addr = memcpy(li + 1, li0->li_addr, li0->li_addrlen);

    if (li0->li_canonname) {
      if (!(li->li_canonname = malloc(SLEN(li0->li_canonname)))) {
	su_freelocalinfo(retval);
	return NULL;
      }
      strcpy(li->li_canonname, li0->li_canonname);
    }

    if (li0->li_ifname)
      li->li_ifname = strcpy(li->li_addrlen + (char *)li->li_addr,
			     li0->li_ifname);
  }

  return retval;
}
Exemplo n.º 27
0
/**
 * Initialise the namespace component
 *
 * \return DOM_NO_ERR on success.
 */
static dom_exception _dom_namespace_initialise(void)
{
	int i;
	dom_exception err;

	err = dom_string_create((const uint8_t *) "xml", SLEN("xml"), &xml);
	if (err != DOM_NO_ERR) {
		return err;
	}

	err = dom_string_create((const uint8_t *) "xmlns", SLEN("xmlns"), 
			&xmlns);
	if (err != DOM_NO_ERR) {
		dom_string_unref(xml);
		xml = NULL;

		return err;
	}

	for (i = 1; i < DOM_NAMESPACE_COUNT; i++) {
		err = dom_string_create(
				(const uint8_t *) namespaces[i],
				strlen(namespaces[i]), &dom_namespaces[i]);
		if (err != DOM_NO_ERR) {
			dom_string_unref(xmlns);
			xmlns = NULL;

			dom_string_unref(xml);
			xml = NULL;

			return err;
		}
	}

	return DOM_NO_ERR;
}
Exemplo n.º 28
0
/**
 * Initialise a dom_html_base_element object
 *
 * \param doc  The document object
 * \param ele  The dom_html_base_element object
 * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
 */
dom_exception _dom_html_base_element_initialise(struct dom_html_document *doc,
		struct dom_html_base_element *ele)
{
	dom_string *name = NULL;
	dom_exception err;

	err = dom_string_create((const uint8_t *) "BASE", SLEN("BASE"), &name);
	if (err != DOM_NO_ERR)
		return err;
	
	err = _dom_html_element_initialise(doc, &ele->base, name, NULL, NULL);
	dom_string_unref(name);

	return err;
}
Exemplo n.º 29
0
static nserror mimesniff__match_unknown_riff(const uint8_t *data, size_t len,
		lwc_string **effective_type)
{
#define SIG(t, s, x) { (const uint8_t *) s, SLEN(s), x, t }
	static const struct map_s riff_match_types[] = {
		SIG(&image_webp, "WEBPVP", true),
		SIG(&audio_wave, "WAVE",   true),
		{ NULL, 0, false, NULL }
	};
#undef SIG
	const struct map_s *it;

	for (it = riff_match_types; it->sig != NULL; it++) {
		if (it->len + SLEN("RIFF????") <= len && 
				memcmp(data, "RIFF", SLEN("RIFF")) == 0 &&
				memcmp(data + SLEN("RIFF????"), 
						it->sig, it->len) == 0) {
			*effective_type = lwc_string_ref(*it->type);
			return NSERROR_OK;
		}
	}

	return NSERROR_NOT_FOUND;
}
Exemplo n.º 30
0
/**
 * Determine whether this codec handles a specific charset
 *
 * \param charset  Charset to test
 * \return true if handleable, false otherwise
 */
bool charset_ascii_codec_handles_charset(const char *charset)
{
    static uint16_t ascii;
    uint16_t match = parserutils_charset_mibenum_from_name(charset,
                     strlen(charset));

    if (ascii == 0) {
        ascii = parserutils_charset_mibenum_from_name(
                    "US-ASCII", SLEN("US-ASCII"));
    }

    if (ascii != 0 && ascii == match)
        return true;

    return false;
}