merge
This commit is contained in:
commit
470eaf2610
|
@ -0,0 +1,2 @@
|
||||||
|
/command-terminal/CommandTerminal/nbproject/private/
|
||||||
|
/command-terminal/CommandTerminal/build/
|
|
@ -12,12 +12,12 @@ lib/network/tcp/server.o: lib/header.h lib/network/tcp/server.h lib/network/tcp/
|
||||||
lib/network/udp/server.o: lib/header.h lib/network/udp/server.h lib/network/udp/server.c
|
lib/network/udp/server.o: lib/header.h lib/network/udp/server.h lib/network/udp/server.c
|
||||||
gcc $(CFLAGS) -c -o lib/network/udp/server.o lib/network/udp/server.c
|
gcc $(CFLAGS) -c -o lib/network/udp/server.o lib/network/udp/server.c
|
||||||
|
|
||||||
lib/util.o: lib/util.h lib/util.c
|
lib/network/format/serializer.o: lib/network/format/serializer.h lib/network/format/serializer.c
|
||||||
gcc $(CFLAGS) -c -o lib/util.o lib/util.c
|
gcc $(CFLAGS) -c -o lib/network/format/serializer.o lib/network/format/serializer.c
|
||||||
|
|
||||||
# Compiles the SGCA
|
# Compiles the SGCA
|
||||||
boot: lib/network/tcp/server.o lib/network/udp/server.o lib/util.o central-manager.h central-manager.c
|
boot: lib/network/tcp/server.o lib/network/udp/server.o lib/network/format/serializer.o central-manager.h central-manager.c
|
||||||
gcc $(CFLAGS) -o boot lib/network/udp/server.o lib/network/tcp/server.o lib/util.o central-manager.c
|
gcc $(CFLAGS) -o boot lib/network/udp/server.o lib/network/tcp/server.o lib/network/format/serializer.o central-manager.c
|
||||||
|
|
||||||
|
|
||||||
# Run full compilation
|
# Run full compilation
|
||||||
|
|
|
@ -5,15 +5,11 @@
|
||||||
* @argv : {0:program name}
|
* @argv : {0:program name}
|
||||||
*
|
*
|
||||||
* @history
|
* @history
|
||||||
* [0] Initialisation des variables
|
* [1] Lancement des THREADS d'écoute
|
||||||
* [1] On démarre le SERVEUR TCP d'écoute globale
|
* 1. On démarre le SERVEUR TCP d'écoute globale
|
||||||
* [2] On démarre le SERVEUR UDP d'écoute globale
|
* 2. On démarre le SERVEUR UDP d'écoute globale
|
||||||
* repeat:
|
* [2] On attends la fin de tous les THREADS
|
||||||
* [3] Attente d'une demande de connection TCP -> création d'un THREAD
|
* [3] On ferme la SOCKET d'écoute globale
|
||||||
* [4] Attente d'une demande de connection UDP -> création d'un THREAD
|
|
||||||
* si SIGINT:
|
|
||||||
* [3] On attends la fin de tous les THREADS
|
|
||||||
* [4] On ferme la SOCKET d'écoute globale
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int main(int argc, char* argv[]){
|
int main(int argc, char* argv[]){
|
||||||
|
@ -35,13 +31,16 @@ int main(int argc, char* argv[]){
|
||||||
pthread_join(listenManagers[0], NULL);
|
pthread_join(listenManagers[0], NULL);
|
||||||
pthread_join(listenManagers[1], NULL);
|
pthread_join(listenManagers[1], NULL);
|
||||||
|
|
||||||
/* [4] On ferme la SOCKET d'écoute globale
|
/* [3] On ferme la SOCKET d'écoute globale
|
||||||
==========================================================*/
|
==========================================================*/
|
||||||
printf("FERMETURE DE TOUTES LES CONNECTIONS!\n");
|
printf("FERMETURE DE TOUTES LES CONNECTIONS!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Attente de connection TCP
|
/* Attente de connection TCP
|
||||||
*
|
*
|
||||||
* @history
|
* @history
|
||||||
|
@ -136,6 +135,9 @@ void* LISTEN_TCP(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Attente de connection UDP
|
/* Attente de connection UDP
|
||||||
*
|
*
|
||||||
* @history
|
* @history
|
||||||
|
@ -262,7 +264,15 @@ void* managePlane(void* THREADABLE_SOCKET){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\t\tRequest(%d bytes) : '%s'\n", read, request);
|
/* 3. On désérialise la requête*/
|
||||||
|
|
||||||
|
|
||||||
|
printf("\t\tPLANE Request(%d bytes) : '%s'\n", read, request);
|
||||||
|
|
||||||
|
/* [3] Gestion de la requête
|
||||||
|
=========================================================*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}while( 0 );
|
}while( 0 );
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#include "lib/header.h"
|
#include "lib/header.h"
|
||||||
|
|
||||||
#include "lib/plane/plane.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* local dependencies */
|
/* local dependencies */
|
||||||
#include "lib/util.h"
|
|
||||||
#include "lib/network/tcp/server.h"
|
#include "lib/network/tcp/server.h"
|
||||||
#include "lib/network/udp/server.h"
|
#include "lib/network/udp/server.h"
|
||||||
|
#include "lib/network/format/serializer.h"
|
||||||
|
|
||||||
|
|
||||||
/* headers */
|
/* headers */
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include "serializer.h"
|
||||||
|
|
||||||
|
|
||||||
|
int parse_plane_request(const char* pIn, struct plane_request* pOut){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( strlen(pIn)*sizeof(char) != sizeof(struct plane_request) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Parse buffer */
|
||||||
|
memcpy(pOut, pIn, (size_t) sizeof(struct plane_request));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int parse_viewterm_request(const char* pIn, struct vterm_request* pOut){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( strlen(pIn)*sizeof(char) != sizeof(struct vterm_request) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Parse buffer */
|
||||||
|
memcpy(pOut, pIn, sizeof(struct vterm_request));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int parse_ctrlterm_request(const char* pIn, struct cterm_request* pOut){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( strlen(pIn)*sizeof(char) != sizeof(struct cterm_request) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Parse buffer */
|
||||||
|
memcpy(pOut, pIn, sizeof(struct cterm_request));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int serialize_term_response(const struct term_response* pIn, char* pOut, const size_t pSize){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( sizeof(struct term_response) > pSize*sizeof(char) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Serialize response into buffer */
|
||||||
|
memcpy(pOut, pIn, sizeof(struct term_response));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
|
@ -1,35 +1,66 @@
|
||||||
#ifndef _LIB_NETWORK_FORMAT_SERIALIZER_H_
|
#ifndef _LIB_NETWORK_FORMAT_SERIALIZER_H_
|
||||||
#define _LIB_NETWORK_FORMAT_SERIALIZER_H_
|
#define _LIB_NETWORK_FORMAT_SERIALIZER_H_
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "../../plane/plane.h"
|
||||||
|
|
||||||
#define SGCA_PLANE 0x01
|
struct plane_request{ // Plane Request
|
||||||
#define SGCA_VIEWTERM 0x02
|
struct coord co;
|
||||||
#define SGCA_CTRLTERM 0x04
|
struct control ct;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct vterm_request{ // ViewTerminal Request
|
||||||
#include "../../header.h";
|
|
||||||
|
|
||||||
struct view{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int z;
|
|
||||||
int cap;
|
|
||||||
int speed;
|
|
||||||
|
|
||||||
char id[6];
|
|
||||||
}; // 26 bytes
|
|
||||||
|
|
||||||
struct ctrl{
|
|
||||||
int cap;
|
|
||||||
int speed;
|
|
||||||
int z;
|
|
||||||
}; // 12 bytes
|
|
||||||
|
|
||||||
struct netflow{
|
|
||||||
char type;
|
|
||||||
char flags;
|
char flags;
|
||||||
char data[39];
|
};
|
||||||
} // 41 bytes
|
|
||||||
|
struct term_response{ // Terminal-s Response
|
||||||
|
char flags;
|
||||||
|
struct coord co;
|
||||||
|
struct control ct;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cterm_request{ // ControlTerminal Request
|
||||||
|
char flags;
|
||||||
|
int z;
|
||||||
|
struct control ct;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Parse a plane request ('char*' to 'struct plane_request')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to destination struct)
|
||||||
|
* [2] Parse buffer to struct
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int parse_plane_request(const char* pIn, struct plane_request* pOut);
|
||||||
|
|
||||||
|
/* Parse a viewTerminal request ('char*' to 'struct vt_request')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to destination struct)
|
||||||
|
* [2] Parse buffer to struct
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int parse_viewterm_request(const char* pIn, struct vterm_request* pOut);
|
||||||
|
|
||||||
|
/* Parse a ctrlTerminal request ('char*' to 'struct ct_request')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to destination struct)
|
||||||
|
* [2] Parse buffer to struct
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int parse_ctrlterm_request(const char* pIn, struct cterm_request* pOut);
|
||||||
|
|
||||||
|
/* Serialize a Terminal response ('struct t_response' to 'char*')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to input struct)
|
||||||
|
* [2] Serialize struct into buffer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int serialize_term_response(const struct term_response* pIn, char* pOut, const size_t pSize);
|
||||||
|
>>>>>>> d647392d99c86e94aa550f6cf0e7f284c4b226a3
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1 +0,0 @@
|
||||||
../../../global/plane.c
|
|
|
@ -1 +1 @@
|
||||||
../../../global/plane.h
|
../../../plane/plane.h
|
|
@ -1,104 +0,0 @@
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
|
|
||||||
int swrite(int* pSocket, char* pBuffer){
|
|
||||||
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
|
||||||
if( strlen(pBuffer) == 0 ) return 0; // si on a rien à écrire, on n'écrit rien :p
|
|
||||||
|
|
||||||
|
|
||||||
/* 1. On écrit sur la SOCKET */
|
|
||||||
if( DEBUGMOD&BUF ) printf("SENDLEN_1: %lu\n", strlen(pBuffer));
|
|
||||||
int nbSent = write(*pSocket, pBuffer, strlen(pBuffer));
|
|
||||||
if( DEBUGMOD&BUF ) printf("SENDLEN_2: %d\n", nbSent);
|
|
||||||
|
|
||||||
/* 2. Si on est déconnecté, on retourne une erreur */
|
|
||||||
if( nbSent <= 0 ){
|
|
||||||
if( DEBUGMOD&BUF ) printf("NOTHING TO SEND\n");
|
|
||||||
return -1; // on retourne une erreur
|
|
||||||
}
|
|
||||||
|
|
||||||
if( DEBUGMOD&RVL ) printf("SEND_1\n");
|
|
||||||
if( DEBUGMOD&RVL ) revealString(pBuffer);
|
|
||||||
if( DEBUGMOD&RVL ) printf("SEND_2\n");
|
|
||||||
|
|
||||||
|
|
||||||
/* 3. On retourne le nombre de <char> envoyés */
|
|
||||||
return nbSent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int sread(int* pSocket, char* pBuffer){
|
|
||||||
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
|
||||||
|
|
||||||
|
|
||||||
/* 1. On vide le buffer avant de lire */
|
|
||||||
memset(pBuffer, '\0', MAX_BUF_LEN);
|
|
||||||
if( DEBUGMOD&BUF ) printf("READLEN_1: %lu\n", strlen(pBuffer));
|
|
||||||
|
|
||||||
/* 2. On lit la SOCKET */
|
|
||||||
int nbRead = read(*pSocket, pBuffer, MAX_BUF_LEN);
|
|
||||||
if( DEBUGMOD&BUF ) printf("READLEN_3: %d\n", nbRead);
|
|
||||||
|
|
||||||
|
|
||||||
/* 3. Si on est déconnecté, on retourne une erreur */
|
|
||||||
if( nbRead <= 0 ){
|
|
||||||
if( DEBUGMOD&BUF ) printf("NOTHING TO READ\n");
|
|
||||||
return -1; // on retourne une erreur
|
|
||||||
}
|
|
||||||
|
|
||||||
if( DEBUGMOD&RVL ) printf("READ_1\n");
|
|
||||||
if( DEBUGMOD&RVL ) revealString(pBuffer);
|
|
||||||
if( DEBUGMOD&RVL ) printf("READ_2\n");
|
|
||||||
|
|
||||||
/* 4. On retourne le nombre de caractères lus */
|
|
||||||
return nbRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec){
|
|
||||||
/* 1. On créé la structure contenant le timeout */
|
|
||||||
struct timeval timeout;
|
|
||||||
timeout.tv_sec = pSec;
|
|
||||||
timeout.tv_usec = pUSec;
|
|
||||||
|
|
||||||
setsockopt(*pSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(struct timeval));
|
|
||||||
|
|
||||||
if( DEBUGMOD&SCK ) printf("Set socket(%d) timeout to %lus\n", *pSocket, (long unsigned) timeout.tv_sec );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xPrint(char* pPattern, char* pBuffer){
|
|
||||||
char tmpBuffer[MAX_BUF_LEN];
|
|
||||||
strcpy(tmpBuffer, pBuffer);
|
|
||||||
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// on supprimes les retours à la ligne de la fin
|
|
||||||
for( i = strlen(tmpBuffer)-1 ; i >= 0 && tmpBuffer[i] != '\0' ; i-- )
|
|
||||||
if( tmpBuffer[i] == '\n' || tmpBuffer[i] == '\r' ) // si c'est un retour chariot
|
|
||||||
tmpBuffer[i] = '\0'; // on efface
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
printf(pPattern, pBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void revealString(char* pString){
|
|
||||||
/* 1. On créé une copie de @pString */
|
|
||||||
char revealedString[MAX_BUF_LEN] = {0};
|
|
||||||
|
|
||||||
/* 2. On rend visible tous les caractères "invisibles" */
|
|
||||||
int i;
|
|
||||||
for( i = 0 ; i < strlen(pString) && pString[i] != '\0' ; i++ ){
|
|
||||||
if( pString[i] == '\r' ){ revealedString[strlen(revealedString)] = '\\'; revealedString[strlen(revealedString)] = 'r'; }
|
|
||||||
else if( pString[i] == '\n' ){ revealedString[strlen(revealedString)] = '\\'; revealedString[strlen(revealedString)] = 'n'; }
|
|
||||||
else revealedString[strlen(revealedString)] = pString[i];
|
|
||||||
|
|
||||||
revealedString[strlen(revealedString)] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 3. On affiche la chaîne explicite */
|
|
||||||
if( DEBUGMOD&RVL ) printf("[[%s]]\n", revealedString);
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec);
|
|
||||||
|
|
||||||
|
|
||||||
/* read/write socket */
|
|
||||||
int swrite(int* pSocket, char* pBuffer);
|
|
||||||
int sread(int* pSocket, char* pBuffer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Affiche une string en supprimant les retours à la ligne de fin de chaînes
|
|
||||||
*
|
|
||||||
* @pPattern<char*> Schéma du print (1er arg)
|
|
||||||
* @pBuffer<char*> Buffer en question
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void xPrint(char* pPattern, char* pBuffer);
|
|
||||||
|
|
||||||
|
|
||||||
/* Révèle les caractères spéciaux d'une string
|
|
||||||
*
|
|
||||||
* @pString<char*> La string à révéler
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @print explicitString<char*> On affiche la chaîne explicité
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void revealString(char* pString);
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- You may freely edit this file. See commented blocks below for -->
|
||||||
|
<!-- some examples of how to customize the build. -->
|
||||||
|
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||||
|
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||||
|
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||||
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
|
<project name="CommandTerminal" default="default" basedir=".">
|
||||||
|
<description>Builds, tests, and runs the project CommandTerminal.</description>
|
||||||
|
<import file="nbproject/build-impl.xml"/>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
There exist several targets which are by default empty and which can be
|
||||||
|
used for execution of your tasks. These targets are usually executed
|
||||||
|
before and after some main targets. They are:
|
||||||
|
|
||||||
|
-pre-init: called before initialization of project properties
|
||||||
|
-post-init: called after initialization of project properties
|
||||||
|
-pre-compile: called before javac compilation
|
||||||
|
-post-compile: called after javac compilation
|
||||||
|
-pre-compile-single: called before javac compilation of single file
|
||||||
|
-post-compile-single: called after javac compilation of single file
|
||||||
|
-pre-compile-test: called before javac compilation of JUnit tests
|
||||||
|
-post-compile-test: called after javac compilation of JUnit tests
|
||||||
|
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||||
|
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||||
|
-pre-jar: called before JAR building
|
||||||
|
-post-jar: called after JAR building
|
||||||
|
-post-clean: called after cleaning build products
|
||||||
|
|
||||||
|
(Targets beginning with '-' are not intended to be called on their own.)
|
||||||
|
|
||||||
|
Example of inserting an obfuscator after compilation could look like this:
|
||||||
|
|
||||||
|
<target name="-post-compile">
|
||||||
|
<obfuscate>
|
||||||
|
<fileset dir="${build.classes.dir}"/>
|
||||||
|
</obfuscate>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
For list of available properties check the imported
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
|
||||||
|
Another way to customize the build is by overriding existing main targets.
|
||||||
|
The targets of interest are:
|
||||||
|
|
||||||
|
-init-macrodef-javac: defines macro for javac compilation
|
||||||
|
-init-macrodef-junit: defines macro for junit execution
|
||||||
|
-init-macrodef-debug: defines macro for class debugging
|
||||||
|
-init-macrodef-java: defines macro for class execution
|
||||||
|
-do-jar: JAR building
|
||||||
|
run: execution of project
|
||||||
|
-javadoc-build: Javadoc generation
|
||||||
|
test-report: JUnit report generation
|
||||||
|
|
||||||
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
|
<target name="run" depends="CommandTerminal-impl.jar">
|
||||||
|
<exec dir="bin" executable="launcher.exe">
|
||||||
|
<arg file="${dist.jar}"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
Notice that the overridden target depends on the jar target and not only on
|
||||||
|
the compile target as the regular run target does. Again, for a list of available
|
||||||
|
properties which you can use, check the target you are overriding in the
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
-->
|
||||||
|
</project>
|
|
@ -0,0 +1,3 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,8 @@
|
||||||
|
build.xml.data.CRC32=fdad8e2e
|
||||||
|
build.xml.script.CRC32=1cd81838
|
||||||
|
build.xml.stylesheet.CRC32=8064a381@1.74.1.48
|
||||||
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
|
nbproject/build-impl.xml.data.CRC32=fdad8e2e
|
||||||
|
nbproject/build-impl.xml.script.CRC32=95faf5a3
|
||||||
|
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.1.48
|
|
@ -0,0 +1,73 @@
|
||||||
|
annotation.processing.enabled=true
|
||||||
|
annotation.processing.enabled.in.editor=false
|
||||||
|
annotation.processing.processor.options=
|
||||||
|
annotation.processing.processors.list=
|
||||||
|
annotation.processing.run.all.processors=true
|
||||||
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
|
build.classes.dir=${build.dir}/classes
|
||||||
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
|
# This directory is removed when the project is cleaned:
|
||||||
|
build.dir=build
|
||||||
|
build.generated.dir=${build.dir}/generated
|
||||||
|
build.generated.sources.dir=${build.dir}/generated-sources
|
||||||
|
# Only compile against the classpath explicitly listed here:
|
||||||
|
build.sysclasspath=ignore
|
||||||
|
build.test.classes.dir=${build.dir}/test/classes
|
||||||
|
build.test.results.dir=${build.dir}/test/results
|
||||||
|
# Uncomment to specify the preferred debugger connection transport:
|
||||||
|
#debug.transport=dt_socket
|
||||||
|
debug.classpath=\
|
||||||
|
${run.classpath}
|
||||||
|
debug.test.classpath=\
|
||||||
|
${run.test.classpath}
|
||||||
|
# Files in build.classes.dir which should be excluded from distribution jar
|
||||||
|
dist.archive.excludes=
|
||||||
|
# This directory is removed when the project is cleaned:
|
||||||
|
dist.dir=dist
|
||||||
|
dist.jar=${dist.dir}/CommandTerminal.jar
|
||||||
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
|
excludes=
|
||||||
|
includes=**
|
||||||
|
jar.compress=false
|
||||||
|
javac.classpath=
|
||||||
|
# Space-separated list of extra javac options
|
||||||
|
javac.compilerargs=
|
||||||
|
javac.deprecation=false
|
||||||
|
javac.processorpath=\
|
||||||
|
${javac.classpath}
|
||||||
|
javac.source=1.8
|
||||||
|
javac.target=1.8
|
||||||
|
javac.test.classpath=\
|
||||||
|
${javac.classpath}:\
|
||||||
|
${build.classes.dir}
|
||||||
|
javac.test.processorpath=\
|
||||||
|
${javac.test.classpath}
|
||||||
|
javadoc.additionalparam=
|
||||||
|
javadoc.author=false
|
||||||
|
javadoc.encoding=${source.encoding}
|
||||||
|
javadoc.noindex=false
|
||||||
|
javadoc.nonavbar=false
|
||||||
|
javadoc.notree=false
|
||||||
|
javadoc.private=false
|
||||||
|
javadoc.splitindex=true
|
||||||
|
javadoc.use=true
|
||||||
|
javadoc.version=false
|
||||||
|
javadoc.windowtitle=
|
||||||
|
main.class=commandterminal.CommandTerminal
|
||||||
|
manifest.file=manifest.mf
|
||||||
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
|
mkdist.disabled=false
|
||||||
|
platform.active=default_platform
|
||||||
|
run.classpath=\
|
||||||
|
${javac.classpath}:\
|
||||||
|
${build.classes.dir}
|
||||||
|
# Space-separated list of JVM arguments used when running the project.
|
||||||
|
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||||
|
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||||
|
run.jvmargs=
|
||||||
|
run.test.classpath=\
|
||||||
|
${javac.test.classpath}:\
|
||||||
|
${build.test.classes.dir}
|
||||||
|
source.encoding=UTF-8
|
||||||
|
src.dir=src
|
||||||
|
test.src.dir=test
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
|
<name>CommandTerminal</name>
|
||||||
|
<source-roots>
|
||||||
|
<root id="src.dir"/>
|
||||||
|
</source-roots>
|
||||||
|
<test-roots>
|
||||||
|
<root id="test.src.dir"/>
|
||||||
|
</test-roots>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package DatagramSocket;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author lmascaro
|
||||||
|
*/
|
||||||
|
public class AsynchronousDatagramSocket implements Runnable, AutoCloseable{
|
||||||
|
|
||||||
|
private final static int MAX_MESSAGE_SIZE = 300;
|
||||||
|
|
||||||
|
private SynchronizedBuffer<DatagramPacket> buf;
|
||||||
|
private DatagramSocket socket;
|
||||||
|
|
||||||
|
public AsynchronousDatagramSocket() throws SocketException{
|
||||||
|
this.buf = new SynchronizedBuffer<>();
|
||||||
|
this.socket = new DatagramSocket();
|
||||||
|
new Thread(this).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsynchronousDatagramSocket(int port) throws SocketException{
|
||||||
|
this.buf = new SynchronizedBuffer<>();
|
||||||
|
this.socket = new DatagramSocket(port);
|
||||||
|
new Thread(this).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(DatagramPacket dp) throws IOException{
|
||||||
|
this.socket.send(dp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean asynchronousReceive(DatagramPacket dp){
|
||||||
|
if(this.buf.available() == 0){
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
dp = this.buf.removeElement(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void synchronousReceive(DatagramPacket dp){
|
||||||
|
dp = this.buf.removeElement(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean available(){
|
||||||
|
return this.buf.available()>0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(){
|
||||||
|
this.socket.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
DatagramPacket packet = new DatagramPacket(new byte[MAX_MESSAGE_SIZE],MAX_MESSAGE_SIZE);
|
||||||
|
try {
|
||||||
|
this.socket.receive(packet);
|
||||||
|
this.buf.addElement(packet);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(AsynchronousDatagramSocket.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package DatagramSocket;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author lmascaro
|
||||||
|
*/
|
||||||
|
public class SynchronizedBuffer<T>{
|
||||||
|
|
||||||
|
private LinkedList<T> elements = new LinkedList<T>();
|
||||||
|
|
||||||
|
public synchronized T removeElement(boolean sync){
|
||||||
|
if(!sync && this.elements.isEmpty()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(this.elements.isEmpty()){
|
||||||
|
try {
|
||||||
|
this.wait();
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Logger.getLogger(SynchronizedBuffer.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.elements.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void addElement(T elem){
|
||||||
|
this.elements.add(elem);
|
||||||
|
this.notifyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int available(){
|
||||||
|
return this.elements.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package commandterminal;
|
||||||
|
|
||||||
|
import DatagramSocket.AsynchronousDatagramSocket;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InterfaceAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author lmascaro
|
||||||
|
*/
|
||||||
|
public class CommandTerminal {
|
||||||
|
|
||||||
|
private final static int SGCA_BROADCAST_PORT = 9999;
|
||||||
|
private final static int MAX_MESSAGE_SIZE = 300;
|
||||||
|
private static AsynchronousDatagramSocket socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args){
|
||||||
|
|
||||||
|
//the following code go through every interfaces to get broadcasts addresses in order to contact the sgca
|
||||||
|
HashSet<InetAddress> listOfBroadcasts = new HashSet<InetAddress>();
|
||||||
|
Enumeration list;
|
||||||
|
try {
|
||||||
|
list = NetworkInterface.getNetworkInterfaces();
|
||||||
|
|
||||||
|
while(list.hasMoreElements()) {
|
||||||
|
NetworkInterface iface = (NetworkInterface) list.nextElement();
|
||||||
|
|
||||||
|
if(iface == null) continue;
|
||||||
|
//if the interface is not loopback
|
||||||
|
if(!iface.isLoopback() && iface.isUp()) {
|
||||||
|
|
||||||
|
Iterator it = iface.getInterfaceAddresses().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
InterfaceAddress address = (InterfaceAddress) it.next();
|
||||||
|
if(address == null) continue;
|
||||||
|
InetAddress broadcast = address.getBroadcast();
|
||||||
|
if(broadcast != null)
|
||||||
|
{
|
||||||
|
//we found it !
|
||||||
|
listOfBroadcasts.add(broadcast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException ex) {
|
||||||
|
System.err.println("Error while getting network interfaces");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer sgcaPort;
|
||||||
|
InetAddress sgcaAddress;
|
||||||
|
DatagramPacket packet;
|
||||||
|
try {
|
||||||
|
//try to send a request to all the broadcasts (usually there is only one) and wait for the response of the sgca
|
||||||
|
DatagramSocket broadcastSocket = new DatagramSocket();
|
||||||
|
byte[] data;
|
||||||
|
for(InetAddress adr : listOfBroadcasts){
|
||||||
|
data = new byte[1];
|
||||||
|
Integer clientType = 1;
|
||||||
|
data[0] = clientType.byteValue();
|
||||||
|
packet = new DatagramPacket(data,data.length,adr,SGCA_BROADCAST_PORT);
|
||||||
|
broadcastSocket.send(packet);
|
||||||
|
|
||||||
|
}
|
||||||
|
data = new byte[1];
|
||||||
|
packet = new DatagramPacket(data,data.length);
|
||||||
|
broadcastSocket.receive(packet);
|
||||||
|
sgcaAddress = packet.getAddress();
|
||||||
|
Byte b = new Byte(packet.getData()[0]);
|
||||||
|
sgcaPort = b.intValue();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.getLogger(CommandTerminal.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//from now we assume that the network discovery part went well and we have the port/address of the sgca
|
||||||
|
//send a ISALIVE to ensure the sgca is ready to receive commands
|
||||||
|
DatagramSocket comSock;
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(1);
|
||||||
|
try {
|
||||||
|
comSock = new DatagramSocket(sgcaPort);
|
||||||
|
buf.putInt(OpCode.ISALIVE.ordinal());
|
||||||
|
packet = new DatagramPacket(buf.array(),buf.arrayOffset(),sgcaAddress,sgcaPort);
|
||||||
|
comSock.send(packet);
|
||||||
|
|
||||||
|
//receive response
|
||||||
|
comSock.receive(packet);
|
||||||
|
Byte response = new Byte(packet.getData()[0]);
|
||||||
|
OpCode success = OpCode.values()[response.intValue()];
|
||||||
|
|
||||||
|
if(success != OpCode.SUCCESS){
|
||||||
|
System.out.println("SGCA Not ready, exiting");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.getLogger(CommandTerminal.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
//now the sgca is connected and ready, let's start the real work
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package commandterminal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author lmascaro
|
||||||
|
*/
|
||||||
|
public enum OpCode {
|
||||||
|
ISALIVE,
|
||||||
|
CAP,
|
||||||
|
ALT,
|
||||||
|
SPEED,
|
||||||
|
SUCCESS,
|
||||||
|
ERROR
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
CFLAGS=-Wall
|
||||||
|
|
||||||
|
# Runs 'all' depenency as default / i.e. 'make' command will run 'make all' implicitly
|
||||||
|
default: all
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lib/network/tcp/client.o: lib/header.h lib/network/tcp/client.h lib/network/tcp/client.c
|
||||||
|
gcc $(CFLAGS) -c -o lib/network/tcp/client.o lib/network/tcp/client.c
|
||||||
|
|
||||||
|
lib/network/format/serializer.o: lib/network/format/serializer.h lib/network/format/serializer.c
|
||||||
|
gcc $(CFLAGS) -c -o lib/network/format/serializer.o lib/network/format/serializer.c
|
||||||
|
|
||||||
|
# Compiles the Plane
|
||||||
|
boot: lib/network/tcp/client.o lib/network/format/serializer.o plane.h plane.c
|
||||||
|
gcc $(CFLAGS) -o boot lib/network/tcp/client.o lib/network/format/serializer.o plane.c -lm
|
||||||
|
|
||||||
|
|
||||||
|
# Run full compilation
|
||||||
|
all: boot
|
||||||
|
|
||||||
|
# cleans the compiled files
|
||||||
|
clean:
|
||||||
|
rm boot;
|
||||||
|
rm ./**/*.o
|
|
@ -1,500 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head data-suburl="">
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
|
||||||
|
|
||||||
<meta name="author" content="xdrm-brackets" />
|
|
||||||
<meta name="description" content="proxy.ftp.c" />
|
|
||||||
<meta name="keywords" content="go, git, self-hosted, gogs">
|
|
||||||
|
|
||||||
<meta name="referrer" content="no-referrer" />
|
|
||||||
<meta name="_csrf" content="oL9HDhjy3U7tPSwjawLkQB4VNfA6MTQ5MDcxOTc2NTY0Nzg0MDkyNQ==" />
|
|
||||||
<meta name="_suburl" content="" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<meta property="og:url" content="https://git.xdrm.io/xdrm-brackets/proxy.ftp.c" />
|
|
||||||
<meta property="og:type" content="object" />
|
|
||||||
<meta property="og:title" content="xdrm-brackets/proxy.ftp.c">
|
|
||||||
<meta property="og:description" content="">
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="shortcut icon" href="/img/favicon.png" />
|
|
||||||
|
|
||||||
<script src="/js/jquery-1.11.3.min.js"></script>
|
|
||||||
<script src="/js/libs/jquery.are-you-sure.js"></script>
|
|
||||||
<link rel="stylesheet" href="/assets/font-awesome-4.6.3/css/font-awesome.min.css">
|
|
||||||
<link rel="stylesheet" href="/assets/octicons-4.3.0/octicons.min.css">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="/css/semantic-2.2.7.min.css">
|
|
||||||
<link rel="stylesheet" href="/css/gogs.css?v=73519fd9811805bce6fc4aa2d24bb413">
|
|
||||||
|
|
||||||
|
|
||||||
<script src="/js/semantic-2.2.7.min.js"></script>
|
|
||||||
<script src="/js/gogs.js?v=73519fd9811805bce6fc4aa2d24bb413"></script>
|
|
||||||
|
|
||||||
<title>xdrm-brackets/proxy.ftp.c - xdrm-brackets' git server</title>
|
|
||||||
|
|
||||||
<meta name="theme-color" content="#ff5343">
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="full height">
|
|
||||||
<noscript>Please enable JavaScript in your browser!</noscript>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="following bar light">
|
|
||||||
<div class="ui container">
|
|
||||||
<div class="ui grid">
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui top secondary menu">
|
|
||||||
<a class="item brand" href="/">
|
|
||||||
<img class="ui mini image" src="/img/favicon.png">
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
<a class="item" href="/">Home</a>
|
|
||||||
|
|
||||||
|
|
||||||
<a class="item" href="/explore/repos">Explore</a>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a class="item" target="_blank" href="https://gogs.io/docs" rel="noreferrer">Help</a>
|
|
||||||
<div class="right menu">
|
|
||||||
|
|
||||||
<a class="item" href="/user/sign_up">
|
|
||||||
<i class="octicon octicon-person"></i> Register
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class="item" href="/user/login?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
|
|
||||||
<i class="octicon octicon-sign-in"></i> Sign In
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="repository file list">
|
|
||||||
<div class="header-wrapper">
|
|
||||||
|
|
||||||
<div class="ui container">
|
|
||||||
<div class="ui vertically padded grid head">
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui header">
|
|
||||||
<div class="ui huge breadcrumb">
|
|
||||||
<i class="mega-octicon octicon-repo"></i>
|
|
||||||
<a href="/xdrm-brackets">xdrm-brackets</a>
|
|
||||||
<div class="divider"> / </div>
|
|
||||||
<a href="/xdrm-brackets/proxy.ftp.c">proxy.ftp.c</a>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui right">
|
|
||||||
<div class="ui labeled button" tabindex="0">
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/watch?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
|
|
||||||
<i class="icon fa-eye-slash"></i>Watch
|
|
||||||
</a>
|
|
||||||
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/watchers">
|
|
||||||
1
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="ui labeled button" tabindex="0">
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/star?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
|
|
||||||
<i class="icon fa-star-o"></i>Star
|
|
||||||
</a>
|
|
||||||
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/stars">
|
|
||||||
0
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui labeled button" tabindex="0">
|
|
||||||
<a class="ui button " href="/repo/fork/49">
|
|
||||||
<i class="octicon octicon-repo-forked"></i>Fork
|
|
||||||
</a>
|
|
||||||
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/forks">
|
|
||||||
0
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="ui tabs container">
|
|
||||||
<div class="ui tabular menu navbar">
|
|
||||||
<a class="active item" href="/xdrm-brackets/proxy.ftp.c">
|
|
||||||
<i class="octicon octicon-file-text"></i> Files
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/issues">
|
|
||||||
<i class="octicon octicon-issue-opened"></i> Issues <span class="ui gray small label">0</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/pulls">
|
|
||||||
<i class="octicon octicon-git-pull-request"></i> Pull Requests <span class="ui gray small label">0</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/commits/master">
|
|
||||||
<i class="octicon octicon-history"></i> Commits <span class="ui blue small label">23</span>
|
|
||||||
</a>
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/releases">
|
|
||||||
<i class="octicon octicon-tag"></i> Releases <span class="ui gray small label">0</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/wiki">
|
|
||||||
<i class="octicon octicon-book"></i> Wiki
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ui tabs divider"></div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui container">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p id="repo-desc">
|
|
||||||
<span class="no-description text-italic">No Description</span>
|
|
||||||
<a class="link" href=""></a>
|
|
||||||
</p>
|
|
||||||
<div class="ui secondary menu">
|
|
||||||
|
|
||||||
<div class="fitted item choose reference">
|
|
||||||
<div class="ui floating filter dropdown" data-no-results="No results found.">
|
|
||||||
<div class="ui basic small button">
|
|
||||||
<span class="text">
|
|
||||||
<i class="octicon octicon-git-branch"></i>
|
|
||||||
Branch:
|
|
||||||
<strong>master</strong>
|
|
||||||
</span>
|
|
||||||
<i class="dropdown icon"></i>
|
|
||||||
</div>
|
|
||||||
<div class="menu">
|
|
||||||
<div class="ui icon search input">
|
|
||||||
<i class="filter icon"></i>
|
|
||||||
<input name="search" placeholder="Filter branch or tag...">
|
|
||||||
</div>
|
|
||||||
<div class="header">
|
|
||||||
<div class="ui grid">
|
|
||||||
<div class="two column row">
|
|
||||||
<a class="reference column" href="#" data-target="#branch-list">
|
|
||||||
<span class="text black">
|
|
||||||
<i class="octicon octicon-git-branch"></i> Branches
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
<a class="reference column" href="#" data-target="#tag-list">
|
|
||||||
<span class="text ">
|
|
||||||
<i class="reference tags icon"></i> Tags
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="branch-list" class="scrolling menu" >
|
|
||||||
|
|
||||||
<div class="item selected" data-url="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c">master</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div id="tag-list" class="scrolling menu" style="display: none">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="fitted item">
|
|
||||||
<div class="ui breadcrumb">
|
|
||||||
<a class="section" href="/xdrm-brackets/proxy.ftp.c/src/master">proxy.ftp.c</a>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="divider"> / </div>
|
|
||||||
|
|
||||||
|
|
||||||
<span class="section"><a href="/xdrm-brackets/proxy.ftp.c/src/master/dep">dep</a></span>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="divider"> / </div>
|
|
||||||
|
|
||||||
<span class="active section">client.c</span>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="right fitted item">
|
|
||||||
|
|
||||||
<div id="file-buttons" class="ui tiny blue buttons">
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="file-content" class="tab-size-8">
|
|
||||||
<h4 class="ui top attached header" id="repo-read-file">
|
|
||||||
|
|
||||||
<i class="file text outline icon ui left"></i>
|
|
||||||
<strong>client.c</strong> <span class="text grey normal">3.9KB</span>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="ui right file-actions">
|
|
||||||
<div class="ui buttons">
|
|
||||||
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/src/18a5e4338baaec92912eee057d26004b57b0b2a0/dep/client.c">Permalink</a>
|
|
||||||
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/commits/master/dep/client.c">History</a>
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/raw/master/dep/client.c">Raw</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="You must fork this repository before editing the file" data-position="bottom center" data-variation="tiny inverted"></i>
|
|
||||||
|
|
||||||
|
|
||||||
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="You must have write access to make or propose changes to this file" data-position="bottom center" data-variation="tiny inverted"></i>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</h4>
|
|
||||||
<div class="ui attached table segment">
|
|
||||||
<div id="" class="file-view code-view has-emoji">
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
|
|
||||||
<td class="lines-num"><span id="L1">1</span><span id="L2">2</span><span id="L3">3</span><span id="L4">4</span><span id="L5">5</span><span id="L6">6</span><span id="L7">7</span><span id="L8">8</span><span id="L9">9</span><span id="L10">10</span><span id="L11">11</span><span id="L12">12</span><span id="L13">13</span><span id="L14">14</span><span id="L15">15</span><span id="L16">16</span><span id="L17">17</span><span id="L18">18</span><span id="L19">19</span><span id="L20">20</span><span id="L21">21</span><span id="L22">22</span><span id="L23">23</span><span id="L24">24</span><span id="L25">25</span><span id="L26">26</span><span id="L27">27</span><span id="L28">28</span><span id="L29">29</span><span id="L30">30</span><span id="L31">31</span><span id="L32">32</span><span id="L33">33</span><span id="L34">34</span><span id="L35">35</span><span id="L36">36</span><span id="L37">37</span><span id="L38">38</span><span id="L39">39</span><span id="L40">40</span><span id="L41">41</span><span id="L42">42</span><span id="L43">43</span><span id="L44">44</span><span id="L45">45</span><span id="L46">46</span><span id="L47">47</span><span id="L48">48</span><span id="L49">49</span><span id="L50">50</span><span id="L51">51</span><span id="L52">52</span><span id="L53">53</span><span id="L54">54</span><span id="L55">55</span><span id="L56">56</span><span id="L57">57</span><span id="L58">58</span><span id="L59">59</span><span id="L60">60</span><span id="L61">61</span><span id="L62">62</span><span id="L63">63</span><span id="L64">64</span><span id="L65">65</span><span id="L66">66</span><span id="L67">67</span><span id="L68">68</span><span id="L69">69</span><span id="L70">70</span><span id="L71">71</span><span id="L72">72</span><span id="L73">73</span><span id="L74">74</span><span id="L75">75</span><span id="L76">76</span><span id="L77">77</span><span id="L78">78</span><span id="L79">79</span><span id="L80">80</span><span id="L81">81</span><span id="L82">82</span><span id="L83">83</span><span id="L84">84</span><span id="L85">85</span><span id="L86">86</span><span id="L87">87</span><span id="L88">88</span><span id="L89">89</span><span id="L90">90</span><span id="L91">91</span><span id="L92">92</span><span id="L93">93</span><span id="L94">94</span><span id="L95">95</span><span id="L96">96</span><span id="L97">97</span><span id="L98">98</span><span id="L99">99</span><span id="L100">100</span><span id="L101">101</span><span id="L102">102</span><span id="L103">103</span><span id="L104">104</span><span id="L105">105</span><span id="L106">106</span><span id="L107">107</span></td>
|
|
||||||
<td class="lines-code"><pre><code class="c"><ol class="linenums"><li class="L1" rel="L1">#include "client.h"</li>
|
|
||||||
<li class="L2" rel="L2"></li>
|
|
||||||
<li class="L3" rel="L3"></li>
|
|
||||||
<li class="L4" rel="L4">int CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){</li>
|
|
||||||
<li class="L5" rel="L5"> if( DEBUGMOD&HDR ) printf("====== CONNECT_CLIENT(%s, %s, %d) ======\n\n", serverHost, serverPort, *pSocket);</li>
|
|
||||||
<li class="L6" rel="L6"></li>
|
|
||||||
<li class="L7" rel="L7"> struct addrinfo hints; // contiendra le filtre/format</li>
|
|
||||||
<li class="L8" rel="L8"> struct addrinfo* addrinfo; // contiendra les infos</li>
|
|
||||||
<li class="L9" rel="L9"> int CONNECT; // file_desc(s)</li>
|
|
||||||
<li class="L10" rel="L10"> int GETADDRINFO; // contiendra l'erreur ou pas de getaddrinfo()</li>
|
|
||||||
<li class="L11" rel="L11"> char BUFFER[MAX_BUF_LEN]; // BUFFER de communication</li>
|
|
||||||
<li class="L12" rel="L12"></li>
|
|
||||||
<li class="L13" rel="L13"> /* [1] On définit le filtre/format</li>
|
|
||||||
<li class="L14" rel="L14"> =======================================================*/</li>
|
|
||||||
<li class="L15" rel="L15"> memset(&hints, 0, sizeof(struct addrinfo)); // on vide le filtre</li>
|
|
||||||
<li class="L16" rel="L16"> hints.ai_family = AF_UNSPEC; // Allow IPv4 ou IPv6</li>
|
|
||||||
<li class="L17" rel="L17"> hints.ai_socktype = SOCK_STREAM; // TCP (SOCK_DGRAM = UDP)</li>
|
|
||||||
<li class="L18" rel="L18"> hints.ai_flags = 0; // non spécifié</li>
|
|
||||||
<li class="L19" rel="L19"> hints.ai_protocol = 0; // non spécifié</li>
|
|
||||||
<li class="L20" rel="L20"></li>
|
|
||||||
<li class="L21" rel="L21"> if( DEBUGMOD&SCK ) printf("============HINTS===========\n");</li>
|
|
||||||
<li class="L22" rel="L22"> if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", hints.ai_flags ); // int</li>
|
|
||||||
<li class="L23" rel="L23"> if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", hints.ai_family ); // int</li>
|
|
||||||
<li class="L24" rel="L24"> if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", hints.ai_socktype ); // int</li>
|
|
||||||
<li class="L25" rel="L25"> if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", hints.ai_protocol ); // int</li>
|
|
||||||
<li class="L26" rel="L26"> if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", hints.ai_addrlen ); // int</li>
|
|
||||||
<li class="L27" rel="L27"> if( DEBUGMOD&SCK ) printf("\n");</li>
|
|
||||||
<li class="L28" rel="L28"></li>
|
|
||||||
<li class="L29" rel="L29"></li>
|
|
||||||
<li class="L30" rel="L30"> /* [2] On récupère les infos</li>
|
|
||||||
<li class="L31" rel="L31"> =======================================================*/</li>
|
|
||||||
<li class="L32" rel="L32"> GETADDRINFO = getaddrinfo(serverHost, serverPort, &hints, &addrinfo);</li>
|
|
||||||
<li class="L33" rel="L33"></li>
|
|
||||||
<li class="L34" rel="L34"> // si erreur</li>
|
|
||||||
<li class="L35" rel="L35"> if( GETADDRINFO < 0 ) return -1;</li>
|
|
||||||
<li class="L36" rel="L36"></li>
|
|
||||||
<li class="L37" rel="L37"> if( DEBUGMOD&SCK ) printf("=============RES============\n");</li>
|
|
||||||
<li class="L38" rel="L38"> if( DEBUGMOD&SCK ) printf( "AI_FLAGS = %d\n", addrinfo->ai_flags ); // int</li>
|
|
||||||
<li class="L39" rel="L39"> if( DEBUGMOD&SCK ) printf( "AI_FAMILY = %d\n", addrinfo->ai_family ); // int</li>
|
|
||||||
<li class="L40" rel="L40"> if( DEBUGMOD&SCK ) printf( "AI_SOCKTYPE = %d\n", addrinfo->ai_socktype ); // int</li>
|
|
||||||
<li class="L41" rel="L41"> if( DEBUGMOD&SCK ) printf( "AI_PROTOCOL = %d\n", addrinfo->ai_protocol ); // int</li>
|
|
||||||
<li class="L42" rel="L42"> if( DEBUGMOD&SCK ) printf( "AI_ADDRLEN = %d\n", addrinfo->ai_addrlen ); // int</li>
|
|
||||||
<li class="L43" rel="L43"> if( DEBUGMOD&SCK ) printf("\n");</li>
|
|
||||||
<li class="L44" rel="L44"></li>
|
|
||||||
<li class="L45" rel="L45"> /* [3] Création de la socket</li>
|
|
||||||
<li class="L46" rel="L46"> =======================================================*/</li>
|
|
||||||
<li class="L47" rel="L47"> *pSocket = socket(addrinfo->ai_family, addrinfo->ai_socktype, 0);</li>
|
|
||||||
<li class="L48" rel="L48"></li>
|
|
||||||
<li class="L49" rel="L49"> if( DEBUGMOD&SCK ) printf("SOCKET = %d\n", *pSocket);</li>
|
|
||||||
<li class="L50" rel="L50"></li>
|
|
||||||
<li class="L51" rel="L51"> // si erreur</li>
|
|
||||||
<li class="L52" rel="L52"> if( *pSocket == -1 ) return -1;</li>
|
|
||||||
<li class="L53" rel="L53"></li>
|
|
||||||
<li class="L54" rel="L54"></li>
|
|
||||||
<li class="L55" rel="L55"> /* [4] On établit la connection</li>
|
|
||||||
<li class="L56" rel="L56"> =======================================================*/</li>
|
|
||||||
<li class="L57" rel="L57"> CONNECT = connect(</li>
|
|
||||||
<li class="L58" rel="L58"> *pSocket,</li>
|
|
||||||
<li class="L59" rel="L59"> addrinfo->ai_addr,</li>
|
|
||||||
<li class="L60" rel="L60"> addrinfo->ai_addrlen</li>
|
|
||||||
<li class="L61" rel="L61"> );</li>
|
|
||||||
<li class="L62" rel="L62"></li>
|
|
||||||
<li class="L63" rel="L63"> if( DEBUGMOD&SCK ) printf("CONNECT = %d\n", CONNECT);</li>
|
|
||||||
<li class="L64" rel="L64"></li>
|
|
||||||
<li class="L65" rel="L65"> // si erreur</li>
|
|
||||||
<li class="L66" rel="L66"> if( CONNECT == -1 ) return -1;</li>
|
|
||||||
<li class="L67" rel="L67"></li>
|
|
||||||
<li class="L68" rel="L68"> // on a plus besoin des infos de l'adresse</li>
|
|
||||||
<li class="L69" rel="L69"> freeaddrinfo(addrinfo);</li>
|
|
||||||
<li class="L70" rel="L70"></li>
|
|
||||||
<li class="L71" rel="L71"></li>
|
|
||||||
<li class="L72" rel="L72"> /* [5] On retourne la SOCKET</li>
|
|
||||||
<li class="L73" rel="L73"> =======================================================*/</li>
|
|
||||||
<li class="L74" rel="L74"> return *pSocket;</li>
|
|
||||||
<li class="L75" rel="L75">}</li>
|
|
||||||
<li class="L76" rel="L76"></li>
|
|
||||||
<li class="L77" rel="L77"></li>
|
|
||||||
<li class="L78" rel="L78"></li>
|
|
||||||
<li class="L79" rel="L79"></li>
|
|
||||||
<li class="L80" rel="L80"></li>
|
|
||||||
<li class="L81" rel="L81"></li>
|
|
||||||
<li class="L82" rel="L82">int CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer){</li>
|
|
||||||
<li class="L83" rel="L83"> if( DEBUGMOD&HDR ) printf("====== CLIENT_SEND(%d, %s, %s) ======\n\n", *pSocket, pRequest, *pAnswer);</li>
|
|
||||||
<li class="L84" rel="L84"> char BUFFER[MAX_BUF_LEN] = {0};</li>
|
|
||||||
<li class="L85" rel="L85"></li>
|
|
||||||
<li class="L86" rel="L86"> /* [1] On écrit sur la socket</li>
|
|
||||||
<li class="L87" rel="L87"> =======================================================*/</li>
|
|
||||||
<li class="L88" rel="L88"> int nbSend = swrite(pSocket, pRequest);</li>
|
|
||||||
<li class="L89" rel="L89"></li>
|
|
||||||
<li class="L90" rel="L90"> if( DEBUGMOD&BUF ) printf("nbSend: %d\n", nbSend);</li>
|
|
||||||
<li class="L91" rel="L91"> if( DEBUGMOD&BUF ) printf("Message: %s\n", pRequest);</li>
|
|
||||||
<li class="L92" rel="L92"></li>
|
|
||||||
<li class="L93" rel="L93"> // si pas tout envoyé</li>
|
|
||||||
<li class="L94" rel="L94"> if( strlen(pRequest) != nbSend ) return -1;</li>
|
|
||||||
<li class="L95" rel="L95"></li>
|
|
||||||
<li class="L96" rel="L96"> /* [2] On attends et lit la réponse</li>
|
|
||||||
<li class="L97" rel="L97"> =======================================================*/</li>
|
|
||||||
<li class="L98" rel="L98"> int nbRecup = WAIT_SOCKET_UPDATE(pSocket, BUFFER);</li>
|
|
||||||
<li class="L99" rel="L99"></li>
|
|
||||||
<li class="L100" rel="L100"> /* [3] On retourne la réponse par référence</li>
|
|
||||||
<li class="L101" rel="L101"> =======================================================*/</li>
|
|
||||||
<li class="L102" rel="L102"> *pAnswer = malloc( MAX_BUF_LEN );</li>
|
|
||||||
<li class="L103" rel="L103"> strcpy(*pAnswer, BUFFER);</li>
|
|
||||||
<li class="L104" rel="L104"></li>
|
|
||||||
<li class="L105" rel="L105"> if( DEBUGMOD&BUF ) printf("nbReceived: %d\n", nbRecup);</li>
|
|
||||||
<li class="L106" rel="L106"> if( DEBUGMOD&BUF ) printf("Message: %s\n", *pAnswer);</li>
|
|
||||||
<li class="L107" rel="L107">}</li>
|
|
||||||
</ol></code></pre></td>
|
|
||||||
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function submitDeleteForm() {
|
|
||||||
var message = prompt("delete_confirm_message\n\ndelete_commit_summary", "Delete ''");
|
|
||||||
if (message != null) {
|
|
||||||
$("#delete-message").val(message);
|
|
||||||
$("#delete-file-form").submit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<footer>
|
|
||||||
<div class="ui container">
|
|
||||||
<div class="ui left">
|
|
||||||
© 2017 Gogs Version: 0.10.10.0308 Page: <strong>52ms</strong> Template: <strong>2ms</strong>
|
|
||||||
</div>
|
|
||||||
<div class="ui right links">
|
|
||||||
|
|
||||||
<div class="ui language bottom floating slide up dropdown link item">
|
|
||||||
<i class="world icon"></i>
|
|
||||||
<div class="text">English</div>
|
|
||||||
<div class="menu">
|
|
||||||
|
|
||||||
<a class="item active selected" href="#">English</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-CN">简体中文</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-HK">繁體中文(香港)</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-TW">繁體中文(台湾)</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=de-DE">Deutsch</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=fr-FR">Français</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=nl-NL">Nederlands</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=lv-LV">Latviešu</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=ru-RU">Русский</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=ja-JP">日本語</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=es-ES">Español</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=pt-BR">Português do Brasil</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=pl-PL">Polski</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=bg-BG">български</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=it-IT">Italiano</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=fi-FI">Suomalainen</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=tr-TR">Türkçe</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=cs-CZ">čeština</a>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="/assets/librejs/librejs.html" style="display:none" data-jslicense="1">Javascript Licenses</a>
|
|
||||||
<a target="_blank" href="https://gogs.io">Website</a>
|
|
||||||
<span class="version">Go1.8</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="/plugins/highlight-9.6.0/github.css">
|
|
||||||
<script src="/plugins/highlight-9.6.0/highlight.pack.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script src="/js/libs/emojify-1.1.0.min.js"></script>
|
|
||||||
<script src="/js/libs/clipboard-1.5.9.min.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -1,433 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head data-suburl="">
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
|
||||||
|
|
||||||
<meta name="author" content="xdrm-brackets" />
|
|
||||||
<meta name="description" content="proxy.ftp.c" />
|
|
||||||
<meta name="keywords" content="go, git, self-hosted, gogs">
|
|
||||||
|
|
||||||
<meta name="referrer" content="no-referrer" />
|
|
||||||
<meta name="_csrf" content="sS0pasZdHndRhsO38JoAUyyuIWs6MTQ5MDcxOTc2NzE3OTU4NzUxOA==" />
|
|
||||||
<meta name="_suburl" content="" />
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<meta property="og:url" content="https://git.xdrm.io/xdrm-brackets/proxy.ftp.c" />
|
|
||||||
<meta property="og:type" content="object" />
|
|
||||||
<meta property="og:title" content="xdrm-brackets/proxy.ftp.c">
|
|
||||||
<meta property="og:description" content="">
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="shortcut icon" href="/img/favicon.png" />
|
|
||||||
|
|
||||||
<script src="/js/jquery-1.11.3.min.js"></script>
|
|
||||||
<script src="/js/libs/jquery.are-you-sure.js"></script>
|
|
||||||
<link rel="stylesheet" href="/assets/font-awesome-4.6.3/css/font-awesome.min.css">
|
|
||||||
<link rel="stylesheet" href="/assets/octicons-4.3.0/octicons.min.css">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="/css/semantic-2.2.7.min.css">
|
|
||||||
<link rel="stylesheet" href="/css/gogs.css?v=73519fd9811805bce6fc4aa2d24bb413">
|
|
||||||
|
|
||||||
|
|
||||||
<script src="/js/semantic-2.2.7.min.js"></script>
|
|
||||||
<script src="/js/gogs.js?v=73519fd9811805bce6fc4aa2d24bb413"></script>
|
|
||||||
|
|
||||||
<title>xdrm-brackets/proxy.ftp.c - xdrm-brackets' git server</title>
|
|
||||||
|
|
||||||
<meta name="theme-color" content="#ff5343">
|
|
||||||
|
|
||||||
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="full height">
|
|
||||||
<noscript>Please enable JavaScript in your browser!</noscript>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="following bar light">
|
|
||||||
<div class="ui container">
|
|
||||||
<div class="ui grid">
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui top secondary menu">
|
|
||||||
<a class="item brand" href="/">
|
|
||||||
<img class="ui mini image" src="/img/favicon.png">
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
<a class="item" href="/">Home</a>
|
|
||||||
|
|
||||||
|
|
||||||
<a class="item" href="/explore/repos">Explore</a>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a class="item" target="_blank" href="https://gogs.io/docs" rel="noreferrer">Help</a>
|
|
||||||
<div class="right menu">
|
|
||||||
|
|
||||||
<a class="item" href="/user/sign_up">
|
|
||||||
<i class="octicon octicon-person"></i> Register
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class="item" href="/user/login?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.h">
|
|
||||||
<i class="octicon octicon-sign-in"></i> Sign In
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="repository file list">
|
|
||||||
<div class="header-wrapper">
|
|
||||||
|
|
||||||
<div class="ui container">
|
|
||||||
<div class="ui vertically padded grid head">
|
|
||||||
<div class="column">
|
|
||||||
<div class="ui header">
|
|
||||||
<div class="ui huge breadcrumb">
|
|
||||||
<i class="mega-octicon octicon-repo"></i>
|
|
||||||
<a href="/xdrm-brackets">xdrm-brackets</a>
|
|
||||||
<div class="divider"> / </div>
|
|
||||||
<a href="/xdrm-brackets/proxy.ftp.c">proxy.ftp.c</a>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui right">
|
|
||||||
<div class="ui labeled button" tabindex="0">
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/watch?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.h">
|
|
||||||
<i class="icon fa-eye-slash"></i>Watch
|
|
||||||
</a>
|
|
||||||
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/watchers">
|
|
||||||
1
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="ui labeled button" tabindex="0">
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/star?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.h">
|
|
||||||
<i class="icon fa-star-o"></i>Star
|
|
||||||
</a>
|
|
||||||
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/stars">
|
|
||||||
0
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui labeled button" tabindex="0">
|
|
||||||
<a class="ui button " href="/repo/fork/49">
|
|
||||||
<i class="octicon octicon-repo-forked"></i>Fork
|
|
||||||
</a>
|
|
||||||
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/forks">
|
|
||||||
0
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="ui tabs container">
|
|
||||||
<div class="ui tabular menu navbar">
|
|
||||||
<a class="active item" href="/xdrm-brackets/proxy.ftp.c">
|
|
||||||
<i class="octicon octicon-file-text"></i> Files
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/issues">
|
|
||||||
<i class="octicon octicon-issue-opened"></i> Issues <span class="ui gray small label">0</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/pulls">
|
|
||||||
<i class="octicon octicon-git-pull-request"></i> Pull Requests <span class="ui gray small label">0</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/commits/master">
|
|
||||||
<i class="octicon octicon-history"></i> Commits <span class="ui blue small label">23</span>
|
|
||||||
</a>
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/releases">
|
|
||||||
<i class="octicon octicon-tag"></i> Releases <span class="ui gray small label">0</span>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/wiki">
|
|
||||||
<i class="octicon octicon-book"></i> Wiki
|
|
||||||
</a>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ui tabs divider"></div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="ui container">
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p id="repo-desc">
|
|
||||||
<span class="no-description text-italic">No Description</span>
|
|
||||||
<a class="link" href=""></a>
|
|
||||||
</p>
|
|
||||||
<div class="ui secondary menu">
|
|
||||||
|
|
||||||
<div class="fitted item choose reference">
|
|
||||||
<div class="ui floating filter dropdown" data-no-results="No results found.">
|
|
||||||
<div class="ui basic small button">
|
|
||||||
<span class="text">
|
|
||||||
<i class="octicon octicon-git-branch"></i>
|
|
||||||
Branch:
|
|
||||||
<strong>master</strong>
|
|
||||||
</span>
|
|
||||||
<i class="dropdown icon"></i>
|
|
||||||
</div>
|
|
||||||
<div class="menu">
|
|
||||||
<div class="ui icon search input">
|
|
||||||
<i class="filter icon"></i>
|
|
||||||
<input name="search" placeholder="Filter branch or tag...">
|
|
||||||
</div>
|
|
||||||
<div class="header">
|
|
||||||
<div class="ui grid">
|
|
||||||
<div class="two column row">
|
|
||||||
<a class="reference column" href="#" data-target="#branch-list">
|
|
||||||
<span class="text black">
|
|
||||||
<i class="octicon octicon-git-branch"></i> Branches
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
<a class="reference column" href="#" data-target="#tag-list">
|
|
||||||
<span class="text ">
|
|
||||||
<i class="reference tags icon"></i> Tags
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="branch-list" class="scrolling menu" >
|
|
||||||
|
|
||||||
<div class="item selected" data-url="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h">master</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div id="tag-list" class="scrolling menu" style="display: none">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="fitted item">
|
|
||||||
<div class="ui breadcrumb">
|
|
||||||
<a class="section" href="/xdrm-brackets/proxy.ftp.c/src/master">proxy.ftp.c</a>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="divider"> / </div>
|
|
||||||
|
|
||||||
|
|
||||||
<span class="section"><a href="/xdrm-brackets/proxy.ftp.c/src/master/dep">dep</a></span>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="divider"> / </div>
|
|
||||||
|
|
||||||
<span class="active section">client.h</span>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="right fitted item">
|
|
||||||
|
|
||||||
<div id="file-buttons" class="ui tiny blue buttons">
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="file-content" class="tab-size-8">
|
|
||||||
<h4 class="ui top attached header" id="repo-read-file">
|
|
||||||
|
|
||||||
<i class="file text outline icon ui left"></i>
|
|
||||||
<strong>client.h</strong> <span class="text grey normal">1.0KB</span>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="ui right file-actions">
|
|
||||||
<div class="ui buttons">
|
|
||||||
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/src/18a5e4338baaec92912eee057d26004b57b0b2a0/dep/client.h">Permalink</a>
|
|
||||||
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/commits/master/dep/client.h">History</a>
|
|
||||||
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/raw/master/dep/client.h">Raw</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="You must fork this repository before editing the file" data-position="bottom center" data-variation="tiny inverted"></i>
|
|
||||||
|
|
||||||
|
|
||||||
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="You must have write access to make or propose changes to this file" data-position="bottom center" data-variation="tiny inverted"></i>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</h4>
|
|
||||||
<div class="ui attached table segment">
|
|
||||||
<div id="" class="file-view code-view has-emoji">
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
|
|
||||||
<td class="lines-num"><span id="L1">1</span><span id="L2">2</span><span id="L3">3</span><span id="L4">4</span><span id="L5">5</span><span id="L6">6</span><span id="L7">7</span><span id="L8">8</span><span id="L9">9</span><span id="L10">10</span><span id="L11">11</span><span id="L12">12</span><span id="L13">13</span><span id="L14">14</span><span id="L15">15</span><span id="L16">16</span><span id="L17">17</span><span id="L18">18</span><span id="L19">19</span><span id="L20">20</span><span id="L21">21</span><span id="L22">22</span><span id="L23">23</span><span id="L24">24</span><span id="L25">25</span><span id="L26">26</span><span id="L27">27</span><span id="L28">28</span><span id="L29">29</span><span id="L30">30</span><span id="L31">31</span><span id="L32">32</span><span id="L33">33</span><span id="L34">34</span><span id="L35">35</span><span id="L36">36</span><span id="L37">37</span><span id="L38">38</span><span id="L39">39</span><span id="L40">40</span></td>
|
|
||||||
<td class="lines-code"><pre><code class=""><ol class="linenums"><li class="L1" rel="L1">/* Envoi d'une requête à un serveur et réception de la réponse</li>
|
|
||||||
<li class="L2" rel="L2">*</li>
|
|
||||||
<li class="L3" rel="L3">* @serverHost<char*> Nom de l'hôte distant (server)</li>
|
|
||||||
<li class="L4" rel="L4">* @serverPort<char*> Numéro du port distant (server)</li>
|
|
||||||
<li class="L5" rel="L5">* @pSocket<int*> Pointeur sur la requête à créer</li>
|
|
||||||
<li class="L6" rel="L6">*</li>
|
|
||||||
<li class="L7" rel="L7">*</li>
|
|
||||||
<li class="L8" rel="L8">* @return error<int> retourne -1 en cas d'erreur, sinon la SOCKET</li>
|
|
||||||
<li class="L9" rel="L9">*</li>
|
|
||||||
<li class="L10" rel="L10">*</li>
|
|
||||||
<li class="L11" rel="L11">* </li>
|
|
||||||
<li class="L12" rel="L12">* @history</li>
|
|
||||||
<li class="L13" rel="L13">* [1] On définit le filtre/format</li>
|
|
||||||
<li class="L14" rel="L14">* [2] On récupère les infos</li>
|
|
||||||
<li class="L15" rel="L15">* [3] Création de la socket</li>
|
|
||||||
<li class="L16" rel="L16">* [4] On établit la connection</li>
|
|
||||||
<li class="L17" rel="L17">* [5] On retourne la SOCKET</li>
|
|
||||||
<li class="L18" rel="L18">* </li>
|
|
||||||
<li class="L19" rel="L19">*/</li>
|
|
||||||
<li class="L20" rel="L20">int CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket);</li>
|
|
||||||
<li class="L21" rel="L21"></li>
|
|
||||||
<li class="L22" rel="L22"></li>
|
|
||||||
<li class="L23" rel="L23"></li>
|
|
||||||
<li class="L24" rel="L24">/* Envoi d'une requête vers une SOCKET et récupère la réponse</li>
|
|
||||||
<li class="L25" rel="L25">*</li>
|
|
||||||
<li class="L26" rel="L26">* @pSocket<int*> Pointeur sur la SOCKET en question</li>
|
|
||||||
<li class="L27" rel="L27">* @pRequest<char*> Requête à lui envoyer (swrite)</li>
|
|
||||||
<li class="L28" rel="L28">* @pAnswer<char**> Réponse qui se lira après la requête (sread)</li>
|
|
||||||
<li class="L29" rel="L29">*</li>
|
|
||||||
<li class="L30" rel="L30">* @return error<int> Retourne -1 en cas d'erreur</li>
|
|
||||||
<li class="L31" rel="L31">*</li>
|
|
||||||
<li class="L32" rel="L32">*</li>
|
|
||||||
<li class="L33" rel="L33">*</li>
|
|
||||||
<li class="L34" rel="L34">* @history</li>
|
|
||||||
<li class="L35" rel="L35">* [1] On écrit sur la socket</li>
|
|
||||||
<li class="L36" rel="L36">* [2] On attends et lit la réponse</li>
|
|
||||||
<li class="L37" rel="L37">* [3] On retourne la réponse par référence</li>
|
|
||||||
<li class="L38" rel="L38">* </li>
|
|
||||||
<li class="L39" rel="L39">*/</li>
|
|
||||||
<li class="L40" rel="L40">int CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer);</li>
|
|
||||||
</ol></code></pre></td>
|
|
||||||
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function submitDeleteForm() {
|
|
||||||
var message = prompt("delete_confirm_message\n\ndelete_commit_summary", "Delete ''");
|
|
||||||
if (message != null) {
|
|
||||||
$("#delete-message").val(message);
|
|
||||||
$("#delete-file-form").submit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<footer>
|
|
||||||
<div class="ui container">
|
|
||||||
<div class="ui left">
|
|
||||||
© 2017 Gogs Version: 0.10.10.0308 Page: <strong>53ms</strong> Template: <strong>1ms</strong>
|
|
||||||
</div>
|
|
||||||
<div class="ui right links">
|
|
||||||
|
|
||||||
<div class="ui language bottom floating slide up dropdown link item">
|
|
||||||
<i class="world icon"></i>
|
|
||||||
<div class="text">English</div>
|
|
||||||
<div class="menu">
|
|
||||||
|
|
||||||
<a class="item active selected" href="#">English</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=zh-CN">简体中文</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=zh-HK">繁體中文(香港)</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=zh-TW">繁體中文(台湾)</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=de-DE">Deutsch</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=fr-FR">Français</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=nl-NL">Nederlands</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=lv-LV">Latviešu</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=ru-RU">Русский</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=ja-JP">日本語</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=es-ES">Español</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=pt-BR">Português do Brasil</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=pl-PL">Polski</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=bg-BG">български</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=it-IT">Italiano</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=fi-FI">Suomalainen</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=tr-TR">Türkçe</a>
|
|
||||||
|
|
||||||
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.h?lang=cs-CZ">čeština</a>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="/assets/librejs/librejs.html" style="display:none" data-jslicense="1">Javascript Licenses</a>
|
|
||||||
<a target="_blank" href="https://gogs.io">Website</a>
|
|
||||||
<span class="version">Go1.8</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="/plugins/highlight-9.6.0/github.css">
|
|
||||||
<script src="/plugins/highlight-9.6.0/highlight.pack.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script src="/js/libs/emojify-1.1.0.min.js"></script>
|
|
||||||
<script src="/js/libs/clipboard-1.5.9.min.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -1,169 +0,0 @@
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
void splitFtpRequest(char* pRequest, char* pCommand, char* pContent){
|
|
||||||
/* [1] Vérification du format
|
|
||||||
===========================================*/
|
|
||||||
int firstSpaceIndex = indexOf(pRequest, ' ');
|
|
||||||
|
|
||||||
if( firstSpaceIndex != 3 && firstSpaceIndex != 4){ // contient aucun espace en position 3 ou 4, on quitte
|
|
||||||
strcpy(pCommand, "ERROR");
|
|
||||||
strcpy(pContent, "");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* [2] Séparation des 2 parties
|
|
||||||
===========================================*/
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for( i = 0 ; i < strlen(pRequest) && pRequest[i] != '\0' ; i++ ){
|
|
||||||
|
|
||||||
if( i < firstSpaceIndex ) // première partie (pCommand)
|
|
||||||
strcat( pCommand, (char[2]){(char) pRequest[i], '\0'});
|
|
||||||
if( i > firstSpaceIndex ) // seconde partie (pContent)
|
|
||||||
strcat( pContent, (char[2]){(char) pRequest[i], '\0'});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText){
|
|
||||||
/* [1] Vérification du format
|
|
||||||
===========================================*/
|
|
||||||
int codeLength = 3; // taille du code
|
|
||||||
|
|
||||||
/* [2] Séparation des 2 parties
|
|
||||||
===========================================*/
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for( i = 0 ; i < strlen(pAnswer) && pAnswer[i] != '\0' ; i++ ){
|
|
||||||
|
|
||||||
if( i < codeLength ) // première partie (ftpCode)
|
|
||||||
strcat(ftpCode, (char[2]){(char)pAnswer[i], '\0' });
|
|
||||||
if( i > codeLength ) // seconde partie (ftpText)
|
|
||||||
strcat(ftpText, (char[2]){(char)pAnswer[i], '\0' });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int indexOf(char* haystack, char needle){
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for( i = 0 ; i < strlen(haystack) && haystack[i] != '\0' ; i++ )
|
|
||||||
if( haystack[i] == needle ) // si on trouve le caractère
|
|
||||||
return i;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int swrite(int* pSocket, char* pBuffer){
|
|
||||||
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
|
||||||
if( strlen(pBuffer) == 0 ) return 0; // si on a rien à écrire, on n'écrit rien :p
|
|
||||||
|
|
||||||
|
|
||||||
/* 1. On écrit sur la SOCKET */
|
|
||||||
if( DEBUGMOD&BUF ) printf("SENDLEN_1: %lu\n", strlen(pBuffer));
|
|
||||||
int nbSent = write(*pSocket, pBuffer, strlen(pBuffer));
|
|
||||||
if( DEBUGMOD&BUF ) printf("SENDLEN_2: %d\n", nbSent);
|
|
||||||
|
|
||||||
/* 2. Si on est déconnecté, on retourne une erreur */
|
|
||||||
if( nbSent <= 0 ){
|
|
||||||
if( DEBUGMOD&BUF ) printf("NOTHING TO SEND\n");
|
|
||||||
return -1; // on retourne une erreur
|
|
||||||
}
|
|
||||||
|
|
||||||
if( DEBUGMOD&RVL ) printf("SEND_1\n");
|
|
||||||
if( DEBUGMOD&RVL ) revealString(pBuffer);
|
|
||||||
if( DEBUGMOD&RVL ) printf("SEND_2\n");
|
|
||||||
|
|
||||||
|
|
||||||
/* 3. On retourne le nombre de <char> envoyés */
|
|
||||||
return nbSent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int sread(int* pSocket, char* pBuffer){
|
|
||||||
if( *pSocket == -1 ) return -1; // si SOCKET fermée, on retourne une erreur
|
|
||||||
|
|
||||||
|
|
||||||
/* 1. On vide le buffer avant de lire */
|
|
||||||
memset(pBuffer, '\0', MAX_BUF_LEN);
|
|
||||||
if( DEBUGMOD&BUF ) printf("READLEN_1: %lu\n", strlen(pBuffer));
|
|
||||||
|
|
||||||
/* 2. On lit la SOCKET */
|
|
||||||
int nbRead = read(*pSocket, pBuffer, MAX_BUF_LEN);
|
|
||||||
if( DEBUGMOD&BUF ) printf("READLEN_3: %d\n", nbRead);
|
|
||||||
|
|
||||||
|
|
||||||
/* 3. Si on est déconnecté, on retourne une erreur */
|
|
||||||
if( nbRead <= 0 ){
|
|
||||||
if( DEBUGMOD&BUF ) printf("NOTHING TO READ\n");
|
|
||||||
return -1; // on retourne une erreur
|
|
||||||
}
|
|
||||||
|
|
||||||
if( DEBUGMOD&RVL ) printf("READ_1\n");
|
|
||||||
if( DEBUGMOD&RVL ) revealString(pBuffer);
|
|
||||||
if( DEBUGMOD&RVL ) printf("READ_2\n");
|
|
||||||
|
|
||||||
/* 4. On retourne le nombre de caractères lus */
|
|
||||||
return nbRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec){
|
|
||||||
/* 1. On créé la structure contenant le timeout */
|
|
||||||
struct timeval timeout;
|
|
||||||
timeout.tv_sec = pSec;
|
|
||||||
timeout.tv_usec = pUSec;
|
|
||||||
|
|
||||||
setsockopt(*pSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(struct timeval));
|
|
||||||
|
|
||||||
if( DEBUGMOD&SCK ) printf("Set socket(%d) timeout to %lus\n", *pSocket, (long unsigned) timeout.tv_sec );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xPrint(char* pPattern, char* pBuffer){
|
|
||||||
char tmpBuffer[MAX_BUF_LEN];
|
|
||||||
strcpy(tmpBuffer, pBuffer);
|
|
||||||
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// on supprimes les retours à la ligne de la fin
|
|
||||||
for( i = strlen(tmpBuffer)-1 ; i >= 0 && tmpBuffer[i] != '\0' ; i-- )
|
|
||||||
if( tmpBuffer[i] == '\n' || tmpBuffer[i] == '\r' ) // si c'est un retour chariot
|
|
||||||
tmpBuffer[i] = '\0'; // on efface
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
printf(pPattern, pBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void revealString(char* pString){
|
|
||||||
/* 1. On créé une copie de @pString */
|
|
||||||
char revealedString[MAX_BUF_LEN] = {0};
|
|
||||||
|
|
||||||
/* 2. On rend visible tous les caractères "invisibles" */
|
|
||||||
int i;
|
|
||||||
for( i = 0 ; i < strlen(pString) && pString[i] != '\0' ; i++ ){
|
|
||||||
if( pString[i] == '\r' ){ revealedString[strlen(revealedString)] = '\\'; revealedString[strlen(revealedString)] = 'r'; }
|
|
||||||
else if( pString[i] == '\n' ){ revealedString[strlen(revealedString)] = '\\'; revealedString[strlen(revealedString)] = 'n'; }
|
|
||||||
else revealedString[strlen(revealedString)] = pString[i];
|
|
||||||
|
|
||||||
revealedString[strlen(revealedString)] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 3. On affiche la chaîne explicite */
|
|
||||||
if( DEBUGMOD&RVL ) printf("[[%s]]\n", revealedString);
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
/* Découpe la requête FTP en 2 parties
|
|
||||||
*
|
|
||||||
* @pRequest<char*> La requête en question
|
|
||||||
*
|
|
||||||
* @pCommand<char*> Remplissage: commande (1ère partie)
|
|
||||||
* @pContant<char*> Remplissage: contenu (2ème partie)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void splitFtpRequest(char* pRequest, char* pCommand, char* pContent);
|
|
||||||
|
|
||||||
/* Découpe la réponse FTP en 2 parties
|
|
||||||
*
|
|
||||||
* @pAnswer<char*> La réponse en question
|
|
||||||
*
|
|
||||||
* @ftpCode<char*> Remplissage: code FTP (1ère partie)
|
|
||||||
* @ftpText<char*> Remplissage: text associé (2ème partie)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void splitFtpResponse(char* pAnswer, char* ftpCode, char* ftpText);
|
|
||||||
|
|
||||||
|
|
||||||
/* Retourne le rang d'un caractère dans une string
|
|
||||||
*
|
|
||||||
* @haystack<char*> La chaîne dans laquelle rechercher
|
|
||||||
* @needle<char> Le caractère recherché
|
|
||||||
*
|
|
||||||
* @return position<int> Retourne l'index de @needle dans @haystack ou -1 si ne trouve pas
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int indexOf(char* haystack, char needle);
|
|
||||||
|
|
||||||
void setSocketTimeout(int* pSocket, const int pSec, const int pUSec);
|
|
||||||
|
|
||||||
|
|
||||||
/* read/write socket */
|
|
||||||
int swrite(int* pSocket, char* pBuffer);
|
|
||||||
int sread(int* pSocket, char* pBuffer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Affiche une string en supprimant les retours à la ligne de fin de chaînes
|
|
||||||
*
|
|
||||||
* @pPattern<char*> Schéma du print (1er arg)
|
|
||||||
* @pBuffer<char*> Buffer en question
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void xPrint(char* pPattern, char* pBuffer);
|
|
||||||
|
|
||||||
|
|
||||||
/* Révèle les caractères spéciaux d'une string
|
|
||||||
*
|
|
||||||
* @pString<char*> La string à révéler
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @print explicitString<char*> On affiche la chaîne explicité
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void revealString(char* pString);
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef _LIB_HEADER_H_
|
||||||
|
#define _LIB_HEADER_H_
|
||||||
|
|
||||||
|
|
||||||
|
/* global */
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/* sys */
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* socket */
|
||||||
|
#include <unistd.h> // close
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h> // getaddrinfo, getnameinfo
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
/* vars */
|
||||||
|
#define SRV_HOST "localhost"
|
||||||
|
#define SRV_PORT 4444
|
||||||
|
|
||||||
|
#define MAX_BUF_LEN 512
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include "serializer.h"
|
||||||
|
|
||||||
|
|
||||||
|
int parse_plane_request(const char* pIn, struct plane_request* pOut){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( strlen(pIn)*sizeof(char) != sizeof(struct plane_request) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Parse buffer */
|
||||||
|
memcpy(pOut, pIn, (size_t) sizeof(struct plane_request));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int parse_viewterm_request(const char* pIn, struct vterm_request* pOut){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( strlen(pIn)*sizeof(char) != sizeof(struct vterm_request) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Parse buffer */
|
||||||
|
memcpy(pOut, pIn, sizeof(struct vterm_request));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int parse_ctrlterm_request(const char* pIn, struct cterm_request* pOut){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( strlen(pIn)*sizeof(char) != sizeof(struct cterm_request) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Parse buffer */
|
||||||
|
memcpy(pOut, pIn, sizeof(struct cterm_request));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int serialize_term_response(const struct term_response* pIn, char* pOut, const size_t pSize){
|
||||||
|
|
||||||
|
/* 1. Check buffer length */
|
||||||
|
if( sizeof(struct term_response) > pSize*sizeof(char) )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* 2. Serialize response into buffer */
|
||||||
|
memcpy(pOut, pIn, sizeof(struct term_response));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
#ifndef _LIB_NETWORK_FORMAT_SERIALIZER_H_
|
||||||
|
#define _LIB_NETWORK_FORMAT_SERIALIZER_H_
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "../../../plane.h"
|
||||||
|
|
||||||
|
struct plane_request{ // Plane Request
|
||||||
|
struct coord co;
|
||||||
|
struct control ct;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct vterm_request{ // ViewTerminal Request
|
||||||
|
char flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct term_response{ // Terminal-s Response
|
||||||
|
char flags;
|
||||||
|
struct coord co;
|
||||||
|
struct control ct;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cterm_request{ // ControlTerminal Request
|
||||||
|
char flags;
|
||||||
|
int z;
|
||||||
|
struct control ct;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Parse a plane request ('char*' to 'struct plane_request')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to destination struct)
|
||||||
|
* [2] Parse buffer to struct
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int parse_plane_request(const char* pIn, struct plane_request* pOut);
|
||||||
|
|
||||||
|
/* Parse a viewTerminal request ('char*' to 'struct vt_request')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to destination struct)
|
||||||
|
* [2] Parse buffer to struct
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int parse_viewterm_request(const char* pIn, struct vterm_request* pOut);
|
||||||
|
|
||||||
|
/* Parse a ctrlTerminal request ('char*' to 'struct ct_request')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to destination struct)
|
||||||
|
* [2] Parse buffer to struct
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int parse_ctrlterm_request(const char* pIn, struct cterm_request* pOut);
|
||||||
|
|
||||||
|
/* Serialize a Terminal response ('struct t_response' to 'char*')
|
||||||
|
*
|
||||||
|
* @history
|
||||||
|
* [1] Check if buffer have correct size (according to input struct)
|
||||||
|
* [2] Serialize struct into buffer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int serialize_term_response(const struct term_response* pIn, char* pOut, const size_t pSize);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1 @@
|
||||||
|
#include "client.h"
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef _LIB_NETWORK_TCP_CLIENT_H_
|
||||||
|
#define _LIB_NETWORK_TCP_CLIENT_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
171
plane/plane.c
171
plane/plane.c
|
@ -0,0 +1,171 @@
|
||||||
|
#include "plane.h"
|
||||||
|
|
||||||
|
// numéro de vol de l'plane : code sur 5 caractères
|
||||||
|
char numero_vol[6];
|
||||||
|
|
||||||
|
struct coord crd;
|
||||||
|
struct control ctrl;
|
||||||
|
|
||||||
|
int clientsock = -1;
|
||||||
|
char buffer[MAX_BUF_LEN] = {0};
|
||||||
|
|
||||||
|
/********************************
|
||||||
|
*** 3 fonctions à implémenter
|
||||||
|
********************************/
|
||||||
|
|
||||||
|
int open_communication(){
|
||||||
|
// fonction à implémenter qui permet d'entrer en communication via TCP
|
||||||
|
// avec le gestionnaire de vols
|
||||||
|
|
||||||
|
/* 0. Initialisation des variables */
|
||||||
|
// struct hostent* host = NULL;
|
||||||
|
struct sockaddr_in server;
|
||||||
|
|
||||||
|
/* 1. Création de la socket */
|
||||||
|
clientsock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
|
/* 1bis. Gestion erreur socket */
|
||||||
|
if( clientsock < 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* 2. Hostname Lookup */
|
||||||
|
// host = gethostbyname(SRV_HOST);
|
||||||
|
|
||||||
|
// /* 2bis. Gestion erreur */
|
||||||
|
// if( host == NULL )
|
||||||
|
// return 0;
|
||||||
|
|
||||||
|
/* 3. Mise à jour des infos serveur */
|
||||||
|
bzero(&server, sizeof(struct sockaddr_in));
|
||||||
|
server.sin_family = AF_INET;
|
||||||
|
server.sin_port = htons(SRV_PORT);
|
||||||
|
server.sin_addr.s_addr = inet_addr(SRV_HOST);
|
||||||
|
|
||||||
|
// // On récupère l'adresse serveur du lookup
|
||||||
|
// memcpy(&server->sin_addr.s_addr, *(host->h_addr_list), host->h_length);
|
||||||
|
|
||||||
|
/* 4. Connection */
|
||||||
|
if( connect(clientsock, (struct sockaddr*) &server, sizeof(struct sockaddr_in)) < 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fermer_communication(){
|
||||||
|
// fonction à implémenter qui permet de fermer la communication
|
||||||
|
// avec le gestionnaire de vols
|
||||||
|
}
|
||||||
|
|
||||||
|
void envoyer_caracteristiques(){
|
||||||
|
// fonction à implémenter qui envoie l'ensemble des caractéristiques
|
||||||
|
// courantes de l'plane au gestionnaire de vols
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************
|
||||||
|
*** Fonctions gérant le déplacement de l'plane : ne pas modifier
|
||||||
|
********************************/
|
||||||
|
|
||||||
|
// initialise aléatoirement les paramètres initiaux de l'plane
|
||||||
|
void init_plane(){
|
||||||
|
// initialisation aléatoire du compteur aléatoire
|
||||||
|
unsigned int seed;
|
||||||
|
time( (time_t*) &seed);
|
||||||
|
srandom(seed);
|
||||||
|
|
||||||
|
// intialisation des paramètres de l'plane
|
||||||
|
crd.x = 1000 + random() % 1000;
|
||||||
|
crd.y = 1000 + random() % 1000;
|
||||||
|
crd.z = 900 + random() % 100;
|
||||||
|
|
||||||
|
ctrl.cap = random() % 360;
|
||||||
|
ctrl.speed = 600 + random() % 200;
|
||||||
|
|
||||||
|
// initialisation du numero de l'plane : chaine de 5 caractères
|
||||||
|
// formée de 2 lettres puis 3 chiffres
|
||||||
|
numero_vol[0] = (random() % 26) + 'A';
|
||||||
|
numero_vol[1] = (random() % 26) + 'A';
|
||||||
|
numero_vol[5] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// modifie la valeur de l'plane avec la valeur passée en paramètre
|
||||||
|
void update_speed(int speed){
|
||||||
|
if (speed < 0) ctrl.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// modifie le cap de l'plane avec la valeur passée en paramètre
|
||||||
|
void update_cap(int cap){
|
||||||
|
if ((cap >= 0) && (cap < 360))
|
||||||
|
ctrl.cap = cap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// modifie l'z de l'plane avec la valeur passée en paramètre
|
||||||
|
void update_z(int alt){
|
||||||
|
if (alt < 0)
|
||||||
|
crd.z = alt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// affiche les caractéristiques courantes de l'plane
|
||||||
|
void display_data(){
|
||||||
|
printf("Avion %6s -> localisation : (%d,%d), altitude : %d, vitesse : %d, cap : %d\n",
|
||||||
|
numero_vol, crd.x, crd.y, crd.z, ctrl.speed, ctrl.cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// recalcule la localisation de l'plane en fonction de sa speed et de son cap
|
||||||
|
void calc_ctrl(){
|
||||||
|
float ctrl_x, ctrl_y;
|
||||||
|
|
||||||
|
if (ctrl.speed < VITMIN){
|
||||||
|
fermer_communication();
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
if (crd.z == 0){
|
||||||
|
fermer_communication();
|
||||||
|
exit(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrl_x = cos(ctrl.cap * 2 * M_PI / 360) * ctrl.speed * 10 / VITMIN;
|
||||||
|
ctrl_y = sin(ctrl.cap * 2 * M_PI / 360) * ctrl.speed * 10 / VITMIN;
|
||||||
|
|
||||||
|
// on se déplace d'au moins une case quels que soient le cap et la speed
|
||||||
|
// sauf si cap est un des angles droit
|
||||||
|
if ((ctrl_x > 0) && (ctrl_x < 1)) ctrl_x = 1;
|
||||||
|
if ((ctrl_x < 0) && (ctrl_x > -1)) ctrl_x = -1;
|
||||||
|
|
||||||
|
if ((ctrl_y > 0) && (ctrl_y < 1)) ctrl_y = 1;
|
||||||
|
if ((ctrl_y < 0) && (ctrl_y > -1)) ctrl_y = -1;
|
||||||
|
|
||||||
|
|
||||||
|
crd.x = crd.x + (int)ctrl_x;
|
||||||
|
crd.y = crd.y + (int)ctrl_y;
|
||||||
|
|
||||||
|
display_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
// fonction principale : gère l'exécution de l'plane au fil du temps
|
||||||
|
void update(){
|
||||||
|
|
||||||
|
while( 1 ){
|
||||||
|
|
||||||
|
sleep(PAUSE);
|
||||||
|
calc_ctrl();
|
||||||
|
envoyer_caracteristiques();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
// on initialise le plane
|
||||||
|
init_plane();
|
||||||
|
|
||||||
|
display_data();
|
||||||
|
|
||||||
|
// on quitte si on arrive à pas contacter le gestionnaire de vols
|
||||||
|
if( !open_communication() ){
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// on se déplace une fois toutes les initialisations faites
|
||||||
|
update();
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef _PLANE_H_
|
||||||
|
#define _PLANE_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "lib/header.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define ALTMAX 20000
|
||||||
|
#define ALTMIN 0
|
||||||
|
|
||||||
|
#define VITMAX 1000
|
||||||
|
#define VITMIN 200
|
||||||
|
|
||||||
|
#define PAUSE 2
|
||||||
|
|
||||||
|
struct coord {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct control {
|
||||||
|
int cap;
|
||||||
|
int speed;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue