예제 #1
0
void EntitySet::writeToStream(Stream& stream)
{
	//primero se almacenan los objetos que pertencen al sistema 
 int i,num=(int)objects.size();
 int internalRelations=0;
 int tcpRelations=0;
 stream<<num;
   for(i=0;i<num;i++){
	 stream.write(objects[i]);
	 //compruebo si su parent es otro objeto de la colección
	 if(objects[i]->getLinkedTo()){
		 if(this==objects[i]->getLinkedTo()->getOwner())internalRelations++;
		 Tcp *check=dynamic_cast<Tcp *>(objects[i]->getLinkedTo());
		 if(check){
			 ComposedEntity *aux=dynamic_cast<ComposedEntity *>(check->getOwner());
			 if(aux){
				 if(this==aux->getOwner())tcpRelations++;
			 }
		 }
	 }
   }
   //transmito el numero de las relaciones que hay entre objetos
	 stream<<internalRelations;
   //transmito los emparejamientos
	for(i=0;i<num;i++){
		if(objects[i]->getLinkedTo())
			if(this==objects[i]->getLinkedTo()->getOwner()){
				int a=getIndexOf(objects[i]->getLinkedTo());
				stream<<i<<a;
			
			}
	}
	//transmito uniones a tcp´s
	stream<<tcpRelations;
	for(i=0;i<num;i++){
		if(objects[i]->getLinkedTo())
		{
				Tcp *check=dynamic_cast<Tcp *>(objects[i]->getLinkedTo());
				if(check){
					 ComposedEntity *aux=dynamic_cast<ComposedEntity *>(check->getOwner());
					 if(aux){ 
						 if(this==aux->getOwner()){
							int a=getIndexOf(aux);
							int b=aux->getTcpIndex(check);
							stream<<i<<a<<b;
						 }
					 }
				 }
			
		}
	}

  

}
예제 #2
0
void Container::remove( void *i )
{
//	if( !hasItem( i ) )
//		return;

	removeAt( getIndexOf( i ) );
}
예제 #3
0
int getSessionData(uint8_t *dst, uip_ipaddr_t *addr, SessionDataType type) {
    int i = getIndexOf(addr);
    if (i == -1) {
        PRINTF("getSessionData: Keine Daten zur gesuchten IP gefunden\n");
        return -1;
    }

    uint16_t epo_buf;
    uint32_t num_buf;
    Session_t *s = (Session_t *) RES_SESSION_LIST;
    switch (type) {
        case session_id:
            nvm_getVar(dst, (fpoint_t) &s[i].session, 8);
            return 8;
        case session_epoch:
            nvm_getVar(&epo_buf, (fpoint_t) &s[i].epoch, 2);
            epo_buf = uip_htons(epo_buf);
            memcpy(dst, &epo_buf, 2);
            return 2;
        case session_key:
            nvm_getVar(dst, (fpoint_t) &s[i].private_key, 32);
            return 32;
        case session_num_write:
            num_buf = uip_htonl(seq_num_w[i]);
            memcpy(dst + 2, &num_buf, 4);
            seq_num_w[i]++;
            return 6;
    }
    return 0;
}
예제 #4
0
void QTlenRosterManager::deleteItem(QTreeWidgetItem* item)
{
	if (getJidOf(item) != "-1")
	{
		rosterItems.removeAt(getIndexOf(getJidOf(item)));
		showRoster();
	}
};
예제 #5
0
int createSession(uint32_t *buf, uip_ipaddr_t *addr) {
    uint32_t i;

    Session_t *session = (Session_t *) (buf + 8);
    Session_t *s = (Session_t *) RES_SESSION_LIST; // Pointer auf Flashspeicher
    int index = getIndexOf(addr);

    // Ein neuer private Key für ECDH wird in jedem Fall generiert
    nvm_getVar(buf, RES_ECC_ORDER, LEN_ECC_ORDER);
    #if DEBUG
        printf("ECC_ORDER: ");
        for (i = 0; i < 8; i++) printf("%08X", uip_htonl(buf[i]));
        printf("\n");
    #endif
    do {
        random_x((uint8_t *) session->private_key, 32);
    } while (!ecc_is_valid_key(session->private_key, buf));

    // Falls schon ein Eintrag existiert wird die Session durch
    // setzten des neuen private Keys weiterentwickelt. Ansonsten
    // wird alles gesetzt.
    if (index >= 0) {
        nvm_setVar(session->private_key, (fpoint_t) s[index].private_key, 32);
        PRINTF("Session aktualisiert:\n");
        PRINTSESSION(index);
    } else {
        index = getIndexOf(NULL);;
        if (index < 0)
            return -1;

        uip_ipaddr_copy(&session->addr, addr);
        for (i = 0; i < 8; i++) {
            nvm_getVar(session->session + i, RES_ANSCHARS + (random_8() & 0x3F), 1);
        } // TODO session-id auf doppel prüfen
        session->epoch = 0;
        session->valid = 1;

        nvm_setVar(session, (fpoint_t) &s[index], sizeof(Session_t));
        PRINTF("Session erstellt:\n");
        PRINTSESSION(index);
        seq_num_r[index] = 1;
        seq_num_w[index] = 1;
    }

    return 0;
}
예제 #6
0
void QTlenRosterManager::setAvatar(QString jid, QPixmap avatar)
{
    int index = getIndexOf(jid);
	if (index != -1)
	{
	    rosterItems[index].avatar = avatar;
	    this->showRoster();
	}
}
	char * getValue(char * line){
		char * formated = trim(line);
		int indexEqual = getIndexOf(formated , '=');
		if(indexEqual > 0){
			return getSubString(formated , indexEqual +1 , strlen(formated)-1);
		}else{
			return NULL;
		}
	}
	char * getKey(char * line ){
		char * formated = trim(line);
		int indexEqual = getIndexOf(formated , '=');
		if(indexEqual > 0){
			return getSubString(formated , 0 , indexEqual -1);
		}else{
			return NULL;
		}
	}
