Ejemplo n.º 1
0
int lotHasSufficientSpaceNetToHostname(int LotNr, int needSpace, char subname[], char server[]) {


	int response;
	int sock;
	int i;

	if ((sock = cconnect(server, BLDPORT)) == 0) {
		perror(server);
		return 0;
	}

	//sender heder
        sendpacked(sock,C_getlotHasSufficientSpace,BLDPROTOCOLVERSION, 0, NULL,subname);

	//sender needSpace og lotnr
        sendall(sock,&LotNr, sizeof(LotNr));	
        sendall(sock,&needSpace, sizeof(needSpace));	

        //leser inn svar
        if ((i=recv(sock, &response, sizeof(response),MSG_WAITALL)) == -1) {
                perror("lotHasSufficientSpaceNetToHostname: Cant recv response");
		return 0;
        }

	close(sock);

	return response;

}
Ejemplo n.º 2
0
int getLotToIndex(char subname[],char HostName[], int dirty) {

	int LotNr;
	int sock;
	int i;

	if ((sock = cconnect(HostName, BLDPORT)) == 0) {
		perror(HostName);
		return 0;
	}

	//sender heder
	printf("sending heder\n");
        sendpacked(sock,C_getLotToIndex,BLDPROTOCOLVERSION, 0, NULL,subname);

	//sender dirty
	printf("sending dirty (%i)\n",dirty);
        sendall(sock,&dirty, sizeof(dirty));	

        //leser inn lotnr
        if ((i=recv(sock, &LotNr, sizeof(LotNr),MSG_WAITALL)) == -1) {
                perror("getLotToIndex: Cant recv lot");
		return 0;
        }

	close(sock);

	return LotNr;

}
Ejemplo n.º 3
0
int rSendFileToHostname(char source[], char dest[], int LotNr, char opentype[],char subname[], char HostName[]) {

	int socketha;

	printf("rSendFileToHostname(source=%s, dest=%s, opentype=%s, subname=%s, HostName=%s)\n",source,dest,opentype,subname,HostName);

	if ((socketha = cconnect(HostName, BLDPORT)) == 0) {
		printf("can't connect to host \"%s\"\n",HostName);
		perror(HostName);
		return 0;
	}

	FILE *FILEHANDLER;

       //opner filen
        if ( (FILEHANDLER = fopen(source,"r")) == NULL ) {
                perror(source);
                return 0;
        }

	
	if (!rSendFileByOpenHandlerBySocket(FILEHANDLER,dest,LotNr,opentype,subname,socketha)) {
		return 0;
	}

	fclose(FILEHANDLER);

	close(socketha);

	printf("~rSendFileToHostname\n");

	return 1;
}
int boithoad_groupsForUser(const char username_in[],char **respons_list[],int *nrofresponses) {

	int socketha;
	char username[64];
     
	//ToDo: strscpy
	strncpy(username,username_in,sizeof(username));

        if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		printf("boithoad_groupsForUser: can't connect\n");
		return 0;
	}

        sendpacked(socketha,bad_groupsForUser,BADPROTOCOLVERSION, 0, NULL,"");

	sendall(socketha,username, sizeof(username));
	
	if (!boithoa_getLdapResponsList(socketha,respons_list,nrofresponses)) {
		printf("boithoad_groupsForUser: can't getLdapResponsList for user \"%s\"\n",username);
		return 0;
	}

	close(socketha);

	#ifdef DEBUG
		int i_debug;
		printf("debug: have %i groups\n",*nrofresponses);

		for (i_debug=0;i_debug<*nrofresponses;i_debug++) {
			printf("debug: group name \"%s\", nr %i\n",(*respons_list)[i_debug],i_debug);
		}
	#endif

	return 1;
}
int boithoad_listUsers(char **respons_list[],int *nrofresponses){

	int socketha;

	//hvis nos skulle skje lendere nede så har vi 0 brukere.
	*nrofresponses = 0;

	if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		#ifdef DEBUG
			printf("cant connect to boithobd at %s:%d\n",__FILE__,__LINE__);
		#endif
		return 0;
	} 

	sendpacked(socketha,bad_listUsers,BADPROTOCOLVERSION, 0, NULL,"");


	if (!boithoa_getLdapResponsList(socketha,respons_list,nrofresponses)) {
		return 0;
	}

	close(socketha);


	return 1;
}
Ejemplo n.º 6
0
int cmc_conect(int *socketha, char statusbuff[],int statusbufflen, int port) {

	//extern int errno;


        if (((*socketha) = cconnect("127.0.0.1", port)) == 0) {
		snprintf(statusbuff,statusbufflen,"Can't connect to crawler manager: %s. Is the crawler manager running?",strerror(errno));
		return 0;
	}
	else {
		int nodelayflag = 1;
		setsockopt(*socketha, IPPROTO_TCP, TCP_NODELAY, &nodelayflag, sizeof(int));
		return 1;
	}
}
Ejemplo n.º 7
0
int rGetFileByOpenHandlerFromHostName(char source[],FILE *FILEHANDLER,int LotNr,char subname[],char HostName[]) {

	int n;

	if ((socketha = cconnect(HostName, BLDPORT)) == 0) {
		printf("can't connect to host \"%s\"\n",HostName);
		perror(HostName);
		return 0;
	}

	n = rGetFileByOpenHandlerFromSocket(source,FILEHANDLER,LotNr,subname,socketha);

	close(socketha);

	return n;
}
Ejemplo n.º 8
0
int bbdn_conect(int *socketha, char tkey[], int PORT) {

	int intrespons;
	int i;

	if (((*socketha) = cconnect("127.0.0.1", PORT)) == 0) {
		bperror("Can't connect to back-end document manager");
		return 0;
	}

	//sender heder
        sendpacked((*socketha),bbc_askToAuthenticate,BLDPROTOCOLVERSION, 0, NULL,"");

        
        if (!sendall((*socketha),tkey, 32)) {
		bperror("sendall");
		goto bbdn_conect_err;
	}


        
        if ((i=recv((*socketha), &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) {
            	bperror("Cant recv respons");
  		goto bbdn_conect_err;
        }
	
	if (intrespons == bbc_authenticate_ok) {
		debug("bbc authenticate ok\n");
		return 1;
	}
	else if (intrespons == bbc_authenticate_feiled) {
		berror("bbc authenticate feiled");
		goto bbdn_conect_err;
	}
	else {
		berror("respons from server was nider bbc_authenticate_feiled or bbc_authenticate_ok!\n");
		goto bbdn_conect_err;
	}

	bbdn_conect_err:
		close(*socketha);
		return 0;
	
}
int boitho_authenticat(const char username_in[],char password_in[]) {
        int socketha;
        int response;

        char username[64];
        char password[64];

        strncpy(username,username_in,sizeof(username));
        strncpy(password,password_in,sizeof(password));

        if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		perror("localhost");
		return 0;
	}

	#ifdef DEBUG
		printf("boitho_authenticat: dic cconnect\n");
	#endif

        sendpacked(socketha,bad_askToAuthenticate,BADPROTOCOLVERSION, 0, NULL,"");

	sendall(socketha,username, sizeof(username));
	sendall(socketha,password, sizeof(password));

	recvall(socketha,&response,sizeof(response));

	close(socketha);


	if (response == ad_userauthenticated_OK) {
		return 1;
	}
	else if (response == ad_userauthenticated_ERROR) {
		return 0;
	}
	else if (response == ad_userauthenticated_NOACCESS) {
		return 2;
	}
	else {
		fprintf(stderr,"dident get ad_userauthenticated_ERROR or ad_userauthenticated_OK\n");
		return 0;
	}

}
int boithoad_sidToGroup(char sid_in[], char username_in[]) {

	int socketha;
	int intresponse;
	char username[64];
	char sid[512];
     	int forreturn = 0;

	//ToDo: strscpy
	strncpy(sid,sid_in,sizeof(sid));

        if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		return 0;
	}

        sendpacked(socketha,bad_sidToGroup,BADPROTOCOLVERSION, 0, NULL,"");

	sendall(socketha, sid, sizeof(sid));
	
	//read respons
        if (!recvall(socketha,&intresponse,sizeof(intresponse))) {
                return 0;
        }

	if (intresponse == 1) {
		if (!recvall(socketha,username,sizeof(username))) {
                	return 0;
        	}
		strcpy(username_in, username);
		forreturn = 1;
	}
	else {
		#ifdef DEBUG
			printf("didn't have a group at %s:%d\n",__FILE__,__LINE__);
		#endif
		strcpy(username_in,"");
		forreturn = 0;
	}

	close(socketha);

	return forreturn;

}
int boithoad_getPassword(const char username_in[], char password_in[]) {

	int socketha;
	int intresponse;
	char username[64];
	char password[64];
     	int forreturn = 0;

	//ToDo: strscpy
	strncpy(username,username_in,sizeof(username));

        if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		return 0;
	}

        sendpacked(socketha,bad_getPassword,BADPROTOCOLVERSION, 0, NULL,"");

	sendall(socketha,username, sizeof(username));
	
	//read respons
        if (!recvall(socketha,&intresponse,sizeof(intresponse))) {
                return 0;
        }

	if (intresponse == 1) {
		if (!recvall(socketha,password,sizeof(password))) {
                	return 0;
        	}
		//printf("got \"%s\"\n",password);
		strcpy(password_in,password);
		forreturn = 1;
	}
	else {
		printf("dident have a passord at %s:%d\n",__FILE__,__LINE__);
		strcpy(password_in,"");
		forreturn = 0;
	}

	close(socketha);

	return forreturn;

}
Ejemplo n.º 12
0
/* connect: connect to IRC */
bool TwitchBot::connect()
{
	char buf[MAX_MSG];

	if (!(bot_connected = !cconnect(&client, TWITCH_SERV, TWITCH_PORT)))
		return false;

	/* send required IRC data: PASS, NICK, USER */
	snprintf(buf, MAX_MSG, "PASS %s", bot_password);
	send_raw(&client, buf);
	snprintf(buf, MAX_MSG, "NICK %s", bot_name);
	send_raw(&client, buf);
	snprintf(buf, MAX_MSG, "USER %s", bot_name);
	send_raw(&client, buf);

	/* enable tags in PRIVMSGs */
	snprintf(buf, MAX_MSG, "CAP REQ :twitch.tv/tags");
	send_raw(&client, buf);

	/* receive join and part information */
	snprintf(buf, MAX_MSG, "CAP REQ :twitch.tv/membership");
	send_raw(&client, buf);

	/* allow access to additional twitch commands */
	snprintf(buf, MAX_MSG, "CAP REQ :twitch.tv/commands");
	send_raw(&client, buf);

	if (strlen(bot_channel) > 32) {
		fprintf(stderr, "error: channel name too long\n");
		disconnect();
		return false;
	}

	/* join channel */
	snprintf(buf, MAX_MSG, "JOIN %s", bot_channel);
	send_raw(&client, buf);

	tick_thread = std::thread(&TwitchBot::tick, this);
	init_timers(bot_channel + 1, bot_token, CID);

	return true;
}
int boithoad_listGroups( char **respons_list[],int *nrofresponses){

	int socketha;

	if ((socketha = cconnect("localhost", BADPORT)) == 0) {
		return 0;
	} 

	sendpacked(socketha,bad_listGroups,BADPROTOCOLVERSION, 0, NULL,"");


	if (!boithoa_getLdapResponsList(socketha,respons_list,nrofresponses)) {
		return 0;
	}

	close(socketha);


	return 1;

}
Ejemplo n.º 14
0
int conectTo(int LotNr) {


	char HostName[32]; 

	#ifdef DEBUG
		printf("sendig lot %i to %s\n",LotNr,HostName);
	#endif
	
        lotlistLoad();
        lotlistGetServer(HostName,LotNr);


        if (strcmp(HostName,lastServer) != 0) {

		#ifdef DEBUG
			printf("connecting to %s\n",HostName);
		#endif

               if (strcmp(lastServer,"noone") != 0) {
			#ifdef DEBUG
				printf("closing socket to %s\n",lastServer);
			#endif
                        close(socketha);
               }

               strcpy(lastServer,HostName);

               socketha = cconnect(HostName, BLDPORT);

        }
        else {
		#ifdef DEBUG
			printf("reusing socket to %s\n",lastServer);
		#endif
        }

	return socketha;
}
Ejemplo n.º 15
0
void vp_contour_draw (vp_contour cnt,
		      bool pos  /* positive only flag */, 
		      float **z /* data to contour */, 
		      float c   /* contour level */)
