void ArgumentCoder<WebCore::GraphicsSurfaceToken>::encode(ArgumentEncoder& encoder, const WebCore::GraphicsSurfaceToken& token)
{
#if OS(DARWIN)
    encoder << Attachment(token.frontBufferHandle, MACH_MSG_TYPE_MOVE_SEND);
    encoder << Attachment(token.backBufferHandle, MACH_MSG_TYPE_MOVE_SEND);
#elif OS(WINDOWS)
    encoder << reinterpret_cast<uint64_t>(token.frontBufferHandle);
    encoder << reinterpret_cast<uint64_t>(token.backBufferHandle);
#elif OS(LINUX)
    encoder << token.frontBufferHandle;
#endif
}
Пример #2
0
QList<Attachment> Attachments::attachments()
{
  QList<Attachment> attached;
  int i; int c = attList->count();
  for( i=0; i<c; ++i )
    attached.append( Attachment(
      attList->item(i)->text(),
      attList->item(i)->data( URI_ROLE ).toString() ) );
  return attached;
}
Пример #3
0
GLFramebuffer::Attachment GLFramebuffer::getAttachment(const GLenum attachmentPoint) const
{
	std::vector<Attachment>::const_iterator ait = attachments.cbegin();
	while(ait != attachments.cend()) {
		if (ait->point == attachmentPoint) {
			return (*ait);
		}
	}

	//TODO: This sucks! Do it right.
	return Attachment();
}
Пример #4
0
void Framebuffer::set(AttachmentPoint ap, const TextureRef& texture) {
    if (texture.isNull()) {
        // We're in the wrong overload
        set(ap, (void*)NULL);
        return;
    }

    // Get current framebuffer
    GLint origFB = glGetInteger(GL_FRAMEBUFFER_BINDING_EXT);

    // If we aren't already bound, bind us now
    if (origFB != (GLint)openGLID()) {
        // Bind this framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, openGLID());
        debugAssertGLOk();
    }

    // Check for completeness
    if (numAttachments == 0) {
        // This is the first attachment.
        // Set texture height/width
        m_width  = texture->texelWidth();
        m_height = texture->texelHeight();
    } else {
        // Verify same dimensions
        debugAssertM((texture->texelWidth() != width()) || 
                      (texture->texelHeight() != height()), 
           "All attachments bound to a Framebuffer must "
                     "have identical dimensions!");
    }
    
    if (! attachmentTable.containsKey(ap)) {
        attachmentTable.set(ap, Attachment(texture));
    }

    // Bind texture to framebuffer
    glFramebufferTexture2DEXT(
        GL_FRAMEBUFFER_EXT, 
        ap, 
        texture->openGLTextureTarget(), 
        texture->openGLID(), 0);
    debugAssertGLOk();

    // If we were already bound, don't bother restoring
    if (origFB != (GLint)openGLID()) {
        // Bind original framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, origFB);
    }

    debugAssertGLOk();
}
Пример #5
0
Attachment Document::getAttachment(const string &attachmentId)
{
   Object data = boost::any_cast<Object>(*getData());

   if(data.find("_attachments") == data.end())
      throw Exception("No attachments");

   Object attachments = boost::any_cast<Object>(*data["_attachments"]);
   if(attachments.find(attachmentId) == attachments.end())
      throw Exception("No attachment found with id '" + attachmentId + "'");

   Object attachment = boost::any_cast<Object>(*attachments[attachmentId]);

   return Attachment(comm, db, id, attachmentId, "", boost::any_cast<string>(*attachment["content_type"]));
}
Пример #6
0
void Attachments::edit()
{
  QListWidgetItem *listItem = attList->currentItem();
  if( !listItem ) return;

  AttDialog dialog( Attachment( listItem->text(), listItem->data(URI_ROLE).toString() ) );
  int result = dialog.exec();

  if( result == QDialog::Rejected
      || ( dialog.name().isEmpty() && dialog.uri().isEmpty() )
    ) return;

  listItem->setText( !dialog.name().isEmpty() ? dialog.name() : dialog.uri() );
  listItem->setToolTip( dialog.uri() );
  listItem->setData( URI_ROLE, dialog.uri() );
}
Пример #7
0
vector<Attachment> Document::getAllAttachments()
{
   Object data = boost::any_cast<Object>(*getData());

   if(data.find("_attachments") == data.end())
      throw Exception("No attachments");

   vector<Attachment> vAttachments;

   Object attachments = boost::any_cast<Object>(*data["_attachments"]);

   Object::iterator attachmentItr = attachments.begin();
   const Object::iterator &attachmentEnd = attachments.end();
   for(; attachmentItr != attachmentEnd; ++attachmentItr)
   {
      const string &attachmentId = attachmentItr->first;
      Object attachment = boost::any_cast<Object>(*attachmentItr->second);

      vAttachments.push_back(Attachment(comm, db, id, attachmentId, "",
                                        boost::any_cast<string>(*attachment["content_type"])));
   }

   return vAttachments;
}
Пример #8
0
static PassOwnPtr<ArgumentDecoder> createArgumentDecoder(mach_msg_header_t* header)
{
    if (!(header->msgh_bits & MACH_MSGH_BITS_COMPLEX)) {
        // We have a simple message.
        size_t bodySize = header->msgh_size - sizeof(mach_msg_header_t);
        uint8_t* body = reinterpret_cast<uint8_t*>(header + 1);
        
        return adoptPtr(new ArgumentDecoder(body, bodySize));
    }

    bool messageBodyIsOOL = header->msgh_id & MessageBodyIsOOL;

    mach_msg_body_t* body = reinterpret_cast<mach_msg_body_t*>(header + 1);
    mach_msg_size_t numDescriptors = body->msgh_descriptor_count;
    ASSERT(numDescriptors);

    // Build attachment list
    Deque<Attachment> attachments;
    uint8_t* descriptorData = reinterpret_cast<uint8_t*>(body + 1);

    // If the message body was sent out-of-line, don't treat the last descriptor
    // as an attachment, since it is really the message body.
    if (messageBodyIsOOL)
        --numDescriptors;

    for (mach_msg_size_t i = 0; i < numDescriptors; ++i) {
        mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);

        switch (descriptor->type.type) {
        case MACH_MSG_PORT_DESCRIPTOR:
            attachments.append(Attachment(descriptor->port.name, descriptor->port.disposition));
            descriptorData += sizeof(mach_msg_port_descriptor_t);
            break;
        case MACH_MSG_OOL_DESCRIPTOR:
            attachments.append(Attachment(descriptor->out_of_line.address, descriptor->out_of_line.size,
                                          descriptor->out_of_line.copy, descriptor->out_of_line.deallocate));
            descriptorData += sizeof(mach_msg_ool_descriptor_t);
            break;
        default:
            ASSERT(false && "Unhandled descriptor type");
        }
    }

    if (messageBodyIsOOL) {
        mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
        ASSERT(descriptor->type.type == MACH_MSG_OOL_DESCRIPTOR);
        Attachment messageBodyAttachment(descriptor->out_of_line.address, descriptor->out_of_line.size,
                                         descriptor->out_of_line.copy, descriptor->out_of_line.deallocate);

        uint8_t* messageBody = static_cast<uint8_t*>(messageBodyAttachment.address());
        size_t messageBodySize = messageBodyAttachment.size();

        ArgumentDecoder* argumentDecoder;

        if (attachments.isEmpty())
            argumentDecoder = new ArgumentDecoder(messageBody, messageBodySize);
        else
            argumentDecoder = new ArgumentDecoder(messageBody, messageBodySize, attachments);

        vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(messageBodyAttachment.address()), messageBodyAttachment.size());

        return adoptPtr(argumentDecoder);
    }

    uint8_t* messageBody = descriptorData;
    size_t messageBodySize = header->msgh_size - (descriptorData - reinterpret_cast<uint8_t*>(header));

    return adoptPtr(new ArgumentDecoder(messageBody, messageBodySize, attachments));
}
Пример #9
0
bool Connection::sendOutgoingMessage(MessageID messageID, PassOwnPtr<ArgumentEncoder> arguments)
{
    Vector<Attachment> attachments = arguments->releaseAttachments();
    
    size_t numberOfPortDescriptors = 0;
    size_t numberOfOOLMemoryDescriptors = 0;
    for (size_t i = 0; i < attachments.size(); ++i) {
        Attachment::Type type = attachments[i].type();
        if (type == Attachment::MachPortType)
            numberOfPortDescriptors++;
        else if (type == Attachment::MachOOLMemoryType)
            numberOfOOLMemoryDescriptors++;
    }
    
    size_t messageSize = machMessageSize(arguments->bufferSize(), numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
    char buffer[inlineMessageMaxSize];

    bool messageBodyIsOOL = false;
    if (messageSize > sizeof(buffer)) {
        messageBodyIsOOL = true;

        attachments.append(Attachment(arguments->buffer(), arguments->bufferSize(), MACH_MSG_VIRTUAL_COPY, false));
        numberOfOOLMemoryDescriptors++;
        messageSize = machMessageSize(0, numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
    }

    bool isComplex = (numberOfPortDescriptors + numberOfOOLMemoryDescriptors > 0);

    mach_msg_header_t* header = reinterpret_cast<mach_msg_header_t*>(&buffer);
    header->msgh_bits = isComplex ? MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND | MACH_MSGH_BITS_COMPLEX, 0) : MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
    header->msgh_size = messageSize;
    header->msgh_remote_port = m_sendPort;
    header->msgh_local_port = MACH_PORT_NULL;
    header->msgh_id = messageID.toInt();
    if (messageBodyIsOOL)
        header->msgh_id |= MessageBodyIsOOL;

    uint8_t* messageData;

    if (isComplex) {
        mach_msg_body_t* body = reinterpret_cast<mach_msg_body_t*>(header + 1);
        body->msgh_descriptor_count = numberOfPortDescriptors + numberOfOOLMemoryDescriptors;

        uint8_t* descriptorData = reinterpret_cast<uint8_t*>(body + 1);
        for (size_t i = 0; i < attachments.size(); ++i) {
            Attachment attachment = attachments[i];

            mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
            switch (attachment.type()) {
            case Attachment::MachPortType:
                descriptor->port.name = attachment.port();
                descriptor->port.disposition = attachment.disposition();
                descriptor->port.type = MACH_MSG_PORT_DESCRIPTOR;            

                descriptorData += sizeof(mach_msg_port_descriptor_t);
                break;
            case Attachment::MachOOLMemoryType:
                descriptor->out_of_line.address = attachment.address();
                descriptor->out_of_line.size = attachment.size();
                descriptor->out_of_line.copy = attachment.copyOptions();
                descriptor->out_of_line.deallocate = attachment.deallocate();
                descriptor->out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;            

                descriptorData += sizeof(mach_msg_ool_descriptor_t);
                break;
            default:
                ASSERT_NOT_REACHED();
            }
        }

        messageData = descriptorData;
    } else
        messageData = (uint8_t*)(header + 1);

    // Copy the data if it is not being sent out-of-line.
    if (!messageBodyIsOOL)
        memcpy(messageData, arguments->buffer(), arguments->bufferSize());

    ASSERT(m_sendPort);
    
    // Send the message.
    kern_return_t kr = mach_msg(header, MACH_SEND_MSG, messageSize, 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
    if (kr != KERN_SUCCESS) {
        // FIXME: What should we do here?
    }

    return true;
}
Пример #10
0
Attachment Attachment::fromData(const QVariant &data)
{
    return Attachment(data.toMap());
}
Пример #11
0
bool Connection::processMessage()
{
    if (m_readBufferSize < sizeof(MessageInfo))
        return false;

    uint8_t* messageData = m_readBuffer.data();
    MessageInfo messageInfo;
    memcpy(&messageInfo, messageData, sizeof(messageInfo));
    messageData += sizeof(messageInfo);

    size_t messageLength = sizeof(MessageInfo) + messageInfo.attachmentCount() * sizeof(AttachmentInfo) + (messageInfo.isMessageBodyIsOutOfLine() ? 0 : messageInfo.bodySize());
    if (m_readBufferSize < messageLength)
        return false;

    size_t attachmentFileDescriptorCount = 0;
    size_t attachmentCount = messageInfo.attachmentCount();
    std::unique_ptr<AttachmentInfo[]> attachmentInfo;

    if (attachmentCount) {
        attachmentInfo = std::make_unique<AttachmentInfo[]>(attachmentCount);
        memcpy(attachmentInfo.get(), messageData, sizeof(AttachmentInfo) * attachmentCount);
        messageData += sizeof(AttachmentInfo) * attachmentCount;

        for (size_t i = 0; i < attachmentCount; ++i) {
            switch (attachmentInfo[i].getType()) {
            case Attachment::MappedMemoryType:
            case Attachment::SocketType:
                if (!attachmentInfo[i].isNull())
                    attachmentFileDescriptorCount++;
                break;
            case Attachment::Uninitialized:
            default:
                ASSERT_NOT_REACHED();
                break;
            }
        }

        if (messageInfo.isMessageBodyIsOutOfLine())
            attachmentCount--;
    }

    Vector<Attachment> attachments(attachmentCount);
    AttachmentResourceGuard<Vector<Attachment>, Vector<Attachment>::iterator> attachementDisposer(attachments);
    RefPtr<WebKit::SharedMemory> oolMessageBody;

    size_t fdIndex = 0;
    for (size_t i = 0; i < attachmentCount; ++i) {
        int fd = -1;
        switch (attachmentInfo[i].getType()) {
        case Attachment::MappedMemoryType:
            if (!attachmentInfo[i].isNull())
                fd = m_fileDescriptors[fdIndex++];
            attachments[attachmentCount - i - 1] = Attachment(fd, attachmentInfo[i].getSize());
            break;
        case Attachment::SocketType:
            if (!attachmentInfo[i].isNull())
                fd = m_fileDescriptors[fdIndex++];
            attachments[attachmentCount - i - 1] = Attachment(fd);
            break;
        case Attachment::Uninitialized:
            attachments[attachmentCount - i - 1] = Attachment();
        default:
            break;
        }
    }

    if (messageInfo.isMessageBodyIsOutOfLine()) {
        ASSERT(messageInfo.bodySize());

        if (attachmentInfo[attachmentCount].isNull()) {
            ASSERT_NOT_REACHED();
            return false;
        }

        WebKit::SharedMemory::Handle handle;
        handle.adoptFromAttachment(m_fileDescriptors[attachmentFileDescriptorCount - 1], attachmentInfo[attachmentCount].getSize());

        oolMessageBody = WebKit::SharedMemory::create(handle, WebKit::SharedMemory::ReadOnly);
        if (!oolMessageBody) {
            ASSERT_NOT_REACHED();
            return false;
        }
    }

    ASSERT(attachments.size() == (messageInfo.isMessageBodyIsOutOfLine() ? messageInfo.attachmentCount() - 1 : messageInfo.attachmentCount()));

    uint8_t* messageBody = messageData;
    if (messageInfo.isMessageBodyIsOutOfLine())
        messageBody = reinterpret_cast<uint8_t*>(oolMessageBody->data());

    auto decoder = std::make_unique<MessageDecoder>(DataReference(messageBody, messageInfo.bodySize()), std::move(attachments));

    processIncomingMessage(std::move(decoder));

    if (m_readBufferSize > messageLength) {
        memmove(m_readBuffer.data(), m_readBuffer.data() + messageLength, m_readBufferSize - messageLength);
        m_readBufferSize -= messageLength;
    } else
        m_readBufferSize = 0;

    if (attachmentFileDescriptorCount) {
        if (m_fileDescriptorsSize > attachmentFileDescriptorCount) {
            size_t fileDescriptorsLength = attachmentFileDescriptorCount * sizeof(int);
            memmove(m_fileDescriptors.data(), m_fileDescriptors.data() + fileDescriptorsLength, m_fileDescriptorsSize - fileDescriptorsLength);
            m_fileDescriptorsSize -= fileDescriptorsLength;
        } else
            m_fileDescriptorsSize = 0;
    }


    return true;
}
Пример #12
0
void sendMail(GtkWidget* widget,struct GUI *gui){
	
	char addr[16];
	int sockfd;
	int n,i;
	
	/* Reset Statu Label */
	for(i=0;i<8;i++){
		gtk_label_set_text(GTK_LABEL(gui->statu[i]),"-");
	}
	
	/* Get host and port */
	gui->host = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptHost));
	gui->port = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptPort));
	
	/* Get From */
	gui->from = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptFrom));
	
	/* Get To */
	for(i=0;i<gui->c_to;i++){
		gui->to[i] = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptTo[i]));
	}
	
	/* Get Cc */
	for(i=0;i<gui->c_cc;i++){
		gui->cc[i] = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptCc[i]));
	}
	
	/* Get Bcc */
	for(i=0;i<gui->c_bcc;i++){
		gui->bcc[i] = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptBcc[i]));
	}
	
	/* Get Subject */
	gui->subject = (char *)gtk_entry_get_text(GTK_ENTRY(gui->iptSubject));
	
	/* Get Mailbody file */
	gui->mailbody = (char *)gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gui->btnOpenmail));
	
	/* Get Attachment files */
	for(i=0;i<gui->c_file;i++){
		gui->file[i] = (char *)gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gui->btnOpenfile[i]));
	}
	
	if(strcmp(gui->host,"")==0||strcmp(gui->port,"")==0){
		gtk_label_set_text(GTK_LABEL(gui->statu[0]),"X");
		gtk_widget_show_all(gui->window);
		printf("host or port is (are) null string\n");
		return;
	}
	
	/* Connect to mail server */
	sockfd = connectToHost(gui->host,gui->port,addr);
	if(sockfd==-1){
		/* Connect Fail */
		printf("Connect to host %s:%s fail\n",gui->host,gui->port);
		gtk_label_set_text(GTK_LABEL(gui->statu[0]),"X");
		gtk_widget_show_all(gui->window);
		return;
	}else{
		printf("Connect to host %s(%s):%s\n",gui->host,addr,gui->port);
		
		n = HELO(sockfd);
		if(n==-1){
			close(sockfd);
			printf("Close SimpleMail.\n");
			gtk_label_set_text(GTK_LABEL(gui->statu[0]),"X");
			gtk_widget_show_all(gui->window);
			return;
		}
		gtk_label_set_text(GTK_LABEL(gui->statu[0]),"O");
		gtk_widget_show_all(gui->window);
		
		
		n = MAIL(sockfd,gui->from);
		if(n==-1){
			close(sockfd);
			printf("Close SimpleMail.\n");
			gtk_label_set_text(GTK_LABEL(gui->statu[1]),"X");
			gtk_widget_show_all(gui->window);
			return;
		}
		gtk_label_set_text(GTK_LABEL(gui->statu[1]),"O");
		gtk_widget_show_all(gui->window);
		
		
		n = RCPT(sockfd,gui->to,gui->c_to,gui->cc,gui->c_cc,gui->bcc,gui->c_bcc);
		switch(n){
			case -1:
				close(sockfd);
				printf("Close SimpleMail.\n");
				gtk_label_set_text(GTK_LABEL(gui->statu[2]),"X");
				gtk_widget_show_all(gui->window);
				return;
			case -2:
				close(sockfd);
				printf("Close SimpleMail.\n");
				gtk_label_set_text(GTK_LABEL(gui->statu[2]),"O");
				gtk_label_set_text(GTK_LABEL(gui->statu[3]),"X");
				gtk_widget_show_all(gui->window);
				return;
			case -3:
				close(sockfd);
				printf("Close SimpleMail.\n");
				gtk_label_set_text(GTK_LABEL(gui->statu[2]),"O");
				gtk_label_set_text(GTK_LABEL(gui->statu[3]),"O");
				gtk_label_set_text(GTK_LABEL(gui->statu[4]),"X");
				gtk_widget_show_all(gui->window);
				return;	
		}
		gtk_label_set_text(GTK_LABEL(gui->statu[2]),"O");
		gtk_label_set_text(GTK_LABEL(gui->statu[3]),"O");
		gtk_label_set_text(GTK_LABEL(gui->statu[4]),"O");
		gtk_widget_show_all(gui->window);
		
		
		n = MAIL_Headr(sockfd,gui->from,gui->to,gui->c_to,gui->cc,gui->c_cc,gui->bcc,gui->c_bcc,gui->subject,gui->c_file);
		if(n==-1){
			close(sockfd);
			printf("Close SimpleMail.\n");
			gtk_label_set_text(GTK_LABEL(gui->statu[5]),"X");
			gtk_widget_show_all(gui->window);
			return;
		}
		gtk_label_set_text(GTK_LABEL(gui->statu[5]),"O");
		gtk_widget_show_all(gui->window);
		
		
		MAIL_body(sockfd,gui->mailbody,gui->c_file);
		Attachment(sockfd,gui->file,gui->c_file);
		gtk_label_set_text(GTK_LABEL(gui->statu[6]),"O");
		
		
		n = EOM(sockfd,gui->c_file);
		if(n==-1){
			close(sockfd);
			printf("Close SimpleMail.\n");
			gtk_label_set_text(GTK_LABEL(gui->statu[7]),"X");
			gtk_widget_show_all(gui->window);
			return;
		}
		gtk_label_set_text(GTK_LABEL(gui->statu[7]),"O");
		gtk_widget_show_all(gui->window);
		
		
		n = QUIT(sockfd);
		if(n==-1){
			close(sockfd);
			printf("Close SimpleMail.\n");
			return;
		}
		
		printf("Send mail.\n");
		close(sockfd);	
	}
	
}