Exemplo n.º 1
0
/// \brief main function of simpleTextFile.
int main(int nargs, char *argv[])
{
  std::cout << "simbleTextFile test start" << std::endl;

  // First parameter should be file name or -h for help.
  if (nargs != 2)
  {
    usage(argv[0],std::cerr);
    return 1;
  }
  QString l_argument(argv[1]);

  if (l_argument == "-h")
  {
    usage(argv[0]);
    return 0;
  }

  QFile l_file(l_argument);

  // Check if file exists.
  if (! l_file.exists())
  {
    std::cerr << "File " << l_file.fileName().toStdString() << " does not exists.\n";
    return 1;
  }

  Share::Resource::Config::getInstance()->setLocalStorage(true);
  Share::Resource::Config::getInstance()->setEncryptedByDefault(false);
  Share::Resource::Config::getInstance()->setPublicByDefault(false);

  Share::Auth l_auth;
  Share::Resource::Id l_id = shareFile(l_file,l_auth);

  //md5Resource();

  // Compare md5sum and size of l_file and resource


  return 0;
}
Exemplo n.º 2
0
/*
 * Permet de gérer une connection sur le socket sdClient dans un thread.
 */
void *manageClient(void* par[]) {
    pthread_t id_t = pthread_self();
    //Socket client
    int sdClient = ((acceptThreadArg*) par)->sock;
    struct sockaddr_in client_addr = ((acceptThreadArg*) par)->pair;
    char buffer[MSG_BUFFER_SIZE];
    int ret = 0;

    while (strncmp(buffer, "909", 3) != 0) {

        //Lecture du code du message.
        memset(buffer, 0, MSG_BUFFER_SIZE);
        ret = recv(sdClient, buffer, 3, 0);
        if (ret <= 0) {
            strcat(buffer, "909");
        }

        if (strncmp(buffer, "100", 3) == 0) {//Nouveau client
            if (initClientConnect(sdClient, client_addr) != 0) {
                printf("Erreur initClientConnect.\n");
                exit(EXIT_FAILURE);
            }
        } else if (strncmp(buffer, "200", 3) == 0) {//Partage d'un fichier
            if (shareFile(sdClient, client_addr) != 0) {
                printf("Erreur partage fichier.\n");
                exit(EXIT_FAILURE);
            }
        } else if (strncmp(buffer, "300", 3) == 0) {//DL d'un fichier
            if (dlFile(sdClient, client_addr) != 0) {
                printf("Erreur DL fichier.\n");
                exit(EXIT_FAILURE);
            }
        } else if (strncmp(buffer, "400", 3) == 0) {//Mise a jour meta-data

        }
    }
    //closesocket(sdClient);
    close(sdClient);
    pthread_exit((void*) id_t);
}