Beispiel #1
0
void Chunk::render(int maximumDrawingBlock)
{
	if(m_isDirty)
	{
		calculateLighting();
		sendList(maximumDrawingBlock);
	}

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, g_worldSprites->m_textureID);

	glPushMatrix();
	glBindBuffer( GL_ARRAY_BUFFER, m_vboID );

	glEnableClientState( GL_VERTEX_ARRAY );
	glEnableClientState( GL_COLOR_ARRAY );
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );

	glVertexPointer(	3, GL_FLOAT, sizeof( BlockVertex ), (const GLvoid*) offsetof( BlockVertex, m_position ) );	
	glColorPointer(		4, GL_FLOAT, sizeof( BlockVertex ), (const GLvoid*) offsetof( BlockVertex, m_color ) );	
	glTexCoordPointer(	2, GL_FLOAT, sizeof( BlockVertex ), (const GLvoid*) offsetof( BlockVertex, m_texCoords ) );	

	glDrawArrays( GL_QUADS, 0, m_vertexesSize );

	glDisableClientState( GL_VERTEX_ARRAY );
	glDisableClientState( GL_COLOR_ARRAY );
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );

	glBindBuffer( GL_ARRAY_BUFFER, 0 );
	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}
Beispiel #2
0
void handleInput(char *comm, size_t size) {
    if (strncmp(comm, "ECHO", 4) == 0) {
        sendEcho(comm, size - 5);
    } else if (strncmp(comm, "LIST", 4) == 0) {
        sendList();
    } else if (strncmp(comm, "2ALL", 4) == 0) {
        sendToAll(comm, size - 5);
    } else if (strncmp(comm, "2ONE", 4) == 0) {
        strtok(comm, " ");
        char *str = strtok(comm + 5, " ");
        if (str == NULL) {
            fprintf(stderr, "Wrong number of arguments\n");
            return;
        }
        int id = atoi(str);
        str = strtok(NULL, " ");
        size_t size = 0;
        if (str != NULL)
            size = strlen(str);
        sendToOne(str, id, size);
    } else if (strncmp(comm, "FRIENDS", 7) == 0) {
        sendFriends(comm, size - 8);
    } else if (strncmp(comm, "ADD", 3) == 0) {
        sendAddFriends(comm, size - 4);
    } else if (strncmp(comm, "DEL", 3) == 0) {
        sendDelFriends(comm, size - 4);
    } else if (strncmp(comm, "2FRIENDS", 8) == 0) {
        sendToFriends(comm, size - 9);
    } else if (strncmp(comm, "STOP", 4) == 0) {
        exit(0);
    } else {
        printf("Wrong command -> %s\n", comm);
    }
}
Beispiel #3
0
void* handle_display(void* passedClient) {
	struct ClientIdPair clientIdPaire = *(struct ClientIdPair*) passedClient;
	//sendId(clientIdPaire.client, clientIdPaire.id);
	char message[MESSAGE_SIZE];
	unsigned char action;
	while (true) {
		IOresult result = read(clientIdPaire.client,message,MESSAGE_SIZE);
		if(result == READ_FAILED)
			break;
		if(result == READ_FAILED || result == CONNECTION_FINISHED)
			break;
		printf("message received : %s\n",message);

		action = message[0];
		printf("translated to %d\n",action);
		if (action == ACTION_LIST) {
			printf("send list\n");
			sendList(clientIdPaire.client);
		} else {
			printf("send state");
			sendState(clientIdPaire.client, action);
		}
	}
	close(clientIdPaire.client);
	return 0;
}
/**
 * Отправка команды FTP-серверу.
 * 
 * @param command FTP-команда.
 * 
 * @return Флаг успешности выполнения (0 - не успешно, другое - успешно).
 */
