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;
}
Example #2
0
//http get is responsible if client give get command in terminal
int http_get(const char *file , int sockfd)
{
char muffer[MAXBUF];
char muf[MAXBUFI];
int bytes_read;//bytes_count;
unsigned int rv;
bytes_read = 1;
unsigned int i;
int g=1;
//int fd;
//int count=0;

printf("Name of file %s\n",file);
/*Putting the HTTP GET header into the buffer
-------------------------|
|GET /filebname HTTP/1.1
|Iam: gillb1


|<BODY>
-------------------------|
*/
sprintf(muffer, "GET /%s HTTP/1.1\r\nIam: gill\r\n\r\n", file);	
rv = 0;
rv = send(sockfd, muffer, strlen(muffer), 0);
if (rv != strlen(muffer))
	printf("Error @ send\n");
else
	printf("OK\n");
/*---While there's data, read and print it---*/
memset(muffer, '\0', MAXBUF);
bytes_read = recv(sockfd, muffer, sizeof(muffer), 0);
printf("%s\n",muffer);	


char REQNO[20] = { 0 };		
char* temp=NULL;	


/*Parsing the response for checking whether server has got the file or not*/
temp=strstr(muffer,"HTTP")+strlen("HTTP/1.1 ");	
for(i=0;i<strlen(temp);i++)
	{
	//check for new line					
	if (*(temp+i)=='\r')
		break;
	REQNO[i]=*(temp+i);						
	}
//printf("REQNO contains%s....strlen(REQNO)%d....strlen(404 NOTOK)%d\n",REQNO,strlen(REQNO),strlen("404 NOTOK"));
/***************************************************
Following ifelse statements print the response from the
server either there is an error or success.It compares
the header with 200OK and 404NOT OK.
**************************************************/
if(strcmp(REQNO,"200 OK")==0)
	{
	int k=1;
	/*
	Calls the pull file function, which will ultimately pull 
	the whole file from the server
	*/
	k=pullfile(g,file,muffer,sockfd);
	if(k==0)
		{
		printf("200OK successfull");
		}
	}//end of strcmp 200 OK 	
	else if ((strcmp(REQNO,"404 Not Found"))==0)
	{
		printf("File not found at reciever side , 400NOTOK");
	}
	else
	{
	printf("neither 200OK nor 400NOTOK...it could be HTTP/1.0");
	}	

memset(muf, '\0', MAXBUFI);
return 0;
//memset(buffer, '\0', MAXBUF);	
}