bool configureName(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;

    if ( strlen(param) > 255 )
    {
        printf("* archive name is too long\n");
            return false;
    }

    if (strchr(param, ' ') != NULL)
    {
        printf("* sorry, archive name can't use spaces!\n");
        return false;
    }

    sendCommand(CMD_CONFIGURE_NAME, (char*)param, &(c->sock));

    if (recvCommand(0, &(c->sock)) == CMD_ACK)
        printf("* acknowledged archive name: %s\n",param);
    else
    {
        printf("* rejected archive name: %s\n",param);
        return false;
    }

    return true;
}
bool compress(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    int i=0;
    char buffer[MSGSIZE];
    char archive[MSGSIZE];

    /* direxists -> makesubdir*/

    for(i=0;i<MSGSIZE;i++)
        buffer[i]=0;

    sendCommand(CMD_COMPRESS, NULL, &(c->sock));

    if (recvCommand(buffer, &(c->sock)) != CMD_SEND)
    {
        printf("* compress \"%s\" failed. no file sent or server error\n",param);

        return false;
    }

    sendCommand(CMD_ACK, NULL, &(c->sock));
    printf("* downloading remote archive \"%s\"\n",buffer);

    pullfile(buffer, &(c->sock));

    strcpy(archive,param);
    addSlash(archive);
    strcat(archive,buffer);
    printf("* moving file \"%s\" to %s\n",buffer,archive);
    if (rename(buffer,archive)<0)
        perrorf("rename()");

    return true;
}
 void KillerInterface::runOnce(Killer &killer)
 {
     STREAM_INFO << "Waiting for next command...";
     const Command command = recvCommand();
     STREAM_INFO << "Received " << STREAM_OBJECT(command) << ", executing...";
     run(killer, command);
     STREAM_INFO << "Command " << STREAM_OBJECT(command) << " was successfully executed.";
 }
Ejemplo n.º 4
0
CDebugger::CDebugger(QObject *parent, QLocalSocket* socket)
	: QObject(parent)
	, m_clientConnection(socket)
	, m_targetItem(NULL)
{
	connect(m_clientConnection, SIGNAL(readyRead()),    this, SLOT(recvCommand()));
	connect(m_clientConnection, SIGNAL(destroyed()),    this, SLOT(deleteLater()));

	// 設定の変更通史の登録と設定からの初期化処理
	connect(theConf, SIGNAL(updateConfiguration(const Configuration*)),
	        this,  SLOT(updateConfiguration(const Configuration*)));
	updateConfiguration(theConf);
}
bool listfiles(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    char buffer[MSGSIZE];

    sendCommand(CMD_LIST, NULL , &(c->sock));

    if (recvCommand(buffer, &(c->sock)) == CMD_ACK)
        printf("* uploaded files:\n%s\n",buffer);
    else
        printf("* remote folder is empty!\n");

    return true;
}
bool removefile(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    sendCommand(CMD_REMOVE, (char *)param, &(c->sock));

    if (recvCommand(0, &(c->sock)) == CMD_ACK)
        printf("* %s removed\n",param);
    else
    {
        printf("* can't delete \"%s\"\n",param);
        return false;
    }
    return true;
}
bool configureCompressor(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    sendCommand(CMD_CONFIGURE_COMPRESSOR, (char*)param, &(c->sock));

    if (recvCommand(0,&(c->sock)) == CMD_ACK)
        printf("* acknowledged compression algorithm type: %s\n", param);
    else
    {
        printf("* rejected compression algorithm type: %s\n", param);
        return false;
    }

    return true;
}
bool ping(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    sendCommand(CMD_PING, NULL , &(c->sock));

    if ( recvCommand(0, &(c->sock)) == CMD_PING)
        printf("* pong!\n");
    else
    {
        printf("* ping failed\n");
        return false;
    }

    return true;
}
bool showConfiguration(char *param, void *conf)
{
    clientConfig *c=(clientConfig*)conf;
    char buffer[MSGSIZE];
    char name[256];
    char type[16];

    sendCommand(CMD_SHOW_CONFIGURATION, NULL, &(c->sock));

    if (recvCommand(buffer, &(c->sock)) == CMD_SHOW_CONFIGURATION )
    {
        sscanf(buffer,"%s / %s",name,type);
        printf("* archive name: %s\n",name);
        printf("* archive type: %s\n",type);
    }
    else
        return false;

    return true;
}
Ejemplo n.º 10
0
bool pushfile(const char *filename, unsigned int *sock)
{
    char buffer[BLOCK], msg[MSGSIZE] = "";
    int  size = fileSize(filename);
    int  nread, nwrite, tot=size;
    int  file;
    char *sha = shaDigest(filename);

    int columns=0;

    struct timeval start;
    struct timeval stop;
    double difftime=0;

    if ( (file = open(filename, O_RDONLY)) < 0)
    {
        perrorf("open()",0);
        sendCommand(CMD_ABORT, NULL, sock);
        free(sha);
        return false;
    }

    printFileInfo(filename,size,sha);
    sprintf(msg,"filesize:%d sha:%s", size, sha);
    sendCommand(CMD_FILE_INFO, (char *)msg, sock);

    if (recvCommand(NULL, sock) != CMD_ACK)
    {
        if(sha)
            free(sha);
        return false;
    }

    if (size<=0)
    {
        if(sha)
            free(sha);
        return false;
    }

    gettimeofday(&start,NULL);

    while(1)
    {
        memset(buffer, 0, BLOCK);
        if ((nread=read(file, buffer, BLOCK)) < 0 )
        {
            perrorf("read()",0);
            if (sha)
                free(sha);
            return false;
        }
        if ((nwrite=write(*sock, buffer, nread)) < 0)
            perrorf("write()",0);
        tot-=nwrite;

        if (columns > 0)
            stepProgressBar(size-tot,columns,size);

        if (tot <= 0)
            break;
    }
    gettimeofday(&stop,NULL);

    if (recvCommand(NULL, sock) != CMD_ACK)
        printf("* send of \"%s\" failed\n",filename);
    else
    {
        difftime=timeval_diff(&stop,&start);

        printf("* time:     %f seconds, ",difftime);
        num2human((long double)(size/difftime));
        printf("B/s\n");

        printf("* result:   sending \"%s\" completed successfully\n",filename);
    }

    if (sha)
        free(sha);
    close(file);
    return true;
}
Ejemplo n.º 11
0
bool pullfile(const char *filename, unsigned int *sock)
{
    char buffer[BLOCK];
    int size, nread=0, nwrite=0, tot=0, file;
    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
    char *sha=NULL, recv_sha[41] = "";

    int columns=0;

    struct timeval start;
    struct timeval stop;
    double difftime=0;


    if ((file=open(filename, O_WRONLY | O_CREAT, mode)) < 0)
    {
        makeSubDir((char*)filename);
        remove(filename);
        if ((file=open(filename, O_WRONLY | O_CREAT, mode))<0)
        {
            perrorf("open()",0);
            return false;
        }
    }

    if (recvCommand(buffer, sock) != CMD_FILE_INFO)
    {
        printf("* Can't get \"%s\". Permission or I/O error \n\n",filename);
        close(file);
        return false;
    }

    sscanf(buffer,"filesize:%d sha:%s",&size,recv_sha);
    printFileInfo(filename,size,recv_sha);

    sendCommand(CMD_ACK, NULL, sock);

    if (size==0)
    {
        close(file);
        return true;
    }
    if (size<0)
    {
        if (remove(filename) < 0)
            perrorf( "remove()",0);
        close(file);
        return false;
    }

    gettimeofday(&start,NULL);

    while(1)
    {
        memset(buffer, 0, BLOCK);
        if ((nread=read(*sock, buffer, BLOCK)) < 0)
        {
            perrorf("read()",0);
            return false;
        }    
        if ((nwrite=write(file, buffer, nread)) < 0 )
            perrorf(" write()",0);
        tot+=nread;

        if (columns > 0)
            stepProgressBar(tot,10,size);

        if (tot == size)
            break;
    }

    gettimeofday(&stop,NULL);
    difftime=timeval_diff(&stop,&start);

    printf("* time:     %f seconds, ",difftime);
    num2human((long double)(tot/difftime));
    printf("B/s\n");

    sha = shaDigest(filename);
    if (strcmp(sha, recv_sha) == 0)
    {
        printf("* result:   digest of %s is correct\n",filename);
        sendCommand(CMD_ACK, NULL, sock);
    }
    else
    {
        printf("* result:   digest of %s is wrong\n",filename);
        sendCommand(CMD_ABORT, NULL, sock);
    }

    printf("\n");

    if (sha)
        free(sha);

    close(file);
    return true;
}