示例#1
0
void SdpServer::startHash(uint16_t& crc, MessageType type) {
    crc = 0xFFFF;
    addHash(crc, 'Z');
    addHash(crc, 'e');
    addHash(crc, 'b');
    addHash(crc, 'u');
    addHash(crc, (uint8_t)type);
}
示例#2
0
bool SdpServer::checkVersion() {
    uint16_t ourVersion = SDP_VERSION;
    if (!sendMessage(MESSAGE_GET_VERSION, &ourVersion, sizeof(ourVersion))) {
        return false;
    }

    MessageType responseType;
    if (!getMessageStart(responseType)) {
        return false;
    }

    if (responseType != MESSAGE_VERSION_RESPONSE) {
        return false;
    }

    uint16_t hash;
    startHash(hash, MESSAGE_VERSION_RESPONSE);

    uint16_t theirVersion = get16();
    addHash(hash, theirVersion);

    if (get16() != hash) {
        return false;
    }

    if (theirVersion != SDP_VERSION) {
        return false;
    }

    return true;
}
示例#3
0
int main(int argc, char * argv[])
{
    int counter1 = 0;
    int hashValue;
    int sizeOfList = 102;
    int * sizePtr = &sizeOfList;
    bucket * root;
    //bucket * conductor;
    char ** wordList;
    char * toBeHashed;
    char userInput[BUFSIZE];

    FILE* inputFile;
    
    if (argc != 2)
    {
        printf("Please input a file name and nothing else.\n");
        exit(0);
    }

    inputFile = fopen(argv[1], "r");
    if (inputFile == NULL)
    {
        printf("The file '%s' does not exist.  Quiting.\n", argv[1]);
        exit(0);
    }

    wordList = readFile(inputFile);
    fclose(inputFile);

    root = initLinkedList(sizePtr);    

    if(root == NULL)
    {
        printf("Error creating linked list, quiting...\n");
        exit(0);
    }

    while (wordList[counter1] != NULL)
    {
        hashValue = findHash(wordList[counter1]);
        addHash(hashValue, wordList[counter1], root);
        counter1++;
    }
    free(wordList);

    printf("List successfully hashed! Ready for queries: ");
    while (1==1)
    {
        fgets(userInput, BUFSIZE, stdin);
        toBeHashed = malloc(strlen(userInput)+1);
        strcpy(toBeHashed, userInput);
        hashValue = findHash(toBeHashed);

        queryDatabase(hashValue, root, toBeHashed);
        printf("Ready for queries: ");
    }

    return 0;
}
示例#4
0
文件: HW9.c 项目: focaaby/1031NCNU-C
int main(int argc, char *argv[]) {
    int i, len;
   // char buf1[1000];
    int inputID;
    char buf[1000];  //多宣告一個buf2暫存字串, buf2儲存name
    FILE *f;
    struct hashtable h;
    struct node *check; 
    initHash(&h, 13);
    if (argc >= 2) { 
        f =fopen(argv[1], "r"); //open with read only mod 
        if ( f == NULL) {
            printf("file open fail, please check filename and privilege\n");
            return 1;
        }   
        while (fscanf(f, "%d %s", inputID, buf) != EOF) {  //改成兩個input, 以空格間隔
            addHash(&h, inputID, buf);
        }
    } else {
        printf("please specify filename as the first argument\n");
    }
    // test hash table
    printf("Please input your studentID:");
    scanf("%d", &inputID);
    check = existHash(&h, &inputID); //檢查時, 用學號檢查
    if (check != NULL ) {
        printf("Your student name is %s\n", check->name);
    } else {
        printf("You student ID is not exist!!\n");
    }
    return 0;
}
示例#5
0
int main() {
    hashTable ht;
    asserthashInit(&ht);
    addHash(&ht, 816, 620);
    int v = findHash(&ht, 816);
    printf("%d\n", v);
}
示例#6
0
int StringSet::addStringL(const char* s, int slen) {
	int hash = stringHash(s, slen);
	int pos = findStringL(s, slen, hash);
	if (pos == -1) {
		pos = m_data.size();
		addHash(hash, pos);
		m_data.insert(m_data.end(), s, s + slen + 1);
	}
	return pos;
}
示例#7
0
int main()
{
	FILE *file;
	file = fopen("txt.txt", "r");
	while(!feof(file))
	{
		char string[12];
		fscanf(file, "%s", string);
		addHash(string);
	}
	printHash();
	delHash();
	std :: cin.get();
	return 0;
}
示例#8
0
bool SdpServer::sendMessage(MessageType type, const void* data, size_t length) {
    uint16_t hash;
    startHash(hash, type);

    uart.putc('Z');
    uart.putc('e');
    uart.putc('b');
    uart.putc('u');
    uart.putc(type);

    if (data != nullptr && length > 0) {
        uart.write((const char*)data, length);
        addHash(hash, (const uint8_t*)data, length);
    }

    uart.write((char*)&hash, sizeof(hash));

    return true;
}
示例#9
0
MobileWindow::MobileWindow(MusicPlayer* player) 
{
	ui.setupUi(this);

	this->player = player;

	//initFolderList();

	// SIGNALS
	// CALL NUMBERS
	connect(ui.call1Button, SIGNAL(clicked()), this, SLOT(add1()));
	connect(ui.call2Button, SIGNAL(clicked()), this, SLOT(add2()));
	connect(ui.call3Button, SIGNAL(clicked()), this, SLOT(add3()));
	connect(ui.call4Button, SIGNAL(clicked()), this, SLOT(add4()));
	connect(ui.call5Button, SIGNAL(clicked()), this, SLOT(add5()));
	connect(ui.call6Button, SIGNAL(clicked()), this, SLOT(add6()));
	connect(ui.call7Button, SIGNAL(clicked()), this, SLOT(add7()));
	connect(ui.call8Button, SIGNAL(clicked()), this, SLOT(add8()));
	connect(ui.call9Button, SIGNAL(clicked()), this, SLOT(add9()));
	connect(ui.call0Button, SIGNAL(clicked()), this, SLOT(add0()));
	connect(ui.callAsteriskButton, SIGNAL(clicked()), this, SLOT(addAsterisk()));
	connect(ui.callHashButton, SIGNAL(clicked()), this, SLOT(addHash()));
	
	// CALL, HANG UP AND DELETE BUTTONS
	connect(ui.removeButton, SIGNAL(clicked()), this, SLOT(removeDigit()));
	connect(ui.callButton, SIGNAL(clicked()), this, SLOT(call()));
	connect(ui.hangUpButton, SIGNAL(clicked()), this, SLOT(hangUp()));

	// CONTACTS 
	connect(ui.contactList, SIGNAL(itemSelectionChanged()), this, SLOT(contactSelected()));
		
	// FILL CONTACTS
	ddbb.readFromFile("ddbb\\contacts.xml");
	QList<Contact*> contacts = ddbb.getContacts();

	foreach (Contact* c,contacts) {
		ui.contactList->addItem(c->name);
	}
示例#10
0
/**********************************************************************
*%FUNCTION: createSession
*%ARGUMENTS:
* ac -- Ethernet interface on access-concentrator side
* cli -- Ethernet interface on client side
* acMac -- Access concentrator's MAC address
* cliMac -- Client's MAC address
* acSess -- Access concentrator's session ID.
*%RETURNS:
* PPPoESession structure; NULL if one could not be allocated
*%DESCRIPTION:
* Initializes relay hash table and session tables.
***********************************************************************/
PPPoESession *
createSession(PPPoEInterface const *ac,
	      PPPoEInterface const *cli,
	      unsigned char const *acMac,
	      unsigned char const *cliMac,
	      UINT16_t acSes)
{
    PPPoESession *sess;
    SessionHash *acHash, *cliHash;

    if (NumSessions >= MaxSessions) {
	printErr("Maximum number of sessions reached -- cannot create new session");
	return NULL;
    }

    /* Grab a free session */
    sess = FreeSessions;
    FreeSessions = sess->next;
    NumSessions++;

    /* Link it to the active list */
    sess->next = ActiveSessions;
    if (sess->next) {
	sess->next->prev = sess;
    }
    ActiveSessions = sess;
    sess->prev = NULL;

    sess->epoch = Epoch;

    /* Get two hash entries */
    acHash = FreeHashes;
    cliHash = acHash->next;
    FreeHashes = cliHash->next;

    acHash->peer = cliHash;
    cliHash->peer = acHash;

    sess->acHash = acHash;
    sess->clientHash = cliHash;

    acHash->interface = ac;
    cliHash->interface = cli;

    memcpy(acHash->peerMac, acMac, ETH_ALEN);
    acHash->sesNum = acSes;
    acHash->ses = sess;

    memcpy(cliHash->peerMac, cliMac, ETH_ALEN);
    cliHash->sesNum = sess->sesNum;
    cliHash->ses = sess;

    addHash(acHash);
    addHash(cliHash);

    /* Log */
    syslog(LOG_INFO,
	   "Opened session: server=%02x:%02x:%02x:%02x:%02x:%02x(%s:%d), client=%02x:%02x:%02x:%02x:%02x:%02x(%s:%d)",
	   acHash->peerMac[0], acHash->peerMac[1],
	   acHash->peerMac[2], acHash->peerMac[3],
	   acHash->peerMac[4], acHash->peerMac[5],
	   acHash->interface->name,
	   ntohs(acHash->sesNum),
	   cliHash->peerMac[0], cliHash->peerMac[1],
	   cliHash->peerMac[2], cliHash->peerMac[3],
	   cliHash->peerMac[4], cliHash->peerMac[5],
	   cliHash->interface->name,
	   ntohs(cliHash->sesNum));

    return sess;
}
示例#11
0
void SdpServer::addHash(uint16_t& crc, uint16_t datum) {
	addHash(crc, (uint8_t)(datum & 0xFF));
	addHash(crc, (uint8_t)(datum >> 8));
}
示例#12
0
int handleDefcpugrp( void *fcb, unsigned int cpugrpid,
		int cpuorcpugrpidarraydim, const unsigned int *cpuorcpugrpidarray,
		const char *cpugrpname ) {


	uint32_t* procs;
	uint32_t i;
	int existing;
	uint32_t tmp;
	/* set first bit to 1 */
	uint32_t mpg= (uint32_t) cpugrpid | 0x80000000;

	fcbT *fha= ((fcbT*)fcb);


	if ( ( 1 << 31 ) > (int)cpugrpid ) {

		fprintf( stderr, "WARNING in '%s': "
			"VTF3 cpu group id '%u' < 2^31 invalid\n", "handleDefcpugrp", cpugrpid );
	}


	/* add the mapping */
	existing= 1;
	while( 1 == existing ) {
	
		existing= 0;
	
		for( i= 0; i < (uint32_t)fha->reservedIdsc; ++i ) {
		
			if( fha->reservedIds[i] == mpg ) {
				existing= 1;
				++mpg;
				break;
			}
		}
	}
	addHash( fha->pghash, (uint32_t) cpugrpid, mpg );
	
	fha->reservedIds= (uint32_t *) realloc( fha->reservedIds, sizeof( uint32_t )
		* ( fha->reservedIdsc + 1 ) );
	fha->reservedIds[fha->reservedIdsc]= mpg;
	++fha->reservedIdsc;
	
	procs= (uint32_t*) malloc( cpuorcpugrpidarraydim * sizeof(uint32_t) );
	assert( procs );

	for ( i= 0; i < (uint32_t)cpuorcpugrpidarraydim; i++ ) {

		if( 0 == (cpuorcpugrpidarray[i]&0x80000000) ) {
		
			procs[i]= cpuorcpugrpidarray[i] +1;
			
		} else {
		
			tmp= searchHash( fha->pghash, cpuorcpugrpidarray[i] );
			if( 0 != tmp ) {
			
				procs[i]= tmp;
				
			} else {
			
				procs[i]= cpuorcpugrpidarray[i];
			}
		}
	}

	fha->processgroups= ( ProcessGroup* ) realloc( fha->processgroups,
		sizeof(ProcessGroup) * (fha->processgroupcount + 1) );
	assert( NULL != fha->processgroups );

	fha->processgroups[fha->processgroupcount].id= mpg;
	fha->processgroups[fha->processgroupcount].size= cpuorcpugrpidarraydim;
	fha->processgroups[fha->processgroupcount].procs= procs;
	fha->processgroups[fha->processgroupcount].name= strdup( cpugrpname );

	fha->processgroupcount++;

	return 0;
}
示例#13
0
int handleDefcommunicator( void *fcb, int communicator,
		int communicatorsize, int tripletarraydim,
		const unsigned int *tripletarray ) {


	uint32_t* procs;
	uint32_t p;
	uint32_t i;
	uint32_t j;
	char tmp[32];
	/* set first two bits to 1 */
	uint32_t mcommunicator= ((uint32_t) communicator) | 0xc0000000;
	int existing;
	
	fcbT *fha= ((fcbT*)fcb);


	if ( 0 > communicator ) {

		fprintf( stderr, "WARNING in '%s': "
			"VTF3 communicator id '%i' < 0 invalid\n", "handleDefcommunicator", communicator );
	}
	
	/* add the mapping */
	existing= 1;
	while( 1 == existing ) {
	
		existing= 0;
	
		for( i= 0; i < (uint32_t)fha->reservedIdsc; ++i ) {
		
			if( fha->reservedIds[i] == mcommunicator ) {
				existing= 1;
				++mcommunicator;
				break;
			}
		}
	}
	addHash( fha->pghash, (uint32_t) communicator, mcommunicator );
	
	fha->reservedIds= (uint32_t *) realloc( fha->reservedIds, sizeof( uint32_t )
		* ( fha->reservedIdsc + 1 ) );
	fha->reservedIds[fha->reservedIdsc]= mcommunicator;
	++fha->reservedIdsc;
	
	
	procs= (uint32_t*) malloc( communicatorsize * sizeof(uint32_t) );
	assert( procs );

	p= 0;
	for ( i= 0; i < (uint32_t)tripletarraydim; i++ ) {

		for ( j= tripletarray[3*i+0]; j <= tripletarray[3*i+1]; j += tripletarray[3*i+2] ) {
		
			assert( p < (uint32_t)communicatorsize );
			procs[p]= j + 1;
			p++;
		}
	}

	assert( p == (uint32_t)communicatorsize );

	fha->processgroups= ( ProcessGroup* ) realloc( fha->processgroups,
		sizeof(ProcessGroup) * (fha->processgroupcount + 1) );
	assert( NULL != fha->processgroups );

	sprintf( tmp, "communicator %u", mcommunicator& 0x3fffffff );
	fha->processgroups[fha->processgroupcount].id= mcommunicator;
	fha->processgroups[fha->processgroupcount].size= communicatorsize;
	fha->processgroups[fha->processgroupcount].procs= procs;
	fha->processgroups[fha->processgroupcount].name= strdup( tmp );

	fha->processgroupcount++;

	return 0;
}