int ProtocolInterpreter::sendCommand(string command) {
    int success;
    
    if (command == "USER") {
        success = sendUser();
    } else if (command == "PASS") {
        success = sendPass();
    } else if (command == "TYPE") {
        success = sendType();
    } else if (command == "MODE") {
        success = sendMode();
    } else if (command == "STRU") {
        success = sendStru();
    } else if (command == "PORT") {
        success = sendPort();
    } else if (command == "PASV") {
        success = sendPasv();
    } else if (command == "NLST") {
        success = sendNlst();
    } else if (command == "LIST") {
        success = sendList();
    } else if (command == "RETR") {
        success = sendRetr();
    } else if (command == "STOR") {
        success = sendStor();
    } else if (command == "RNTO") {
        success = sendRnto();
    } else if (command == "RNFR") {
        success = sendRnfr();
    } else if (command == "DELE") {
        success = sendDele();
    } else if (command == "MKD") {
        success = sendMkd();
    } else if (command == "RMD") {
        success = sendRmd();
    } else if (command == "CWD") {
        success = sendCwd();
    } else if (command == "CDUP") {
        success = sendCdup();
    } else if (command == "PWD") {
        success = sendPwd();
    } else if (command == "ABOR") {
        success = sendAbor();
    } else if (command == "REIN") {
        success = sendRein();
    } else if (command == "QUIT") {
        success = sendQuit();
    } else if (command == "SYST") {
        success = sendSyst();
    } else if (command == "STAT") {
        success = sendStat();
    } else if (command == "NOOP") {
        success = sendNoop();
    } else {
        service->printMessage(1, "Unknown command!");
    }
    
    return success;
}
Beispiel #5
0
void Network::handle(std::istream &i) {
	uint8_t oc = Utils::getVal<uint8_t>(i);
	switch (oc) {
		case OC_GET:     sendList(); break;
		case OC_MONITOR: monitor(i); break;
		default:         break;
	}
}
Beispiel #6
0
void Network::onUpdateTimer() {
	sendList();
	if (m_updateTimer) {
		Utils::timedCallback(
			this, &Network::onUpdateTimer, m_updateTimer
		);
	}
}
Beispiel #7
0
int main(int argc,char *argv[]){

	char* PORTNO = "5540";
	char* SERVERIP = "127.0.0.1";

    //Populate the OS name
    if(uname(&sysname)){
        perror("Error obtaining os name");
        exit(-1);
    }
    
	hostname[511]='\0';
	gethostname(hostname,511);

	char *buf;
	int status,sockfd,numbytes;
	struct addrinfo hints,*res,*me;
	socklen_t addr_size;
	char s[INET6_ADDRSTRLEN];
	
	//Server details
	memset(&hints,0,sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	
	getaddrinfo(SERVERIP,PORTNO,&hints,&res);
	
	//Create a socket
	if((sockfd = socket(res->ai_family,res->ai_socktype,res->ai_protocol)) == -1){
		perror("Server:socket creating error");
	}
	
	if(connect(sockfd,res->ai_addr,res->ai_addrlen) == -1){
		close(sockfd);
		perror("Client : Connect");
		exit(1);
	}
	
	inet_ntop(res->ai_family,get_in_addr((struct sockaddr *)res->ai_addr),s,sizeof(s));
	gethostname(hostname,1023);
	printf("Hostname : %s\n",hostname);
	printf("Client connecting to : %s\n",s);

    initClient(sockfd);
    
    sendLookup(sockfd,789);
    
    sendList(sockfd);
    
	close(sockfd);
    
	return 0;
}
Beispiel #8
0
    JNIEXPORT jint JNICALL Java_org_scilab_modules_javasci_Call_1ScilabJNI_putList(JNIEnv *jenv, jclass cl, jstring jvarName, jobject list, jchar type)
    {
        char * varName = (char*)(*jenv)->GetStringUTFChars(jenv, jvarName, 0);
        SciErr sciErr = sendList(jenv, list, 0, 0, varName, (char)type);
        (*jenv)->ReleaseStringUTFChars(jenv, jvarName, (const char *)varName);

        if (sciErr.iErr)
        {
            return -1;
        }

        return 0;
    }
Beispiel #9
0
Chunk::Chunk(Vec2i chunkCoords, Chunk* northChunk,Chunk* southChunk,Chunk* eastChunk,Chunk* westChunk) 
	:	m_chunkCoords(chunkCoords),
		m_northChunk(northChunk),
		m_southChunk(southChunk),
		m_eastChunk(eastChunk),
		m_westChunk(westChunk)
{
	m_enableCulling = true;
	m_vertexes.reserve(20000);
	m_lightDirtyIndex.reserve(5000);
	m_vboID = 0;
	m_block = new Block[BLOCKS_IN_A_CHUNK];
	m_pumpkinCount = 0;

	if(m_northChunk != nullptr)
	{
		m_northChunk->m_southChunk = this;
		m_northChunk->m_isDirty = true;
		m_northChunk->checkBoundary();
	}

	if(m_southChunk != nullptr)
	{
		m_southChunk->m_northChunk = this;
		m_southChunk->m_isDirty = true;
		m_southChunk->checkBoundary();
	}

	if(m_westChunk != nullptr)
	{
		m_westChunk->m_eastChunk = this;
		m_westChunk->m_isDirty = true;
		m_westChunk->checkBoundary();
	}

	if(m_eastChunk != nullptr)
	{
		m_eastChunk->m_westChunk = this;
		m_eastChunk->m_isDirty = true;
		m_eastChunk->checkBoundary();
	}

	if(!loadFromDisk())
		generateBlocks();
	
	initialLightLevel();
	sendList(BLOCKS_IN_A_CHUNK);

	m_timeSinceLastUpdate = 0.1f;
}
void
ProtocolDataTransfer::run()
{
        switch (m_SocketMode)
        {
        case Slave:
                if (accept() == -1)
                {
                        return;
                }
                break;
        case Active:
                if (connectTo() == -1)
                {
                        return;
                }
                break;
        default:
                return;
        }

        switch (m_Protocol)
        {
        case DoSendFile:
                sendFile();
                break;
        case DoRecvFile:
                recvFile();
                break;
        case DoSendDir:
                sendDir();
                break;
        case DoRecvDir:
                recvDir();
                break;
        case DoSendList:
                sendList();
                break;
        case DoRecvList:
                recvList();
                break;
        }
}
Beispiel #11
0
void SocketConnection::processPacket(std::string& buf) {
    const char* graphName = buf.c_str() + 1;

    switch (buf[0]) {
    case 'c':
        // Start sending data for the graph specified by graphName
        if (std::find(datasets.begin(), datasets.end(),
                      graphName) == datasets.end()) {
            datasets.push_back(graphName);
        }
        break;
    case 'd':
        // Stop sending data for the graph specified by graphName
        std::remove_if(datasets.begin(), datasets.end(),
                       [&] (const auto& set) { return set == graphName; });
        break;
    case 'l':
        sendList();
    }
}
Beispiel #12
0
////////////////////////////////////////////////////////////////////////////////
// Funciton to connect and register and all that nonsense
void connectPlease( Folder *dir, int sock ) {
  int nbytes;                // Number of bytes
  char buffer[ MAXBUFSIZE ]; // Buffer

  nbytes = write( sock, "CONNECT", MAXBUFSIZE );
  ERROR( nbytes < 0 );
  
  bzero( buffer, MAXBUFSIZE );
  nbytes = read( sock, buffer, MAXBUFSIZE );
  ERROR ( nbytes < 0 );
  switch ( parseCmd( buffer ) ) {
  case CONNECT:
	{
	  printf( "$ Connection Established\n" );
	  switch ( registerClient( dir, sock ) ) {
	  case FAILURE: 
		{
		  printf( "$ There is already a user with the name '%s' on the server.\n", 
				  dir->name );
		  close( sock );
		  exit( EXIT_SUCCESS );
		}
	  case SUCCESS:
		{
		  printf( "$ You have been connected as %s\n", dir->name );
		  sendList( dir, sock );
		  break;
		}
	  }	  
	  break;
	}
  default: 
	{
	  printf( "$ Error in registering\n" );
	}
  }
} // connectionPlease( )
Beispiel #13
0
    SciErr sendList(JNIEnv * jenv, jobject list, int * parentList, int pos, char * varName, char listType)
    {
        int listLen = (*jenv)->GetArrayLength(jenv, list);
        jboolean isCopy = JNI_FALSE;
        jintArray jtypes = (jintArray)(*jenv)->GetObjectArrayElement(jenv, list, 0);
        jint * types = (*jenv)->GetIntArrayElements(jenv, jtypes, &isCopy);
        int i = 0;
        SciErr sciErr;
        int * currentList = 0;
        if (parentList)
        {
            switch (listType)
            {
                case 'l' :
                    sciErr = createListInNamedList(NULL, varName, parentList, pos, listLen - 1, &currentList);
                    break;
                case 't' :
                    sciErr = createTListInNamedList(NULL, varName, parentList, pos, listLen - 1, &currentList);
                    break;
                case 'm' :
                    sciErr = createMListInNamedList(NULL, varName, parentList, pos, listLen - 1, &currentList);
                    break;
            }
        }
        else
        {
            //cleanStackListAddress();
            switch (listType)
            {
                case 'l' :
                    sciErr = createNamedList(NULL, varName, listLen - 1, &currentList);
                    break;
                case 't' :
                    sciErr = createNamedTList(NULL, varName, listLen - 1, &currentList);
                    break;
                case 'm' :
                    sciErr = createNamedMList(NULL, varName, listLen - 1, &currentList);
                    break;
            }
        }

        if (sciErr.iErr)
        {
            (*jenv)->ReleaseIntArrayElements(jenv, jtypes, types, JNI_ABORT);
            (*jenv)->DeleteLocalRef(jenv, jtypes);
            return sciErr;
        }

        //pushListAddress(currentList);

        for (; i < listLen - 1; i++)
        {
            switch (types[i])
            {
                case sci_matrix :
                {
                    int nbCol = 0;
                    int j = 0, k = 0;
                    double * real = 0;
                    double * imag = 0;
                    int nbRow = 0;

                    jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    int isReal = (*jenv)->GetArrayLength(jenv, infos) == 1;
                    jobjectArray data = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0);

                    if (!data)
                    {
                        // empty matrix
                        sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                        (*jenv)->DeleteLocalRef(jenv, infos);
                        break;
                    }

                    nbRow = (*jenv)->GetArrayLength(jenv, data);

                    if (isReal)
                    {
                        // Get the matrix rowsw
                        for (; j < nbRow; j++)
                        {
                            jboolean isCopy1 = JNI_FALSE;
                            jdouble* element = NULL;
                            jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, data, j);
                            if (nbCol == 0)
                            {
                                nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                real = (double*)MALLOC(sizeof(double) * nbRow * nbCol);
                            }

                            element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                            // Get the matrix element
                            for (k = 0; k < nbCol; k++)
                            {
                                real[k * nbRow + j] = element[k];
                            }
                            (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                            (*jenv)->DeleteLocalRef(jenv, oneDim);
                        }
                        (*jenv)->DeleteLocalRef(jenv, data);

                        sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, real);
                        FREE(real);
                    }
                    else
                    {
                        jobject imagData = (jobject)(*jenv)->GetObjectArrayElement(jenv, infos, 1);
                        // Get the matrix rows
                        for (; j < nbRow; j++)
                        {
                            jboolean isCopy1 = JNI_FALSE;
                            jdouble* elementR = NULL;
                            jdouble* elementI = NULL;
                            jdoubleArray oneDimR = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, data, j);
                            jdoubleArray oneDimI = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, imagData, j);
                            if (nbCol == 0)
                            {
                                nbCol = (*jenv)->GetArrayLength(jenv, oneDimR);
                                real = (double*)MALLOC(sizeof(double) * nbRow * nbCol);
                                imag = (double*)MALLOC(sizeof(double) * nbRow * nbCol);
                            }

                            elementR = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimR, &isCopy1);
                            isCopy1 = JNI_FALSE;
                            elementI = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimI, &isCopy1);

                            // Get the matrix element
                            for (k = 0; k < nbCol; k++)
                            {
                                real[k * nbRow + j] = elementR[k];
                                imag[k * nbRow + j] = elementI[k];
                            }
                            (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimR, elementR, JNI_ABORT);
                            (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimI, elementI, JNI_ABORT);
                            (*jenv)->DeleteLocalRef(jenv, oneDimR);
                            (*jenv)->DeleteLocalRef(jenv, oneDimI);
                        }
                        (*jenv)->DeleteLocalRef(jenv, data);
                        (*jenv)->DeleteLocalRef(jenv, imagData);

                        sciErr = createComplexMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, real, imag);
                        FREE(real);
                        FREE(imag);
                    }
                    (*jenv)->DeleteLocalRef(jenv, infos);
                    break;
                }
                case sci_poly :
                {
                    jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    jobject data = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                    int nbRow = (*jenv)->GetArrayLength(jenv, data);
                    int isReal = 0;
                    jstring js;
                    char * polyVarName = NULL;
                    int nbCol = 0;
                    int j = 0, k = 0;
                    double ** real = NULL;
                    double ** imag = NULL;
                    int * nbCoef = NULL;

                    if (!data || nbRow == 0)
                    {
                        sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                        if (!data)
                        {
                            (*jenv)->DeleteLocalRef(jenv, data);
                        }
                        (*jenv)->DeleteLocalRef(jenv, infos);
                        break;
                    }

                    isReal = (*jenv)->GetArrayLength(jenv, infos) == 2;
                    js = (jstring)(*jenv)->GetObjectArrayElement(jenv, infos, 0);
                    polyVarName = (char*)(*jenv)->GetStringUTFChars(jenv, js, 0);

                    if (isReal)
                    {
                        // Get the matrix rows
                        for (; j < nbRow; j++)
                        {
                            jobjectArray dblDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, data, j);
                            if (nbCol == 0)
                            {
                                nbCol = (*jenv)->GetArrayLength(jenv, dblDim);
                                real = (double**)MALLOC(sizeof(double*) * nbRow * nbCol);
                                nbCoef = (int*)MALLOC(sizeof(int) * nbRow * nbCol);
                            }

                            // Get the matrix element
                            for (k = 0; k < nbCol; k++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jdouble* element = NULL;
                                jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDim, k);
                                int len = (*jenv)->GetArrayLength(jenv, oneDim);
                                nbCoef[k * nbRow + j] = len;
                                real[k * nbRow + j] = (double*)MALLOC(sizeof(double) * len);
                                element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);
                                memcpy(real[k * nbRow + j], element, sizeof(double) * len);
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, 0);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, dblDim);
                        }
                        (*jenv)->DeleteLocalRef(jenv, data);

                        sciErr = createMatrixOfPolyInNamedList(NULL, varName, currentList, i + 1, polyVarName, nbRow, nbCol, nbCoef, (const double * const*)real);
                        for (j = 0; j < nbRow * nbCol; j++)
                        {
                            FREE(real[j]);
                        }
                        FREE(real);
                        FREE(nbCoef);
                    }
                    else
                    {
                        jobject imagData = (*jenv)->GetObjectArrayElement(jenv, infos, 2);
                        // Get the matrix rows
                        for (; j < nbRow; j++)
                        {
                            jobjectArray dblDimR = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, data, j);
                            jobjectArray dblDimI = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, imagData, j);
                            if (nbCol == 0)
                            {
                                nbCol = (*jenv)->GetArrayLength(jenv, dblDimR);
                                real = (double**)MALLOC(sizeof(double*) * nbRow * nbCol);
                                imag = (double**)MALLOC(sizeof(double*) * nbRow * nbCol);
                                nbCoef = (int*)MALLOC(sizeof(int) * nbRow * nbCol);
                            }

                            // Get the matrix element
                            for (k = 0; k < nbCol; k++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jdouble* element = NULL;
                                jdoubleArray oneDimR = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDimR, k);
                                jdoubleArray oneDimI = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, dblDimI, k);
                                int len = (*jenv)->GetArrayLength(jenv, oneDimR);
                                nbCoef[k * nbRow + j] = len;
                                real[k * nbRow + j] = (double*)MALLOC(sizeof(double) * len);
                                imag[k * nbRow + j] = (double*)MALLOC(sizeof(double) * len);
                                element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimR, &isCopy1);
                                memcpy(real[k * nbRow + j], element, sizeof(double) * len);
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimR, element, 0);
                                (*jenv)->DeleteLocalRef(jenv, oneDimR);
                                isCopy1 = JNI_FALSE;
                                element = (jdouble*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDimI, &isCopy1);
                                memcpy(imag[k * nbRow + j], element, sizeof(double) * len);
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDimI, element, 0);
                                (*jenv)->DeleteLocalRef(jenv, oneDimI);
                            }
                            (*jenv)->DeleteLocalRef(jenv, dblDimR);
                            (*jenv)->DeleteLocalRef(jenv, dblDimI);
                        }
                        (*jenv)->DeleteLocalRef(jenv, data);
                        (*jenv)->DeleteLocalRef(jenv, imagData);

                        sciErr = createComplexMatrixOfPolyInNamedList(NULL, varName, currentList, i + 1, polyVarName, nbRow, nbCol, nbCoef, (const double * const*)real, (const double * const*)imag);
                        for (j = 0; j < nbRow * nbCol; j++)
                        {
                            FREE(real[j]);
                            FREE(imag[j]);
                        }
                        FREE(real);
                        FREE(imag);
                        FREE(nbCoef);
                    }

                    (*jenv)->ReleaseStringUTFChars(jenv, js, polyVarName);
                    (*jenv)->DeleteLocalRef(jenv, js);
                    (*jenv)->DeleteLocalRef(jenv, infos);
                    break;
                }
                case sci_boolean :
                {
                    jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    int nbRow = (*jenv)->GetArrayLength(jenv, data);
                    int nbCol = 0;
                    int j = 0, k;
                    int * b = 0;

                    if (!data || nbRow == 0)
                    {
                        sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                        if (!data)
                        {
                            (*jenv)->DeleteLocalRef(jenv, data);
                        }
                        break;
                    }

                    // Get the matrix rows
                    for (; j < nbRow; j++)
                    {
                        jboolean isCopy1 = JNI_FALSE;
                        jboolean* element = NULL;
                        jdoubleArray oneDim = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, data, j);
                        if (nbCol == 0)
                        {
                            nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                            b = (int*)MALLOC(sizeof(int) * nbRow * nbCol);
                        }

                        element = (jboolean*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                        // Get the matrix element
                        for (k = 0; k < nbCol; k++)
                        {
                            b[k * nbRow + j] = element[k];
                        }
                        (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                        (*jenv)->DeleteLocalRef(jenv, oneDim);
                    }
                    (*jenv)->DeleteLocalRef(jenv, data);

                    sciErr = createMatrixOfBooleanInNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, (const int *)b);
                    FREE(b);
                    break;
                }
                case sci_sparse :
                {
                    jboolean isCopy1 = JNI_FALSE;
                    int* dims = NULL;
                    int* nbItemRow = NULL;
                    int* colPos = NULL;
                    double* data = NULL;
                    double * imagData = NULL;
                    jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    int isReal = (*jenv)->GetArrayLength(jenv, infos) == 4;
                    jintArray jdims = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0);
                    jintArray jnbItemRow = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 1);
                    jintArray jcolPos = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 2);
                    jint nbNonNull = (*jenv)->GetArrayLength(jenv, jcolPos);
                    jdoubleArray jdata = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, infos, 3);
                    jdoubleArray jimagData;

                    if (!isReal)
                    {
                        jimagData = (jdoubleArray)(*jenv)->GetObjectArrayElement(jenv, infos, 4);
                    }

                    dims = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jdims, &isCopy1);
                    isCopy1 = JNI_FALSE;
                    nbItemRow = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jnbItemRow, &isCopy1);
                    isCopy1 = JNI_FALSE;
                    colPos = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jcolPos, &isCopy1);
                    isCopy1 = JNI_FALSE;
                    data = (double*)(*jenv)->GetPrimitiveArrayCritical(jenv, jdata, &isCopy1);
                    isCopy1 = JNI_FALSE;

                    if (!isReal)
                    {
                        imagData = (double*)(*jenv)->GetPrimitiveArrayCritical(jenv, jimagData, &isCopy1);
                    }

                    if (isReal)
                    {
                        sciErr = createSparseMatrixInNamedList(NULL, varName, currentList, i + 1, dims[0], dims[1], nbNonNull, nbItemRow, colPos, data);
                        (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdata, data, JNI_ABORT);
                    }
                    else
                    {
                        sciErr = createComplexSparseMatrixInNamedList(NULL, varName, currentList, i + 1, dims[0], dims[1], nbNonNull, nbItemRow, colPos, data, imagData);
                        (*jenv)->ReleasePrimitiveArrayCritical(jenv, jimagData, imagData, JNI_ABORT);
                        (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdata, data, JNI_ABORT);
                    }

                    (*jenv)->ReleasePrimitiveArrayCritical(jenv, jcolPos, colPos, JNI_ABORT);
                    (*jenv)->ReleasePrimitiveArrayCritical(jenv, jnbItemRow, nbItemRow, JNI_ABORT);
                    (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdims, dims, JNI_ABORT);

                    if (!isReal)
                    {
                        (*jenv)->DeleteLocalRef(jenv, jimagData);
                    }
                    (*jenv)->DeleteLocalRef(jenv, jdata);
                    (*jenv)->DeleteLocalRef(jenv, jcolPos);
                    (*jenv)->DeleteLocalRef(jenv, jnbItemRow);
                    (*jenv)->DeleteLocalRef(jenv, jdims);
                    (*jenv)->DeleteLocalRef(jenv, infos);

                    break;
                }
                case sci_boolean_sparse :
                {
                    jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    jintArray jdims = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0);
                    jintArray jnbItemRow = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 1);
                    jintArray jcolPos = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 2);
                    jint nbNonNull = (*jenv)->GetArrayLength(jenv, jcolPos);
                    int* nbItemRow = NULL;
                    int* dims = NULL;
                    int* colPos = NULL;

                    jboolean isCopy1 = JNI_FALSE;

                    dims = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, jdims, &isCopy1);
                    isCopy1 = JNI_FALSE;
                    nbItemRow = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jnbItemRow, &isCopy1);
                    isCopy1 = JNI_FALSE;
                    colPos = (int*)(*jenv)->GetPrimitiveArrayCritical(jenv, jcolPos, &isCopy1);

                    sciErr = createBooleanSparseMatrixInNamedList(NULL, varName, currentList, i + 1, dims[0], dims[1], nbNonNull, nbItemRow, colPos);

                    (*jenv)->ReleasePrimitiveArrayCritical(jenv, jcolPos, colPos, JNI_ABORT);
                    (*jenv)->ReleasePrimitiveArrayCritical(jenv, jnbItemRow, nbItemRow, JNI_ABORT);
                    (*jenv)->ReleasePrimitiveArrayCritical(jenv, jdims, dims, JNI_ABORT);

                    (*jenv)->DeleteLocalRef(jenv, jcolPos);
                    (*jenv)->DeleteLocalRef(jenv, jnbItemRow);
                    (*jenv)->DeleteLocalRef(jenv, jdims);
                    (*jenv)->DeleteLocalRef(jenv, infos);

                    break;
                }
                case sci_ints :
                {
                    jobjectArray infos = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    jintArray jtype = (jintArray)(*jenv)->GetObjectArrayElement(jenv, infos, 0);
                    jint * typep = (*jenv)->GetIntArrayElements(jenv, jtype, 0);
                    int type = *typep;

                    (*jenv)->ReleaseIntArrayElements(jenv, jtype, typep, JNI_ABORT);
                    (*jenv)->DeleteLocalRef(jenv, jtype);

                    switch (type)
                    {
                        case sci_int8 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            char * data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jbyte* element = NULL;
                                jbyteArray oneDim = (jbyteArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (char*)MALLOC(sizeof(char) * nbRow * nbCol);
                                }
                                isCopy1 = JNI_FALSE;
                                element = (jbyte*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfInteger8InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);
                            break;
                        }
                        case sci_uint8 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            unsigned char * data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jbyte* element = NULL;
                                jboolean isCopy1 = JNI_FALSE;
                                jbyteArray oneDim = (jbyteArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (unsigned char*)MALLOC(sizeof(unsigned char) * nbRow * nbCol);
                                }

                                element = (jbyte*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfUnsignedInteger8InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);

                            break;
                        }
                        case sci_int16 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            short * data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jshort* element = NULL;
                                jshortArray oneDim = (jshortArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (short*)MALLOC(sizeof(short) * nbRow * nbCol);
                                }

                                element = (jshort*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfInteger16InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);

                            break;
                        }
                        case sci_uint16 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            unsigned short * data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jshort* element = NULL;
                                jshortArray oneDim = (jshortArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (unsigned short*)MALLOC(sizeof(unsigned short) * nbRow * nbCol);
                                }
                                isCopy1 = JNI_FALSE;
                                element = (jshort*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfUnsignedInteger16InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);

                            break;
                        }
                        case sci_int32 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            int * data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jint* element = NULL;
                                jintArray oneDim = (jintArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (int*)MALLOC(sizeof(int) * nbRow * nbCol);
                                }
                                isCopy1 = JNI_FALSE;
                                element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfInteger32InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);

                            break;
                        }
                        case sci_uint32 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            unsigned int * data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jint* element = NULL;
                                jintArray oneDim = (jintArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (unsigned int*)MALLOC(sizeof(unsigned int) * nbRow * nbCol);
                                }
                                isCopy1 = JNI_FALSE;
                                element = (jint*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfUnsignedInteger32InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);

                            break;
                        }