예제 #9
0
void QTlenRosterManager::presenceFrom(QString jid,
				      QTlenPresence type,
				      QString description,
				      QString av_type,
				      QString digest)
{	
	if (getIndexOf(jid) != -1)
	{
		int index = getIndexOf(jid);
                rosterItems[index].presence     = type;
                rosterItems[index].desc         = description;
                rosterItems[index].avatar_type  = av_type;
                //TODO: fetch avatars
		if (av_type != "-1")
		{
		    QString nick = jid;
		    nick.chop(8);
		    QTlenAvatarsFetcher *fetcher = new QTlenAvatarsFetcher();
		    //token nick digest
		    connect(fetcher,
			    SIGNAL(gotAvatar(QString,QPixmap)),
			    this,
			    SLOT(setAvatar(QString, QPixmap)));
		    rosterItems[index].avatar = fetcher->getAvatar(av_manager, mailInfo, token, nick, digest);
		}
		sysIcon->showMessage(QString::fromUtf8("Zmiana statusu"), rosterItems[index].name + " ma teraz status " + QSStatus(type));
	}
	else
	{
		RosterItem i;
		i.jid = jid;
		i.name = jid;
		if (description.isEmpty())
			i.desc = "";
		else
			i.desc = description;
		i.subscription = "both";
		i.presence = type;
		i.group = "Tlen";
		rosterItems.append(i);
	}
	showRoster();
};
예제 #10
0
void QTlenRosterManager::addItem(QString jid, QString group, QString name, QString subscription)
{
	if (subscription != "remove")
	{
		if (getIndexOf(jid) != -1)
		{
			int index = getIndexOf(jid);
			if (name.isEmpty())
				rosterItems[index].name = jid;
			else
				rosterItems[index].name = name;
			if (group.isEmpty())
				rosterItems[index].group = "Tlen";
			else
				rosterItems[index].group = group;
			rosterItems[index].subscription = subscription;
		}
		else
		{
			RosterItem i;
			i.jid = jid;
			if (name.isEmpty())
				i.name = jid;
			else
				i.name = name;
			i.subscription = subscription;
			i.desc = QString::null;
                        i.avatar_type = "-1";
                        i.avatar = QPixmap();
			i.presence = Offline;
			if (group.isEmpty())
				i.group = "Tlen";
			else
				i.group = group;
			rosterItems.append(i);
		}
	}
	else
		rosterItems.removeAt(getIndexOf(jid));
	showRoster();
};
예제 #11
0
int deleteSession(uip_ipaddr_t *addr) {
    int index = getIndexOf(addr);
    if (index == -1) {
        PRINTF("delete Session: Ip nicht gefunden\n");
        return -1;
    }

    uint16_t valid = 0;
    Session_t *s = (Session_t *) RES_SESSION_LIST; // Pointer auf Flashspeicher
    nvm_setVar(&valid, (fpoint_t) &s[index].valid, 2);
    return 0;
}
예제 #12
0
파일: ArrayBag.cpp 프로젝트: robgle/csci133
bool ArrayBag<ItemType>::remove(const ItemType& anEntry)
{
    int locatedIndex = getIndexOf(anEntry);
    bool canRemoveItem = !isEmpty() && (locatedIndex > -1);
    if (canRemoveItem)
    {
        itemCount--;
        items[locatedIndex] = items[itemCount];
    }  // end if
    
    return canRemoveItem;
}  // end remove
예제 #13
0
int insertKeyBlock(uip_ipaddr_t *addr, KeyBlock_t *key_block) {
    int index = getIndexOf(addr);
    if (index == -1) {
        PRINTF("insertKeyBlock: Ip nicht gefunden\n");
        return -1;
    }

    PRINTF("Daten vor Insert KeyBlock:\n");
    PRINTSESSION(index);
    KeyBlock_t *ck = (KeyBlock_t *) RES_KEY_BLOCK_LIST;
    nvm_setVar(key_block, (fpoint_t) &ck[(2 * index) + 1], sizeof(KeyBlock_t));
    PRINTF("Daten nach Insert KeyBlock:\n");
    PRINTSESSION(index);
    return 0;
}
예제 #14
0
RosterItem QTlenRosterManager::getRosterItem(QString jid)
{
    int index = getIndexOf(jid);
    if (index != -1)
        return rosterItems[index];
    RosterItem item;
    item.presence = Offline;
    item.name = jid;
    item.jid = jid;
    item.desc = "";
    item.subscription = "";
    item.group = "";
    item.avatar = QPixmap();
    return item;
}
예제 #15
0
파일: QKAS.cpp 프로젝트: httyd-hteam/qkas
std::string QKASClass::getRepr(char base) {
    char toUse = islower(base) ? reprLowercase : reprUppercase;
    int amount = getIndexOf(base);
    std::string repr = "";
    /*
     * Basically means 'if char is a-z'.
     * Simpler doing this than astd::string conversion.
     */
    if (amount > -1) {
        for (int i=0; i <= amount; ++i) {
            repr += toUse;
        }
    }
    else {
        repr += base;
    }
    return repr;
}
예제 #16
0
void PartContainer::save(Json::Value& value) const
{
	Container::save(value);

	value["attachments"].resize(0);

	for(Part* part : *this)
	{
		Json::Value attachments;

		attachments.resize(0);

		for(Part* attachedPart : getAttachedParts(part))
		{
			attachments.append(getIndexOf(attachedPart));
		}

		value["attachments"].append(attachments);
	}
}
예제 #17
0
fpoint_t getKeyBlock(uip_ipaddr_t *addr, uint16_t epoch, int update) {
    if (epoch == 0) return 0;

    int index = getIndexOf(addr);
    if (index == -1) return 0;

    if (update) checkEpochIncrease(index, epoch);

    Session_t *s = (Session_t *) RES_SESSION_LIST;
    KeyBlock_t *kb = (KeyBlock_t *) RES_KEY_BLOCK_LIST;
    if (nvm_cmp(&epoch, (fpoint_t) &s[index].epoch, 2) == 0) {
        return (fpoint_t) &kb[2 * index];
    }
    epoch--;
    if (nvm_cmp(&epoch, (fpoint_t) &s[index].epoch, 2) == 0) {
        return (fpoint_t) &kb[(2 * index) + 1];
    }

    return 0;
}
예제 #18
0
파일: tree.hpp 프로젝트: Awilg/go-ai
    /*!
        Warning: this may move other child nodes of node, e.g. if we reach the end of the nodes
                 array (which is used circularly but doesn't allow children to wrap around, for
                 performance reasons).

        Can only be done if node is childless or no other node has had
        children added since the node has had children added
    */
    Node* addChild(Node* node) {
        assert((node->num_children == 0) || ((node->first_child + node->num_children) == allocation_index));
        assert(getUnusedCapacity() > 0);

        unsigned int parent_index = getIndexOf(node);

        if (node->num_children == 0) {
            node->first_child = allocation_index;
        }
        node->num_children++;

        Node* new_child = &nodes[allocation_index];
        new_child->parent = parent_index;
        new_child->num_children = 0;
        new_child->mark = 0;

        allocation_index++;

        return new_child;
    }
