static gboolean
write_connection_to_child (int fd, NMConnection *connection, GError **error)
{
	NMSettingVPN *s_vpn;
	WriteItemInfo info = { .fd = fd, .secret = FALSE, .error = error };

	s_vpn = nm_connection_get_setting_vpn (connection);
	if (!s_vpn) {
		g_set_error_literal (error,
		                     NM_SECRET_AGENT_ERROR,
		                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
		                     "Connection had no VPN setting");
		return FALSE;
	}

	nm_setting_vpn_foreach_data_item (s_vpn, write_one_key_val, &info);
	if (error && *error)
		return FALSE;

	info.secret = TRUE;
	nm_setting_vpn_foreach_secret (s_vpn, write_one_key_val, &info);
	if (error && *error)
		return FALSE;

	if (!write_item (fd, "DONE\n\n", error))
		return FALSE;

	return TRUE;
}
예제 #2
0
static void write_chunk(struct buffer *dstbuffer, struct buffer *srcbuffer, char *tag)
{
	if (strlen(tag) != 4)
		return;
	buffer_append(dstbuffer, tag, 4);
	write_item(dstbuffer, srcbuffer->bytes, srcbuffer->len);
}
예제 #3
0
static void write_children_recursive(WTF::Vector<char>& v, WebCore::HistoryItem* parent)
{
    const WebCore::HistoryItemVector& children = parent->children();
    WebCore::HistoryItemVector::const_iterator end = children.end();
    for (WebCore::HistoryItemVector::const_iterator i = children.begin(); i != end; ++i) {
        WebCore::HistoryItem* item = (*i).get();
        LOG_ASSERT(parent->bridge(),
                "The parent item should have a bridge object!");
        if (!item->bridge()) {
            WebHistoryItem* bridge = new WebHistoryItem(static_cast<WebHistoryItem*>(parent->bridge()));
            item->setBridge(bridge);
            bridge->setActive();
        } else {
            // The only time this item's parent may not be the same as the
            // parent's bridge is during history close. In that case, the
            // parent must not have a parent bridge.
            WebHistoryItem* bridge = static_cast<WebHistoryItem*>(item->bridge());
            WebHistoryItem* parentBridge = static_cast<WebHistoryItem*>(parent->bridge());
            LOG_ASSERT(parentBridge->parent() == 0 ||
                    bridge->parent() == parentBridge,
                    "Somehow this item has an incorrect parent");
            bridge->setParent(parentBridge);
        }
        write_item(v, item);
        write_children_recursive(v, item);
    }
}
예제 #4
0
파일: tile.c 프로젝트: noradtux/navit-webos
void
tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name)
{
    if (info->write)
        write_item(name, ib, reference);
    else
        tile_extend(name, ib, info->tiles_list);
}
예제 #5
0
파일: write.c 프로젝트: MattX/mulisp
void write_inside_list(Object *object)
{
    if(object->pair.cdr->type == OTYPE_NIL) {
        write_item(object->pair.car);
        printf(")");
    }
    else if(object->pair.cdr->type == OTYPE_PAIR) {
        write_item(object->pair.car);
        printf(" ");
        write_inside_list(object->pair.cdr);
    }
    else {
        write_item(object->pair.car);
        printf(" . ");
        write_item(object->pair.cdr);
        printf(")");
    }
}
예제 #6
0
static void write_crypt_string(struct buffer *buffer, char *bytes, const unsigned char key[KDF_HASH_LEN])
{
	_cleanup_free_ char *encrypted = NULL;
	size_t len;

	len = cipher_aes_encrypt(bytes, key, &encrypted);
	if (!encrypted)
		die("Could not write encrypted string.");
	write_item(buffer, encrypted, len);
}
static void
write_one_key_val (const char *key, const char *value, gpointer user_data)
{
	WriteItemInfo *info = user_data;
	const char *tag;

	if (info->error && *(info->error))
		return;

	/* Write the key name */
	tag = info->secret ? secret_key_tag : data_key_tag;
	if (!write_item (info->fd, tag, info->error))
		return;
	if (!write_item (info->fd, key, info->error))
		return;
	if (!write_item (info->fd, "\n", info->error))
		return;

	/* Write the key value */
	tag = info->secret ? secret_val_tag : data_val_tag;
	if (!write_item (info->fd, tag, info->error))
		return;
	if (!write_item (info->fd, value ? value : "", info->error))
		return;
	if (!write_item (info->fd, "\n\n", info->error))
		return;
}
예제 #8
0
static void get_credential(void)
{
	CREDENTIALW **creds;
	DWORD num_creds;
	int i;

	if (!CredEnumerateW(L"git:*", 0, &num_creds, &creds))
		return;

	/* search for the first credential that matches username */
	for (i = 0; i < num_creds; ++i)
		if (match_cred(creds[i])) {
			write_item("username", creds[i]->UserName,
				wcslen(creds[i]->UserName));
			write_item("password",
				(LPCWSTR)creds[i]->CredentialBlob,
				creds[i]->CredentialBlobSize / sizeof(WCHAR));
			break;
		}

	CredFree(creds);
}
예제 #9
0
파일: util.c 프로젝트: grfrost/fpgajtag
void flush_write(uint8_t *req)
{
    if (req)
        write_item(req);
    int write_length = buffer_current_size();
    usbreadbuffer_ptr = usbreadbuffer;
    if (!write_length)
        return;
    ftdi_write_data(global_ftdi, usbreadbuffer, write_length);
    read_size_ptr = 0;

    const uint8_t *p = usbreadbuffer;
    while (write_length > 0) {
        int plen = 1;
        uint8_t ch = *p;
        unsigned tlen = (p[2] << 8 | p[1]) + 1;
        switch(ch) {
        case 0x85: case 0x87: case 0x8a: case 0xaa: case 0xab:
            break;
        case 0x2e:
            plen = 2;
            break;
        case 0x19: case 0x1b: case 0x2c: case 0x3d: case 0x3f: case 0x4b:
        case 0x6f: case 0x80: case 0x82: case 0x86: case 0x8f:
            plen = 3;
            break;
        default:
            memdump(p-1, write_length, "UNABLE TO PARSE OUTPUT COMMAND");
            exit(-1);
        }
        if (ch & MPSSE_DO_READ) {
            if (ch & MPSSE_BITMODE) {
                int bitsize = *(p+1)+1;
                if (ch & MPSSE_WRITE_TMS)
                    bitsize = 1;
                read_size[read_size_ptr] = -bitsize; /* number of bits */
            }
            else if (ch == 0x2c || ch == 0x3d)       /* DATAR or DATARW */
                read_size[read_size_ptr] = tlen;     /* number of bytes */
            else
                read_size[read_size_ptr] = *(p+1);   /* number of bytes */
            read_size_ptr++;
        }
        p += plen;
        write_length -= plen;
        if (ch == 0x19 || ch == 0x3d) {
            p += tlen;
            write_length -= tlen;
        }
    }
}
예제 #10
0
파일: write.c 프로젝트: MattX/mulisp
void write_item(Object *object)
{
    int i;

    switch (object->type) {
        case OTYPE_NIL:
            printf("()");
            break;
        case OTYPE_INT:
            printf("%d", object->integer.value);
            break;
        case OTYPE_FLT:
            printf("%lf", object->floating.value);
            break;
        case OTYPE_FRAC:
            printf("%d/%u", object->fraction.numerator, object->fraction.denominator);
            break;
        case OTYPE_CHR:
            printf("#\\%c", object->chr.value);
            break;
        case OTYPE_BOOL:
            printf("#%s", object->boolean.value ? "t" : "f");
            break;
        case OTYPE_STR:
            printf("\"%s\"", object->str.value);
            break;
        case OTYPE_VECTOR:
            printf("#(");
            for(i = 0; i < object->vector.length; i++) {
                write_item(object->vector.value[i]);
                if(i < object->vector.length - 1)
                    printf(" ");
            }
            printf(")");
            break;
        case OTYPE_PAIR:
            printf("(");
            write_inside_list(object);
            break;
        case OTYPE_PROC: case OTYPE_PRIM:
            printf("<procedure>");
            break;
        case OTYPE_PORT:
            printf("<port>");
            break;
        case OTYPE_SYM:
            printf("%s", object->str.value);
            break;
    }
}
예제 #11
0
jbyteArray WebHistory::Flatten(JNIEnv* env, WTF::Vector<char>& v, WebCore::HistoryItem* item)
{
    if (!item)
        return NULL;

    // Reserve a vector of chars with an initial size of HISTORY_MIN_SIZE.
    v.reserveCapacity(HISTORY_MIN_SIZE);

    // Write the top-level history item and then write all the children
    // recursively.
    LOG_ASSERT(item->bridge(), "Why don't we have a bridge object here?");
    write_item(v, item);
    write_children_recursive(v, item);

//SAMSUNG - CRASH FIX BEGIN

    int size = v.size();
    if (size > 0) 
    {
        long availableMemory = GetVmAvailableMemory(env);

        if(size > availableMemory)
        {
            LOGV("WebHistory::Flatten(): load size=%d, availableMemory=%ld, still larger, return NULL", size, availableMemory);		
            return NULL;
        }

        checkException(env);
    }

//SAMSUNG - CRASH FIX END
    // Try to create a new java byte array.
    jbyteArray b = env->NewByteArray(v.size());
    if (!b)
    {
//SAMSUNG - CRASH FIX BEGIN
        if (checkException(env))
        {
            LOGV("WebHistory::Flatten(): env exception happened while allocating %d bytes, clear pending exception", v.size());
            env->ExceptionClear();
        }
//SAMSUNG - CRASH FIX END
        return NULL;
    }

    // Write our flattened data to the java array.
    env->SetByteArrayRegion(b, 0, v.size(), (const jbyte*)v.data());
    return b;
}
예제 #12
0
static void find_internet_password(void)
{
	void *buf;
	UInt32 len;
	SecKeychainItemRef item;

	if (SecKeychainFindInternetPassword(KEYCHAIN_ARGS, &len, &buf, &item))
		return;

	write_item("password", buf, len);
	if (!username)
		find_username_in_item(item);

	SecKeychainItemFreeContent(NULL, buf);
}
예제 #13
0
static void find_username_in_item(SecKeychainItemRef item)
{
	SecKeychainAttributeList list;
	SecKeychainAttribute attr;

	list.count = 1;
	list.attr = &attr;
	attr.tag = kSecAccountItemAttr;

	if (SecKeychainItemCopyContent(item, NULL, &list, NULL, NULL))
		return;

	write_item("username", attr.data, attr.length);
	SecKeychainItemFreeContent(&list, NULL);
}
예제 #14
0
bool svg_writer::write_to_file (const QString &filename, const abstract_svg_item *root)
{
  QFile file (filename);
  if (!file.open (QIODevice::WriteOnly))
    return false;

  QXmlStreamWriter writer (&file);
  writer.setAutoFormatting(true);
  map<QString, QString> namespaces = get_used_namespaces (root);
  for (auto namespace_pair : namespaces)
    writer.writeNamespace (namespace_pair.first, namespace_pair.second);

  writer.writeDefaultNamespace (svg_namespaces::svg_uri ());
  writer.writeStartDocument();
  write_item (root, writer);
  writer.writeEndDocument();
  return true;
}
예제 #15
0
void init_items(void)
{
	uint32 i = 0;
	char *path;

	item_array = (item_t *)calloc(MAX_ITEMS, sizeof(item_t));

	for(i = 0; i < MAX_ITEMS; i++){
		item_array[i].name = (char *)calloc(MAX_NAME_LENGTH, sizeof(char));

		path = get_path(ITEM_PATH, i, FILE_ENDING);

		check_dir(ITEM_PATH);

		if(file_readable(path))
			read_item(path,i);
		else
			write_item(path,i);
	}
}
예제 #16
0
파일: read.c 프로젝트: ErikCumps/spwproject
int
main (int argc, char *argv[])
{
	arc_t		*arc = NULL;
	arc_item_t	*item = NULL;
	//int		first	= 0;
	unsigned long	id;

	if (argc > 1)
		arc = arc_load (argv[1], NULL);
	else
		arc = arc_load (outfile, (arc_sig_t *)signature);

	if (arc == NULL) {
		printf ("*** Error: failed to open archive file \"%s\"!\n", outfile);
		exit (42);
	}

	printf ("%6s %10s %10s %s\n", "ID", "POS", "SIZE", "NAME");
	printf ("%6s %10s %10s %s\n", "--", "---", "----", "----");
	while ((item = arc_next (arc, item)) != NULL) {
		printf ("%6lu %10lu %10lu %s\n", item->id, item->pos, item->size, item->name);
		//if (!first) {
		//	first = 1;
		//	write_item (item);
		//}
	}
	printf ("\n");

	id = 101;
	item = arc_byid (arc, id);
	if (item == NULL)
		printf ("*** Error: item with id %lu not found!\n", id);
	else {
		printf ("%6lu %10lu %10lu %s\n", item->id, item->pos, item->size, item->name);
		write_item (item);
		printf ("\n");
	}

	return (0);
}
예제 #17
0
jbyteArray WebHistory::Flatten(JNIEnv* env, WTF::Vector<char>& v, WebCore::HistoryItem* item)
{
    if (!item)
        return NULL;

    // Reserve a vector of chars with an initial size of HISTORY_MIN_SIZE.
    v.reserveCapacity(HISTORY_MIN_SIZE);

    // Write the top-level history item and then write all the children
    // recursively.
    LOG_ASSERT(item->bridge(), "Why don't we have a bridge object here?");
    write_item(v, item);
    write_children_recursive(v, item);

    // Try to create a new java byte array.
    jbyteArray b = env->NewByteArray(v.size());
    if (!b)
        return NULL;

    // Write our flattened data to the java array.
    env->SetByteArrayRegion(b, 0, v.size(), (const jbyte*)v.data());
    return b;
}
예제 #18
0
void svg_writer::write_item (const abstract_svg_item *root, QXmlStreamWriter &writer) const
{
  if (root->is_cloned ())
    return;

  if (root->is_character_data ())
    {
      const svg_character_data *data = static_cast<const svg_character_data *> (root);
      writer.writeCharacters (data->char_data ());
      return;
    }

  writer.writeStartElement (root->namespace_uri (), root->type_name ());

  vector<const abstract_attribute *> attributes_list = root->attributes_list ();
  for (const abstract_attribute *attribute : attributes_list)
    {
      QString value;
      if (attribute->is_inherited ())
        value = "inherit";
      else
        attribute->write (value);

      /// Qt ignores default namespace for atributes, force it manually
      if (attribute->namespace_type () == svg_namespaces_t::SVG)
        writer.writeAttribute (attribute->type_name (), value);
      else
        writer.writeAttribute (attribute->namespace_uri (), attribute->type_name (), value);
    }

  for (int i = 0; i < root->children_count (); i++)
    {
      write_item (root->child (i), writer);
    }

  writer.writeEndElement ();
}
예제 #19
0
파일: write.c 프로젝트: MattX/mulisp
void write(Object *object)
{
    write_item(object);
    printf("\n");
}
예제 #20
0
static void write_plain_string(struct buffer *buffer, char *bytes)
{
	write_item(buffer, bytes, strlen(bytes));
}
예제 #21
0
/*
 * This is implementation of NAIIOProvider::write_item method
 */