#ifdef __SCILAB_INT64__
                        case sci_int64 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            long long* data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jlong* element = NULL;
                                jlongArray oneDim = (jlongArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (long long*)MALLOC(sizeof(long long) * nbRow * nbCol);
                                }
                                isCopy1 = JNI_FALSE;
                                element = (jlong*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfInteger64InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);

                            break;
                        }
                        case sci_uint64 :
                        {
                            jobject jdata = (*jenv)->GetObjectArrayElement(jenv, infos, 1);
                            int nbRow = (*jenv)->GetArrayLength(jenv, jdata);
                            int nbCol = 0;
                            int j = 0, k;
                            unsigned long long* data = 0;

                            if (!jdata || nbRow == 0)
                            {
                                sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                                if (!jdata)
                                {
                                    (*jenv)->DeleteLocalRef(jenv, jdata);
                                }
                                break;
                            }

                            // Get the matrix rows
                            for (; j < nbRow; j++)
                            {
                                jboolean isCopy1 = JNI_FALSE;
                                jlong* element = NULL;
                                jlongArray oneDim = (jlongArray)(*jenv)->GetObjectArrayElement(jenv, jdata, j);
                                if (nbCol == 0)
                                {
                                    nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                                    data = (unsigned long long*)MALLOC(sizeof(unsigned long long) * nbRow * nbCol);
                                }
                                isCopy1 = JNI_FALSE;
                                element = (jlong*)(*jenv)->GetPrimitiveArrayCritical(jenv, oneDim, &isCopy1);

                                // Get the matrix element
                                for (k = 0; k < nbCol; k++)
                                {
                                    data[k * nbRow + j] = element[k];
                                }
                                (*jenv)->ReleasePrimitiveArrayCritical(jenv, oneDim, element, JNI_ABORT);
                                (*jenv)->DeleteLocalRef(jenv, oneDim);
                            }
                            (*jenv)->DeleteLocalRef(jenv, jdata);

                            sciErr = createMatrixOfUnsignedInteger64InNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, data);
                            FREE(data);
                            break;
                        }