/*< draw contours >*/
{
    int ix, iy, non, jx, jy;
    float  zxy, ze, zn, x, y;

/*
            north (0)
  (ix,iy+1) --------- (ix+1,iy+1)
            | cell  |
   west (3) | ix,iy | east (1)
            |       |
  (ix,iy)   --------- (ix+1,iy)
            south (2)
*/

    /* find all the intersections */
    non = 0;      /* clear intersection counter */
    for (iy = 0; iy < cnt->n2 - 1; iy++) {
	for (ix = 0; ix < cnt->n1 - 1; ix++) {
	    zxy = z[iy][ix] - c;   /* z(x,y) - c */
	    ze = z[iy][ix+1] - c;  /* (z to the east) - c */
	    zn = z[iy+1][ix] - c;  /* (z to the north) - c */

	    if ((0. < zxy) != (0. < zn)) { /* if west edge intersected */
		cnt->west[iy][ix] = true;
		non++; 
	    } else { 
		cnt->west[iy][ix] = false;
	    }

	    if ((0. < zxy) != (0. < ze)) {  /* if south edge intersected */
		cnt->south[iy][ix] = true;
		non++; 
	    } else { 
		cnt->south[iy][ix] = false;
	    }
	}
    }

    for (ix = 0, iy = cnt->n2 - 1; ix < cnt->n1 - 1; ix++) { /* northern boundary */
	zxy = z[iy][ix]  - c;  /* z(x,y) - c */
	ze = z[iy][ix+1] - c;  /* (z to the east) - c */
	
	if ((0. < zxy) != (0. < ze)) { /* if south edge intersected */
	    cnt->south[iy][ix] = true;
	    non++; 
	} else { 
	    cnt->south[iy][ix] = false;
	}
	cnt->west[iy][ix] = false;
    }
    
    for (iy = 0, ix = cnt->n1 - 1; iy < cnt->n2 - 1; iy++) { /* eastern boundary */
	zxy = z[iy][ix]  - c;  /* z(x,y) - c */
	zn = z[iy+1][ix] - c;  /* (z to the north) - c */
	
	if ((0. < zxy) != (0. < zn)) { /* if west edge intersected */
	    cnt->west[iy][ix] = true;
	    non++; 
	} else { 
	    cnt->west[iy][ix] = false;
	}
	cnt->south[iy][ix] = false;
    }
    
    /* draw contours intersecting a boundary */
    for (ix = 0, iy = cnt->n2 - 1; ix < cnt->n1 - 1 && non > 0; ix++) { /* north */
	if (cnt->south[iy][ix]) {
	    cnt->south[iy][ix] = false;
	    non--;

	    x = ix + delta (c, z[iy][ix], z[iy][ix + 1]);
	    y = iy;

	    draw (cnt, false, x, y);

	    jx = ix;
	    jy = iy - 1;
	    while (cconnect (cnt, pos, z, c, &jx, &jy)) non--;
	}
    }
    
    for (ix = cnt->n1 - 1, iy = 0; iy < cnt->n2 - 1 && non > 0; iy++) { /* east */
	if (cnt->west[iy][ix]) {
	    cnt->west[iy][ix] = false;
	    non--;

	    x = ix;
	    y = iy + delta (c, z[iy][ix], z[iy + 1][ix]);
	    draw (cnt, false, x, y);

	    jx = ix - 1;
	    jy = iy;
	    while (cconnect (cnt, pos, z, c, &jx, &jy)) non--;
	}
    }

    for (ix = 0, iy = 0; ix < cnt->n1 - 1 && non > 0; ix++) {  /* south */
	if (cnt->south[iy][ix]) {
	    cnt->south[iy][ix] = false;
	    non--;

	    x = ix + delta (c, z[iy][ix], z[iy][ix + 1]);
	    y = iy;
	    draw (cnt, false, x, y);

	    jx = ix;
	    jy = iy;
	    while (cconnect (cnt, pos, z, c, &jx, &jy)) non--;
	}
    }

    for (ix = 0, iy = 0; iy < cnt->n2 - 1 && non > 0; iy++) { /* west */
	if (cnt->west[iy][ix]) {
	    cnt->west[iy][ix] = false;
	    non--;

	    x = ix;
	    y = iy + delta (c, z[iy][ix], z[iy + 1][ix]);
	    draw (cnt, false, x, y);

	    jx = ix;
	    jy = iy;
	    while (cconnect (cnt, pos, z, c, &jx, &jy)) non--;
	}
    }

    /* draw interior contours */ 
    for (iy = 0; iy < cnt->n2 - 1 && non > 0; iy++) {
	for (ix = 0; ix < cnt->n1 - 1 && non > 0; ix++) {
	    if (cnt->south[iy][ix]) {  /* check south edge of cell */
		cnt->south[iy][ix] = false;
		non--;

		x = ix + delta (c, z[iy][ix], z[iy][ix + 1]);
		y = iy;
		draw (cnt, false, x, y);

		jx = ix;
		jy = iy;
		cnt->south[iy][ix] = cconnect (cnt, pos, z, c, &jx, &jy);
		while (cconnect (cnt, pos, z, c, &jx, &jy)) non--;
	    }
	}
    }
}