guint
cadp_iio_provider_write_item( const NAIIOProvider *provider, const NAObjectItem *item, GSList **messages )
{
	static const gchar *thisfn = "cadp_iio_provider_write_item";
	guint ret;
	CappDesktopFile *ndf;
	gchar *path;
	gchar *userdir;
	gchar *id;
	gchar *bname;
	GSList *subdirs;
	gchar *fulldir;
	gboolean dir_ok;

	ret = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR;

	g_return_val_if_fail( CADP_IS_DESKTOP_PROVIDER( provider ), ret );
	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), ret );

	if( na_object_is_readonly( item )){
		g_warning( "%s: item=%p is read-only", thisfn, ( void * ) item );
		return( ret );
	}

	ndf = ( CappDesktopFile * ) na_object_get_provider_data( item );

	/* write into the current key file and write it to current path */
	if( ndf ){
		g_return_val_if_fail( CADP_IS_DESKTOP_FILE( ndf ), ret );

	} else {
		userdir = cadp_xdg_dirs_get_user_data_dir();
		subdirs = na_core_utils_slist_from_split( CADP_DESKTOP_PROVIDER_SUBDIRS, G_SEARCHPATH_SEPARATOR_S );
		fulldir = g_build_filename( userdir, ( gchar * ) subdirs->data, NULL );
		dir_ok = TRUE;

		if( !g_file_test( fulldir, G_FILE_TEST_IS_DIR )){
			if( g_mkdir_with_parents( fulldir, 0750 )){
				g_warning( "%s: %s: %s", thisfn, userdir, g_strerror( errno ));
				dir_ok = FALSE;
			} else {
				na_core_utils_dir_list_perms( userdir, thisfn );
			}
		}
		g_free( userdir );
		na_core_utils_slist_free( subdirs );

		if( dir_ok ){
			id = na_object_get_id( item );
			bname = g_strdup_printf( "%s%s", id, CADP_DESKTOP_FILE_SUFFIX );
			g_free( id );
			path = g_build_filename( fulldir, bname, NULL );
			g_free( bname );
		}
		g_free( fulldir );

		if( dir_ok ){
			ndf = cadp_desktop_file_new_for_write( path );
			na_object_set_provider_data( item, ndf );
			g_object_weak_ref( G_OBJECT( item ), ( GWeakNotify ) desktop_weak_notify, ndf );
			g_free( path );
		}
	}

	if( ndf ){
		ret = write_item( provider, item, ndf, messages );
	}

	return( ret );
}