#endif
                    }
                    (*jenv)->DeleteLocalRef(jenv, infos);
                    break;
                }
                case sci_strings :
                {
                    jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    int nbRow = (*jenv)->GetArrayLength(jenv, data);
                    int nbCol = 0;
                    int j = 0, k;
                    char ** strings = 0;

                    if (!data || nbRow == 0)
                    {
                        sciErr = createMatrixOfDoubleInNamedList(NULL, varName, currentList, i + 1, 0, 0, 0);
                        if (!data)
                        {
                            (*jenv)->DeleteLocalRef(jenv, data);
                        }
                        break;
                    }

                    // Get the matrix rows
                    for (; j < nbRow; j++)
                    {
                        jobjectArray oneDim = (jobjectArray)(*jenv)->GetObjectArrayElement(jenv, data, j);
                        if (nbCol == 0)
                        {
                            nbCol = (*jenv)->GetArrayLength(jenv, oneDim);
                            strings = (char**)MALLOC(sizeof(char*) * nbRow * nbCol);
                        }

                        // Get the matrix element
                        for (k = 0; k < nbCol; k++)
                        {
                            jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, oneDim, k);
                            jboolean isCopy1 = JNI_FALSE;
                            char *str = (char *)(*jenv)->GetStringUTFChars(jenv, j_string, &isCopy1);
                            strings[k * nbRow + j] = (char*)MALLOC(sizeof(char) * (strlen(str) + 1));
                            strcpy(strings[k * nbRow + j], str);
                            if (isCopy1)
                            {
                                (*jenv)->ReleaseStringUTFChars(jenv, j_string, (const char *)str);
                            }
                            (*jenv)->DeleteLocalRef(jenv, j_string);
                        }
                        (*jenv)->DeleteLocalRef(jenv, oneDim);
                    }
                    (*jenv)->DeleteLocalRef(jenv, data);

                    sciErr = createMatrixOfStringInNamedList(NULL, varName, currentList, i + 1, nbRow, nbCol, (const char * const*)strings);
                    for (j = 0; j < nbRow * nbCol; j++)
                    {
                        FREE(strings[j]);
                    }
                    FREE(strings);
                    break;
                }
                case sci_list :
                {
                    jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    sciErr = sendList(jenv, data, currentList, i + 1, varName, 'l');
                    (*jenv)->DeleteLocalRef(jenv, data);
                    break;
                }
                case sci_tlist :
                {
                    jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    sciErr = sendList(jenv, data, currentList, i + 1, varName, 't');
                    (*jenv)->DeleteLocalRef(jenv, data);
                    break;
                }
                case sci_mlist :
                {
                    jobject data = (*jenv)->GetObjectArrayElement(jenv, list, i + 1);
                    sciErr = sendList(jenv, data, currentList, i + 1, varName, 'm');
                    (*jenv)->DeleteLocalRef(jenv, data);
                    break;
                }
            }

            if (sciErr.iErr)
            {
                break;
            }
        }

        (*jenv)->ReleaseIntArrayElements(jenv, jtypes, types, JNI_ABORT);
        (*jenv)->DeleteLocalRef(jenv, jtypes);

        //popListAddress();

        if (!parentList)
        {
            //pushVariable(varName);
            //cleanStackListAddress();
        }

        return sciErr;
    }