예제 #19
0
int checkReadNum(uip_ipaddr_t *addr, uint8_t seq_num[6]) {
    int index = getIndexOf(addr);
    if (index == -1) {
        PRINTF("checkReadNum: Keine Daten zur gesuchten IP gefunden\n");
        // Ohne Session ist Epoch 0. seq_num irrelevant -> immer ok
        return 0;
    }

    // Überlauf bei Subtraktion produziert große Zahl
    uint32_t diff = 0;
    diff += (seq_num[2] << 24);
    diff += (seq_num[3] << 16);
    diff += (seq_num[4] <<  8);
    diff += (seq_num[5] <<  0);
    diff -= seq_num_r[index];
    PRINTF("checkReadNum: diff: %u\n", diff + 10);
    if ((diff + 10) > 110) return -1; // Gültig ist  (seq_num_r - 10) bis (seq_num_r + 100)

    seq_num_r[index] += (diff + 1);
    return 0;
}
예제 #20
0
void BunchOfCards::erase(Card targetCard) {
    int iCard = getIndexOf(targetCard);
    if (iCard >= 0)
        mSomeCards.erase(mSomeCards.begin()+iCard);
}
예제 #21
0
bool BunchOfCards::has(Card targetCard) {
    return !(getIndexOf(targetCard)==-1);
}
예제 #22
0
파일: tree.hpp 프로젝트: Awilg/go-ai
 /*!
     Takes a subtree of the tree rooted at a given node
     and makes it the new root.
 */
 void reRoot(Node* node) {
     root_index = getIndexOf(node);
     node->parent = root_index;
 }
