Esempio n. 1
0
static bool
check(const struct grid_info grid, const struct image_info img)
{
        uint32_t pixels[4 * N], expect[4 * N];

        return init_image_pixels(img, 0, expect) &&
                download_image(img, 1, pixels) &&
                check_pixels_v(img, pixels, expect);
}
Esempio n. 2
0
int login()
{
    int image = 0;
    int rc;
    str_t password;
    unsigned char p[MD5_DIGEST_LENGTH << 1];

    rc = want_image(&image);
    if (!rc) return 0;

    if (image)
    {
        size_t i;

        conf_val_t captcha_path_value = conf_lookup(&robot.conf, str_from("CAPTCHA"));
        str_t captcha_path;
        if (captcha_path_value.type != CONF_VALUE_TYPE_STRING)
        {
            fprintf(stdout, "Warning: Unset CAPTCHA variable, the default value is captcha.jpeg!!!!\n");
            fflush(stdout);
            captcha_path = str_from("captcha.jpeg");
        }
        else captcha_path = captcha_path_value.string;

        rc = download_image(captcha_path);
        if (!rc) return 0;

        fprintf(stdout, "Please input verify_code(in %s)\n", captcha_path.ptr);
        fflush(stdout);
        if (scanf("%s", (char*)robot.verify_code) > VERIFY_LEN)
        {
            fprintf(stderr, "verify_code is to long!!!!\n");
            return 0;
        }
        for (i = 0; i < VERIFY_LEN; ++i) robot.verify_code[i] = toupper(robot.verify_code[i]);
        robot.verify_code[VERIFY_LEN] = 0;
    }

    password = conf_lookup(&robot.conf, str_from("PASSWORD")).string;
    encode_password(password, robot.verify_code, robot.bits, p);

    rc = login_step1(p);
    if (!rc) return 0;

    rc = login_step2();
    if (!rc) return 0;

    fprintf(stdout, "Login successed ...\n");
    fflush(stdout);

    return 1;
}
Esempio n. 3
0
static bool
check(const struct image_info img)
{
        uint32_t pixels[N];
        uint32_t expect[N];
        int i;

        for (i = 0; i < N; ++i)
                expect[i] = (i > W ? 2 : 1) + (i % 2 ? -1 : 1);

        return download_image(img, 0, pixels) &&
                check_pixels_v(img, pixels, expect);
}
Esempio n. 4
0
static bool
check_discard(const struct grid_info grid, const struct image_info img,
              unsigned w, unsigned h)
{
        uint32_t pixels[H][W], expect[H][W];
        int i, j;

        for (i = 0; i < W; ++i)
                for (j = 0; j < H; ++j)
                        expect[j][i] = (i % 5 == 0 ? 0 : 1) + j;

        return download_image(img, 0, pixels[0]) &&
                check_pixels_v(img, pixels[0], expect[0]);
}
Esempio n. 5
0
static bool
check(const struct grid_info grid, const struct image_info img, unsigned l)
{
        const unsigned layer_sz = 4 * product(grid.size);
        uint32_t pixels_fb[4 * N], expect_fb[4 * N];
        uint32_t pixels_img[4 * N], expect_img[4 * N];
        unsigned i;

        if (!download_result(grid, pixels_fb) ||
            !download_image(img, 0, pixels_img))
                return false;

        for (i = 0; i < layer_sz; ++i) {
                /*
                 * The framebuffer contents should reflect layer l of
                 * the image which is bound to the image unit.
                 */
                expect_fb[i] = encode(grid.format, layer_sz * l + i);
        }

        for (i = 0; i < 4 * N; ++i) {
                if (i / layer_sz == l) {
                        /*
                         * Layer l should have been modified by the
                         * shader.
                         */
                        expect_img[i] = encode(img.format, 33);
                } else {
                        /*
                         * Other layers should have remained
                         * unchanged.
                         */
                        expect_img[i] = encode(img.format, i);
                }
        }

        if (!check_pixels_v(image_info_for_grid(grid), pixels_fb, expect_fb)) {
                printf("  Source: framebuffer\n");
                return false;
        }

        if (!check_pixels_v(img, pixels_img, expect_img)) {
                printf("  Source: image\n");
                return false;
        }

        return true;
}
///=================================================================================///
void
mgreader::start_downloading()
{
	do {
		dlder_br.open(mgreader_current_page_url,100);
	} while(dlder_br.error());
	if ( !not_published() ) {
		scrap_page();
		manage_chapters();
		download_image();
		go_to_next_page();
	}
	else {
		dlder_stop_flag = true;
	}
}
/**
* renewImage function
* reloads image in Element
*/
void ActionBar::renewImage() {

    // Download avatar image:
    std::string str = mediaLinks.at(picIndex);

    // Extract file extension
    size_t i = str.rfind('.', str.length());
    std::string ext = str.substr(i + 1, str.length() - i);

    // Set filename using this rule: profile_ + Profile ID + extension
    std::string filename = "img/tmp/picture_" + str.substr(str.size() - 9, str.size() - 5) + "." + ext;

    std::string path = CONTENT_PATH + std::string("/") + filename;
    download_image((char*)str.c_str(), (char*)path.c_str());
    eyegui::ImageAlignment alignment = eyegui::ImageAlignment::ORIGINAL;
    eyegui::replaceElementWithPicture(pLayout, "shownPicture", filename, alignment, false);
}
Esempio n. 8
0
bool
download_result(const struct grid_info grid, uint32_t *r_pixels)
{
        if (grid.stages & GL_COMPUTE_SHADER_BIT) {
                /* No actual framebuffer.  Results are returned into
                 * an image. */
                return download_image(image_info_for_grid(grid),
                                      max_image_units(), r_pixels);

        } else {
                glReadPixels(0, 0, grid.size.x, grid.size.y,
                             grid.format->pixel_format,
                             image_base_type(grid.format),
                             r_pixels);
                return piglit_check_gl_error(GL_NO_ERROR);
        }
}
static void
download_cb(ResourceData* data,
    gpointer udata)
{
    RETURN_IF_FAIL(data != NULL);

    g_autoptr(GdkPixbuf) ret = NULL;
    g_autoptr(GError) err = NULL;
    gboolean from_file = FALSE;

    ret = download_image(data->self, data->uri, data->name, data->msg,
        data->istream, &from_file, &err);

    data->cb(from_file ? NULL : g_steal_pointer(&ret),
        data->udata, g_steal_pointer(&err));

    resource_data_free(data);
}
Esempio n. 10
0
void
mgpark::download_each_imgs()
{
	manage_chapters();
	for (int i=0;i<mgpark_imgs.size();i++) {
		dlder_url_img = mgpark_imgs[i];
		if (dlder_stop_flag ) {
			return;
		}
		else {
			while (dlder_paused_flag) {
				sleep(3);
			}
			download_image();
			increase_current();
		}
	}
}
Esempio n. 11
0
static bool
check(const struct image_info img)
{
        const unsigned n = image_num_components(img.format) * product(img.size);
        uint32_t *pixels = malloc(sizeof(uint32_t) * n);
        uint32_t *expect = malloc(sizeof(uint32_t) * n);
        bool ret;
        int i;

        for (i = 0; i < n; ++i)
                expect[i] = encode(img.format, i);

        ret = download_image(img, 1, pixels) &&
                check_pixels_v(img, pixels, expect);

        free(expect);
        free(pixels);
        return ret;
}
/**
* showUsers function
* shows Content of the SearchPageArea
* shows the the Users which where found
*/
void SearchPageArea::showUsers() {
    counter = 0;
    std::string temp = "\n";
    std::string temp2 = " @";
    for (rapidjson::SizeType i = index; (i < content.Size()) && (i < index + 4); i++) {
        counter++;
        eyegui::setContentOfTextBlock(pLayout, textboxes[3 * (i - index) + 2], "Follower: ");
        eyegui::setContentOfTextBlock(pLayout, textboxes[3 * (i - index) + 3], std::to_string(content[i]["followers_count"].GetInt()));
        eyegui::setContentOfTextBlock(pLayout, textboxes[3 * (i - index) + 1], content[i]["screen_name"].GetString() +temp2+ content[i]["name"].GetString()+temp+content[i]["description"].GetString());

        // Download avatar image:
        std::string str = content[i]["profile_image_url"].GetString();

        // Extract file extension
        size_t z = str.rfind('.', str.length());
        std::string ext = str.substr(z + 1, str.length() - z);

        // Set filename using this rule: profile_ + Profile ID + extension
        std::string filename = "img/tmp/profile_" + std::string(content[i]["id_str"].GetString()) + "." + ext;

        // Replace substring '_normal.' with '_400x400' to get profile image in the size of 400x400 pixels.
        int indexStr = str.find("_normal.");
        str = str.replace(indexStr, 8, "_400x400.");

        std::string path = CONTENT_PATH + std::string("/") + filename;
        download_image((char*)str.c_str(), (char*)path.c_str());

        eyegui::ImageAlignment alignment = eyegui::ImageAlignment::ORIGINAL;
        eyegui::replaceElementWithPicture(pLayout, "profilePic" + std::to_string(i - index + 1), filename, alignment, false);

    }
    std::string fillUp = " ";
    for (int r = counter; r < 4; r++)
    {

        eyegui::setContentOfTextBlock(pLayout, textboxes[3 * (r)+1], fillUp);
        eyegui::setContentOfTextBlock(pLayout, textboxes[3 * (r)+2], fillUp);
        eyegui::setContentOfTextBlock(pLayout, textboxes[3 * (r)+3], fillUp);
        eyegui::ImageAlignment alignment = eyegui::ImageAlignment::ORIGINAL;
        eyegui::replaceElementWithPicture(pLayout, "profilePic" + std::to_string(r + 1), "img/invisProf.png", alignment, false);
    }
}
GdkPixbuf*
gt_resource_downloader_download_image(GtResourceDownloader* self,
    const gchar* uri, const gchar* name, GError** error)
{
    RETURN_VAL_IF_FAIL(GT_IS_RESOURCE_DOWNLOADER(self), NULL);
    RETURN_VAL_IF_FAIL(!utils_str_empty(uri), NULL);

    GtResourceDownloaderPrivate* priv = gt_resource_downloader_get_instance_private(self);
    g_autoptr(SoupMessage) msg = NULL;
    g_autoptr(GInputStream) istream = NULL;
    g_autoptr(GdkPixbuf) ret = NULL;
    g_autoptr(GError) err = NULL;

    DEBUG("Downloading image from uri '%s'", uri);

    msg = soup_message_new(SOUP_METHOD_GET, uri);

    /* NOTE: So libsoup isn't actually all that thread safe and
     * calling soup_session_send from multiple threads causes it to
     * crash, so we wrap a mutex around it. One should use the
     * download_image_immediately func if one wants to download
     * several images at the same time */
    g_mutex_lock(&priv->mutex);
    istream = soup_session_send(priv->soup, msg, NULL, &err);
    g_mutex_unlock(&priv->mutex);

    if (err)
    {
        WARNING("Unable to download image from uri '%s' because: %s",
            uri, err->message);

        g_propagate_prefixed_error(error, g_steal_pointer(&err),
            "Unable to download image from uri '%s' because: ", uri);

        return NULL;
    }

    ret = download_image(self, uri, name, msg, istream, NULL, error);

    return g_steal_pointer(&ret);
}
Esempio n. 14
0
static bool
check_derivative(const struct grid_info grid, const struct image_info img,
                 unsigned w, unsigned h)
{
        uint32_t pixels_fb[H][W], expect_fb[H][W];
        uint32_t pixels_img[H][W], expect_img[H][W];
        int i, j;

        for (i = 0; i < W; ++i) {
                for (j = 0; j < H; ++j) {
                        expect_fb[j][i] = (j < h && i < w ? 1000 :
                                           encode(get_image_format(GL_R32F), 0.5));
                        expect_img[j][i] = (j < h && i < w ? 1 : 0) + j;
                }
        }

        if (!download_result(grid, pixels_fb[0]) ||
            !download_image(img, 0, pixels_img[0]))
                return false;

        if (!check_pixels_v(img, pixels_fb[0], expect_fb[0])) {
                printf("  Source: framebuffer\n");
                /*
                 * Purely informational check, we don't care what the
                 * result is as long as derivatives are being
                 * calculated, don't fail if the result doesn't equal
                 * the expected value as it's most likely an accuracy
                 * issue.
                 */
        }

        if (!check_pixels_v(img, pixels_img[0], expect_img[0])) {
                printf("  Source: image\n");
                return false;
        }

        return true;
}
Esempio n. 15
0
int usb_boot(struct usb_device *usbdev, u16 pid)
{
	int i, ret = 0;
	struct file *filp = NULL;
	struct inode *inode = NULL;
	static mm_segment_t fs;
	struct img_header hdr;
	struct fw_info fw_info;
	loff_t pos = 0;
	char *img_name = UIMG_PATH;
	int len;

	tx_buf = (u8 *)kmalloc(DOWNLOAD_SIZE, GFP_KERNEL);
	if (tx_buf == NULL) {
		printk(KERN_ERR "Error: kmalloc\n");
		return -ENOMEM;
	}

	fs = get_fs();
	set_fs(get_ds());

	filp = filp_open(img_name, O_RDONLY | O_LARGEFILE, 0);
	if (IS_ERR(filp)) {
		printk(KERN_ERR "Can't find %s.\n", img_name);
		set_fs(fs);
		ret = -ENOENT;
		goto restore_fs;
	}

	if (filp->f_dentry)
		inode = filp->f_dentry->d_inode;
	if (!inode || !S_ISREG(inode->i_mode)) {
		printk(KERN_ERR "Invalid file type: %s\n", img_name);
		ret = -EINVAL;
		goto out;
	}

	len = filp->f_op->read(filp, (u8 *)&hdr, sizeof(hdr), &pos);
	if (len != sizeof(hdr)) {
		printk(KERN_ERR "gdmwm: Cannot read the image info.\n");
		ret = -EIO;
		goto out;
	}

	array_le32_to_cpu((u32 *)&hdr, 19);
#if 0
	if (hdr.magic_code != 0x10767fff) {
		printk(KERN_ERR "gdmwm: Invalid magic code 0x%08x\n", hdr.magic_code);
		ret = -EINVAL;
		goto out;
	}
#endif
	if (hdr.count > MAX_IMG_CNT) {
		printk(KERN_ERR "gdmwm: Too many images. %d\n", hdr.count);
		ret = -EINVAL;
		goto out;
	}

	for (i = 0; i < hdr.count; i++) {
		if (hdr.offset[i] > hdr.len) {
			printk(KERN_ERR "gdmwm: Invalid offset. Entry = %d Offset = 0x%08x Image length = 0x%08x\n", i, hdr.offset[i], hdr.len);
			ret = -EINVAL;
			goto out;
		}

		pos = hdr.offset[i];
		len = filp->f_op->read(filp, (u8 *)&fw_info, sizeof(fw_info), &pos);
		if (len != sizeof(fw_info)) {
			printk(KERN_ERR "gdmwm: Cannot read the FW info.\n");
			ret = -EIO;
			goto out;
		}

		array_le32_to_cpu((u32 *)&fw_info, 8);
#if 0
		if ((fw_info.id & 0xfffff000) != 0x10767000) {
			printk(KERN_ERR "gdmwm: Invalid FW id. 0x%08x\n", fw_info.id);
			ret = -EIO;
			goto out;
		}
#endif

		if ((fw_info.id & 0xffff) != pid)
			continue;

		pos = hdr.offset[i] + fw_info.kernel_offset;
		ret = download_image(usbdev, filp, &pos, fw_info.kernel_len,
				DN_KERNEL_MAGIC_NUMBER);
		if (ret < 0)
			goto out;
		printk("GCT: Kernel download success.\n");

		pos = hdr.offset[i] + fw_info.rootfs_offset;
		ret = download_image(usbdev, filp, &pos, fw_info.rootfs_len,
				DN_ROOTFS_MAGIC_NUMBER);
		if (ret < 0)
			goto out;
		printk("GCT: Filesystem download success.\n");

		break;
	}

	if (i == hdr.count) {
		printk(KERN_ERR "Firmware for gsk%x is not installed.\n", pid);
		ret = -EINVAL;
	}
out:
	filp_close(filp, current->files);

restore_fs:
	set_fs(fs);
	kfree(tx_buf);
	return ret;
}
Esempio n. 16
0
int usb_boot(struct usb_device *usbdev, u16 pid)
{
	int i, ret = 0;
	struct img_header hdr;
	struct fw_info fw_info;
	loff_t pos = 0;
	char *img_name = FW_DIR FW_UIMG;
	const struct firmware *firm;

	ret = request_firmware(&firm, img_name, &usbdev->dev);
	if (ret < 0) {
		dev_err(&usbdev->dev,
			"requesting firmware %s failed with error %d\n",
			img_name, ret);
		return ret;
	}

	tx_buf = kmalloc(DOWNLOAD_SIZE, GFP_KERNEL);
	if (tx_buf == NULL)
		return -ENOMEM;

	if (firm->size < sizeof(hdr)) {
		dev_err(&usbdev->dev, "Cannot read the image info.\n");
		ret = -EIO;
		goto out;
	}
	memcpy(&hdr, firm->data, sizeof(hdr));

	array_le32_to_cpu((u32 *)&hdr, 19);

	if (hdr.count > MAX_IMG_CNT) {
		dev_err(&usbdev->dev, "Too many images. %d\n", hdr.count);
		ret = -EINVAL;
		goto out;
	}

	for (i = 0; i < hdr.count; i++) {
		if (hdr.offset[i] > hdr.len) {
			dev_err(&usbdev->dev,
				"Invalid offset. Entry = %d Offset = 0x%08x Image length = 0x%08x\n",
				i, hdr.offset[i], hdr.len);
			ret = -EINVAL;
			goto out;
		}

		pos = hdr.offset[i];
		if (firm->size < sizeof(fw_info) + pos) {
			dev_err(&usbdev->dev, "Cannot read the FW info.\n");
			ret = -EIO;
			goto out;
		}
		memcpy(&fw_info, firm->data + pos, sizeof(fw_info));

		array_le32_to_cpu((u32 *)&fw_info, 8);

		if ((fw_info.id & 0xffff) != pid)
			continue;

		pos = hdr.offset[i] + fw_info.kernel_offset;
		if (firm->size < fw_info.kernel_len + pos) {
			dev_err(&usbdev->dev, "Kernel FW is too small.\n");
			goto out;
		}

		ret = download_image(usbdev, firm, pos, fw_info.kernel_len,
				     DN_KERNEL_MAGIC_NUMBER);
		if (ret < 0)
			goto out;
		dev_info(&usbdev->dev, "GCT: Kernel download success.\n");

		pos = hdr.offset[i] + fw_info.rootfs_offset;
		if (firm->size < fw_info.rootfs_len + pos) {
			dev_err(&usbdev->dev, "Filesystem FW is too small.\n");
			goto out;
		}
		ret = download_image(usbdev, firm, pos, fw_info.rootfs_len,
				     DN_ROOTFS_MAGIC_NUMBER);
		if (ret < 0)
			goto out;
		dev_info(&usbdev->dev, "GCT: Filesystem download success.\n");

		break;
	}

	if (i == hdr.count) {
		dev_err(&usbdev->dev, "Firmware for gsk%x is not installed.\n",
			pid);
		ret = -EINVAL;
	}
out:
	release_firmware(firm);
	kfree(tx_buf);
	return ret;
}