Beispiel #14
0
BOOL CTimeShiftUtil::Send(
	NWPLAY_PLAY_INFO* val
	)
{
	CBlockLock lock(&this->utilLock);
	CBlockLock lock2(&this->ioLock);

	//送信先を設定する
	WCHAR ip[64];
	swprintf_s(ip, L"%d.%d.%d.%d", val->ip >> 24, val->ip >> 16 & 0xFF, val->ip >> 8 & 0xFF, val->ip & 0xFF);

	if( this->sendUdpIP.empty() == false && (val->udp == 0 || this->sendUdpIP != ip) ){
		this->sendUdpIP.clear();
		this->sendUdp.CloseUpload();
		ReleaseMutex(this->udpPortMutex);
		CloseHandle(this->udpPortMutex);
	}
	if( this->sendUdpIP.empty() && val->udp != 0 ){
		NW_SEND_INFO item;
		item.ip = val->ip;
		item.port = 1234;
		item.ipString = ip;
		item.broadcastFlag = FALSE;
		wstring mutexKey;
		for( ; item.port < 1234 + 100; item.port++ ){
			Format(mutexKey, L"%s%d_%d", MUTEX_UDP_PORT_NAME, val->ip, item.port);
			this->udpPortMutex = CreateMutex(NULL, TRUE, mutexKey.c_str());
			if( this->udpPortMutex ){
				if( GetLastError() != ERROR_ALREADY_EXISTS ){
					break;
				}
				CloseHandle(this->udpPortMutex);
				this->udpPortMutex = NULL;
			}
		}
		if( this->udpPortMutex ){
			OutputDebugString((mutexKey + L"\r\n").c_str());
			vector<NW_SEND_INFO> sendList(1, item);
			this->sendUdp.StartUpload(&sendList);
			this->sendUdpIP = ip;
			this->sendUdpPort = item.port;
		}
	}
	if( this->sendUdpIP.empty() == false ){
		val->udpPort = this->sendUdpPort;
	}

	if( this->sendTcpIP.empty() == false && (val->tcp == 0 || this->sendTcpIP != ip) ){
		this->sendTcpIP.clear();
		this->sendTcp.CloseUpload();
		ReleaseMutex(this->tcpPortMutex);
		CloseHandle(this->tcpPortMutex);
	}
	if( this->sendTcpIP.empty() && val->tcp != 0 ){
		NW_SEND_INFO item;
		item.ip = val->ip;
		item.port = 2230;
		item.ipString = ip;
		item.broadcastFlag = FALSE;
		wstring mutexKey;
		for( ; item.port < 2230 + 100; item.port++ ){
			Format(mutexKey, L"%s%d_%d", MUTEX_TCP_PORT_NAME, val->ip, item.port);
			this->tcpPortMutex = CreateMutex(NULL, TRUE, mutexKey.c_str());
			if( this->tcpPortMutex ){
				if( GetLastError() != ERROR_ALREADY_EXISTS ){
					break;
				}
				CloseHandle(this->tcpPortMutex);
				this->tcpPortMutex = NULL;
			}
		}
		if( this->tcpPortMutex ){
			OutputDebugString((mutexKey + L"\r\n").c_str());
			vector<NW_SEND_INFO> sendList(1, item);
			this->sendTcp.StartUpload(&sendList);
			this->sendTcpIP = ip;
			this->sendTcpPort = item.port;
		}
	}
	if( this->sendTcpIP.empty() == false ){
		val->tcpPort = this->sendTcpPort;
	}
	return TRUE;
}
Beispiel #15
0
int main(int argc, char* argv[])
{

        // args should only be the port number and the name
        // of the program running
        if (argc != 2) {
            printf("Usage Error - provide port number\n");
            exit(1);
        }

	char *port = argv[1];

        // create the ./files dir
        createSubdir();


	// getaddrinfo(): network address and service translation:
	struct addrinfo *socketaddrinfo = example_getaddrinfo(NULL, port);

	// socket(): create an endpoint for communication
	int sock = example_socket(socketaddrinfo);

	example_setsockopt(sock);
	example_bind(sock, socketaddrinfo);
	example_listen(sock, 128);
	freeaddrinfo(socketaddrinfo); // done with socketaddrinfo

	//printf("Press Ctrl+C to exit server.\n");
	//printf("Run a web browser on the same computer as you run the server and point it to:\n");
	//printf("http://127.0.0.1:%s\n", port);

	while(1)
	{
                printf("Waiting for connections...\n");
		// Get a socket for a particular incoming connection.
		int newsock = accept(sock, NULL, NULL);
		if(newsock == -1)
		{
			perror("accept(): ");
			continue; // try again if accept failed.
		}
                printf("Client connected\n");

                // Check the password of the client
                if (checkPass(newsock) == -1) {
                    printf("Incorrect password - Connection aborted\n");
                    closeSock(newsock);
                    continue;
                } else {
                    printf("Password accepted - Continuing connection\n");
                }

	        sendBytes(newsock, "You connected!\n", strlen("You connected!\n"));

                char cmd[1024];
                memset(cmd, 0, 1024);
                recvBytes(newsock, cmd, 1024);

                printf("Received command: %s\n", cmd);

                if (strcmp(cmd, "list") == 0) {
                    sendBytes(newsock, "File listing:\n", strlen("File listing:\n"));

                    // Scan the dirextory and send the file list
                    sendList(newsock);
                    continue;
                }

                if (strcmp(cmd, "get") == 0) {
                    char retBuf[1024];
                    memset(retBuf, 0, 1024);

                    // Read the name of the file
                    recvBytes(newsock, retBuf, 1024);

                    // Check if the file exists and send it
                    getFile(newsock, retBuf);
                    continue;
                }

                if (strcmp(cmd, "put") == 0) {
                    char retBuf[1024];
                    memset(retBuf, 0, 1024);

                    // Read the name of the file
                    getLine(newsock, retBuf);

                    // Check if the file exists and send it
                    putFile(newsock, retBuf);
                    continue;
                }

//		char http_body[] = "hello world";
//		char http_headers[1024];
//		snprintf(http_headers, 1024,
//		         "HTTP/1.0 200 OK\r\n"
//		         "Content-Length: %zu\r\n"
//		         "Content-Type: text/html\r\n\r\n",
//		         strlen(http_body)); // should check return value


		/* Note: send() does not guarantee that it will send all of
		 * the data that we ask it too. To reliably send data, we
		 * should inspect the return value from send() and then call
		 * send() again on any bytes did not get sent. */

		// Send the HTTP headers
		//if(send(newsock, http_headers, strlen(http_headers), 0) == -1)
		//{
		//	perror("send");
		//	close(newsock);
		//	exit(EXIT_FAILURE);
		//}

		//// Send the HTTP body
		//if(send(newsock, http_body, strlen(http_body), 0) == -1)
		//{
		//	perror("send");
		//	close(newsock);
		//	exit(EXIT_FAILURE);
		//}

		/* shutdown() (see "man 2 shutdown") can be used before
		   close(). It allows you to partially close a socket (i.e.,
		   indicate that we are done sending data but still could
		   receive). This could allow us to signal to a peer that we
		   are done sending data while still allowing us to receive
		   data. SHUT_RD will disallow reads from the socket, SHUT_WR
		   will disallow writes, and SHUT_RDWR will disallow read and
		   write. Also, unlike close(), shutdown() will affect all
		   processes that are sharing the socket---while close() only
		   affects the process that calls it. */
#if 0
		if(shutdown(newsock, SHUT_RDWR) == -1)
		{
			perror("shutdown");
			close(newsock);
			exit(EXIT_FAILURE);
		}
#endif

		closeSock(newsock);
	}
}
Beispiel #16
0
int main (int argc, char **argv)
{
        /* init vars */
    char opt;
    int numforks = 1;
    int msqid;
    int c;
    int i = 0;
    int j = 0;
    int bucket = 0;
    int found_word = 0;
    int msgLen;
    int msgTypes[MAXFORKS+1];
    int EOM = 0;
    char s[MXSTRGLEN];
    char t[MXSTRGLEN];
    struct linkedList * master;
    struct linkedList * childlist[MAXFORKS+1];
    struct mbuf m_toChild;
    struct mbuf m_toParent;
    /* sigaction for SIGINT  */
    struct sigaction si;
    struct sigaction ti;
    /* set up signal handling SIGINT  */
    si.sa_handler = sigi_handler;
    sigemptyset(&si.sa_mask);
    si.sa_flags = 0;
    /* initialize the actions */
    sigaction(SIGINT, &si, &ti);
    /*
       use getopt to parse command line options
       pull in the options from the command line
       convert the numbers to longs using strtol
       acceptable options:
       -n: number of sort forks to create
    */
    while ((opt = getopt (argc,argv,"n:"))!= -1)
        switch (opt){
            case 'n':
                numforks = (int)strtol(argv[optind-1], (char**)NULL, 10);
                break;
            case '?':
                printf("******error******\n");
            default:
                printf("bad input detected\n");
                exit(EXIT_FAILURE);
        }
    
    /*generate a message queue*/
    msqid = msgget(IPC_PRIVATE, S_IRUSR | S_IWUSR);
    

    /*make sure numforks is valid*/
    if (numforks > MAXFORKS) numforks = MAXFORKS;
    else if (numforks < 1) numforks = 1;
    /*bucketize messages into MAXFORKS/numforks buckets
    (most efficient for when MAXFORKS % numforks = 0*/
    bucket = 1;
    for (i = 1; i <= MAXFORKS; i++){
        msgTypes[i] = bucket;
        if (i % ((MAXFORKS ) / numforks) == 0 && bucket < numforks) bucket++;
    }
    /*fork and exec the spec'd no. of times*/
    for (i = 1; i <= numforks; i++){
        switch(fork()){
            case -1:
                perror("fork");
                exit(EXIT_FAILURE);
            case 0:

                /*init linked list for this child*/
                childlist[i]= createLinkedList();
                /*recieve messages until EOM sent*/
                while(!EOM){
                    msgrcv(msqid, &m_toChild, MXSTRGLEN, i, 0);
                    memcpy(t, m_toChild.mtext, MXSTRGLEN);
                    if(strcmp(t,"<EOM>\0") == 0){
                        EOM = 1;
                    }
                    else{
                    /*add received message to list*/
                        addSorted(childlist[i], t);
                    }
                }
                /*send linked list as a message*/
                /*printList(childlist[i]);*/
                sendList(childlist[i], i, msqid, &m_toParent);
                strcpy(m_toParent.mtext,"<EOM>\0");
                m_toParent.mtype = i;
                msgsnd(msqid, &m_toParent, MXSTRGLEN,0);
                /*printList(childlist[i]);*/

                exit(EXIT_SUCCESS);
            default:
                break;

        }
    }
    master = createLinkedList();
    /*parse the text, send it to sort processes*/
    i = 0;
    while ((c =fgetc(stdin)) != EOF )
    {
        /*if it's an alpha, convert it to lower case*/
        if (isalpha(c))
        {
            found_word = 1;
            c = tolower(c);
            /*fputc(c, stdout);*/
            s[j] = c;
            j++;
        }
        else if (found_word) {
            /*fputc('\n', stdout);*/
            s[j] = '\0';
            msgLen = j+1;
            memcpy(m_toChild.mtext, s, msgLen);
            j=0;
            i=0;
            found_word=0;
            m_toChild.mtype = msgTypify(s[0],msgTypes);
            /*addSorted(master, s);*/
            if (msgsnd(msqid, &m_toChild, msgLen, 0) == -1){
                perror("msgsnd");
                exit(EXIT_FAILURE);
            }
        }
    }
    /*send the sort processes the End Of Message*/
    memcpy(m_toChild.mtext, "<EOM>\0", sizeof("<EOM>\0"));
    for (i = 1; i <= numforks; i++){
        m_toChild.mtype = i;
        if (msgsnd(msqid, &m_toChild, msgLen, 0) == -1){
            perror("msgsnd");
            exit(EXIT_FAILURE);
        }
    }

    /*combine*/


    EOM = 0;
    while(EOM < numforks){
        msgrcv(msqid, &m_toParent, MXSTRGLEN, 0, 0);
        strcpy(s, m_toParent.mtext);
        if(strcmp(s,"<EOM>\0")==0) EOM++;
        else addBackList(master, s);
    }

    printList(master);

    /*kill the queue*/
    msgctl(msqid, IPC_RMID, NULL);

    /*wait for children to finish*/
    while (numforks > 1){
        wait(NULL);
        --numforks;
    }
    


    exit(EXIT_SUCCESS);
}
Beispiel #17
0
void ClientThread::analizeCommand(QByteArray &bytearray){
    QString userName;
    if (bytearray.contains("USER")) {
        QRegExp rx("^USER\\s(.*)");
        rx.indexIn(bytearray);
        userName = rx.cap(1);
        mUser = User::getUser(userName);
        sendString(FTPProtocol::getInstance()->getResponse(331));
        return;
    }

    if (bytearray.contains("PASS")) {
        QRegExp rx("^PASS\\s(.*)");
        rx.indexIn(bytearray);
        QString pass = rx.cap(1);
        if (mUser.isNull())
        {
            sendString(FTPProtocol::getInstance()->getResponse(503,"PASS send before USER"));
        }
        else
        {
            if (mUser.auth(pass))
            {
                // logged in
                 sendString(FTPProtocol::getInstance()->getResponse(230));
                 setAuthenticated(true);
                 if (ftpFileSystem != NULL)
                    delete ftpFileSystem;
                 ftpFileSystem = new FtpFileSystem(mUser.getFolder(), mUser.getFileAccess());
            }
            else
            {
                // incorrect
                 sendString(FTPProtocol::getInstance()->getResponse(530));
            }
        }
        return;
    }
    if (isAuthenticated())
    {
        // RNFR -> RNTO sequence
        if (mRenameBeginned){
            if (bytearray.contains("RNTO")){
                QRegExp rx("^RNTO\\s(.*)");
                rx.indexIn(fromEncoding(bytearray));
                QString newName = rx.cap(1);
                mRenameBeginned = false;
                if (ftpFileSystem->rename(mRenameOldName, newName))
                    sendString(FTPProtocol::getInstance()->getResponse(250));
                else
                    sendString(FTPProtocol::getInstance()->getResponse(550));
                return;
            }
            sendString(FTPProtocol::getInstance()->getResponse(503));
            return;
        }
        if (bytearray.contains("SYST")){
            QString syst("Windows Type : L8");
            sendString(FTPProtocol::getInstance()->getResponse(215, syst));
            return;
        }
        if (bytearray.contains("FEAT")){
            QString syst("211-Features:\n\rMDTM\n\rREST STREAM\n\rSIZE\n\rMLST type*;size*;modify*;\n\rMLSD\n\rUTF8\n\rCLNT\n\rMFMT\n\r211 End");
            sendString(syst);
            return;
        }
        if (bytearray.contains("HELP")){
            QString syst("HELP OK");
            sendString(FTPProtocol::getInstance()->getResponse(214, syst));
            return;
        }
        if (bytearray.contains("PWD")){
            sendString(FTPProtocol::getInstance()->getResponse(257, toEncoding("\""+ftpFileSystem->getWorkingDirectory()+"\"")));
            return;
        }
        if (bytearray.contains("OPTS")){
            QRegExp rx("^OPTS ([\\w\\s]+)");
            rx.indexIn(bytearray);
            QRegExp rx2("^UTF8 (\\w+)");
            rx2.indexIn(rx.cap(1));
            if (rx2.cap(1) == "ON")
            {
                mIsUTF8 = true;
            }
            if (rx2.cap(1) == "OFF")
            {
                mIsUTF8 = false;
            }
            sendString(FTPProtocol::getInstance()->getResponse(200));
            return;
        }
        if (bytearray.contains("TYPE")){
            // set transfer type
            QRegExp rx("^TYPE (\\w)( (\\w))?");
            rx.indexIn(bytearray);
            qDebug() << "type" << rx.cap(1) << rx.cap(3);
            mType = rx.cap(1);
            sendString(FTPProtocol::getInstance()->getResponse(200));
            return;
            if (mType == "I")
            {
                sendString(FTPProtocol::getInstance()->getResponse(200));
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("PORT")){
            mIsActiveMode = true;
            QRegExp rx("^PORT (\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)");
            rx.indexIn(bytearray);
            int p1,p2;
            QString buf(rx.cap(5));
            bool flag;
            p1 = rx.cap(5).toInt(&flag);
            p2 = rx.cap(6).toInt(&flag);
            QString addr = rx.cap(1)+"."+rx.cap(2)+"."+rx.cap(3)+"."+rx.cap(4);
            active_addr = addr;
            active_port = p1*256+p2;
            sendString(FTPProtocol::getInstance()->getResponse(200, "Port ok"));
            return;
        }

        if (bytearray.contains("LIST")){
            sendString(FTPProtocol::getInstance()->getResponse(150));
            sendList();
            sendString(FTPProtocol::getInstance()->getResponse(226));
            return;
        }
        if (bytearray.contains("QUIT")){
            sendString(FTPProtocol::getInstance()->getResponse(221));
            closeconnection();
            return;
        }
        if (bytearray.contains("CDUP")){
            if (ftpFileSystem->cdUp())
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("CWD")){
            QRegExp rx("^CWD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString subFolder = rx.cap(1);
            if (ftpFileSystem->changeDir(subFolder))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("RETR")){
            QRegExp rx("^RETR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            QString fullFileName = ftpFileSystem->getFileRead(filename);
            if (fullFileName != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(150));
                sendFile(fullFileName);
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550,"Permission denied"));
            }
            return;
        }
        if (bytearray.contains("STOR")){
            QRegExp rx("^STOR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            QString fullFileName = ftpFileSystem->getFileWrite(filename);
            if (fullFileName != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(150));
                recvFile(fullFileName);
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550,"Permission denied"));
            }
            return;
        }
        if (bytearray.contains("RMD")){
            QRegExp rx("^RMD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            if (ftpFileSystem->removeDir(filename))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("DELE")){
            QRegExp rx("^DELE\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            if (ftpFileSystem->deleteFile(filename))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("MKD")){
            QRegExp rx("^MKD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString dirName = rx.cap(1);
            if (ftpFileSystem->mkDir(dirName))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("PASV")){
            mIsActiveMode = false;
            selectPassivePort();
            return;
        }
        if (bytearray.contains("SIZE")){
            QRegExp rx("^SIZE\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString fileName = rx.cap(1);
            qint64 size;
            if (ftpFileSystem->getSize(fileName, &size))
            {
                sendString(FTPProtocol::getInstance()->getResponse(250, QString::number(size)));
            }
            else
            {
               sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("MDTM")){
            QRegExp rx("^MDTM\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString fileName = rx.cap(1);
            QString sdate = ftpFileSystem->getLastModified(fileName);
            if (sdate != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(250, sdate));
            }
            else
            {
               sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("RNFR")){
            QRegExp rx("^RNFR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            mRenameOldName = rx.cap(1);

            if (ftpFileSystem->exist(mRenameOldName) && ftpFileSystem->isWritable(mRenameOldName))
            {
                sendString(FTPProtocol::getInstance()->getResponse(350));
                mRenameBeginned = true;
            }
            else
                sendString(FTPProtocol::getInstance()->getResponse(550, "Permission denied"));
            return;
        }
    sendString(FTPProtocol::getInstance()->getResponse(500));
    }
    else
        sendString(FTPProtocol::getInstance()->getResponse(530));
}