예제 #23
0
파일: tree.hpp 프로젝트: Awilg/go-ai
 unsigned int getNumChildren(const Node* n) const {
     assert(getIndexOf(n) < max_nodes);
     return n->num_children;
 }
예제 #24
0
파일: tree.hpp 프로젝트: Awilg/go-ai
 Node* getFirstChild(Node* n) {
     assert(getIndexOf(n) < max_nodes);
     return &nodes[n->first_child];
 }
예제 #25
0
파일: tree.hpp 프로젝트: Awilg/go-ai
 Node* getParent(Node* n) {
     assert(getIndexOf(n) < max_nodes);
     return &nodes[n->parent];
 }
예제 #26
0
파일: tree.hpp 프로젝트: Awilg/go-ai
 ChildIterator childEnd(Node* n) {
     assert(getIndexOf(n) < max_nodes);
     return ChildIterator(*this, *n, n->num_children);
 }
예제 #27
0
파일: tree.hpp 프로젝트: Awilg/go-ai
 ChildIterator childBegin(Node* n) {
     assert(getIndexOf(n) < max_nodes);
     return ChildIterator(*this, *n, 0);
 }
예제 #28
0
파일: ArrayBag.cpp 프로젝트: robgle/csci133
bool ArrayBag<ItemType>::contains(const ItemType& anEntry) const
{
    return getIndexOf(anEntry) > -1;
}  // end contains
예제 #29
0
파일: qi.c 프로젝트: 0xd3d0/pygdb
int main (int argc, const char * argv[]) 
{
	long array[] = 
	{
		100,    // 0
		140,    // 1
		2000,   // 2
		2001,   // 3
		2202,   // 4
		3000,   // 5
		4000,   // 6
		5510,   // 7
		5560,   // 8
		6787    // 9
	};
	
	int len = sizeof(array) / sizeof(long);
	assert(getIndexOf(array, len, 3003) == 6);
	assert(getIndexOf(array, len, 3000) == 5);
	assert(getIndexOf(array, len, 2999) == 5);
	assert(getIndexOf(array, len, 1) == 0);
	assert(getIndexOf(array, len, 9000) == 10);

	long array1[] =
	{
		100     // 0
	};
	int len1 = sizeof(array1) / sizeof(long);
	assert(getIndexOf(array1, len1, 1) == 0);
	assert(getIndexOf(array1, len1, 100) == 0);
	assert(getIndexOf(array1, len1, 200) == 1);
	
	long array2[] = 
	{
		100,    // 0
		140     // 1
	};
	int len2 = sizeof(array2) / sizeof(long);
	assert(getIndexOf(array2, len2, 1) == 0);
	assert(getIndexOf(array2, len2, 100) == 0);
	assert(getIndexOf(array2, len2, 120) == 1);
	assert(getIndexOf(array2, len2, 140) == 1);
	assert(getIndexOf(array2, len2, 150) == 2);
	
	long array3[] =
	{
		100,
		200,
		300
	};
	int len3 = sizeof(array3) / sizeof(long);
	assert(getIndexOf(array3, len3, 1) == 0);
	assert(getIndexOf(array3, len3, 100) == 0);
	assert(getIndexOf(array3, len3, 101) == 1);
	assert(getIndexOf(array3, len3, 200) == 1);
	assert(getIndexOf(array3, len3, 201) == 2);
	assert(getIndexOf(array3, len3, 300) == 2);
	assert(getIndexOf(array3, len3, 301) == 3);

	long array3x[] =
	{
		100,
		200,
		200
	};
	int len3x = sizeof(array3x) / sizeof(long);
	assert(getIndexOf(array3x, len3x, 1) == 0);
	assert(getIndexOf(array3x, len3x, 100) == 0);
	assert(getIndexOf(array3x, len3x, 101) == 1);
	assert(getIndexOf(array3x, len3x, 200) == 1);
	assert(getIndexOf(array3x, len3x, 201) == 3);
	
    return 0;
}