Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vytor Calixto
Caco
Commits
002e600f
Commit
002e600f
authored
9 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Started implementation of commands in server side
Signed-off-by:
Israel Barreto Sant'Anna
<
ibsa14@inf.ufpr.br
>
parent
53c7bbd5
Branches
Branches containing commit
No related tags found
1 merge request
!1
Lento
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
Protocol.cpp
+20
-8
20 additions, 8 deletions
Protocol.cpp
Protocol.h
+5
-2
5 additions, 2 deletions
Protocol.h
definitions.h
+10
-7
10 additions, 7 deletions
definitions.h
dirFunctions.cpp
+0
-13
0 additions, 13 deletions
dirFunctions.cpp
server.cpp
+26
-12
26 additions, 12 deletions
server.cpp
with
61 additions
and
42 deletions
Protocol.cpp
+
20
−
8
View file @
002e600f
...
...
@@ -10,28 +10,40 @@ void Protocol::setMessage(Message message){
this
->
message
=
message
;
}
vector
<
BYTE
>
Protocol
::
getData
(){
return
data
;
}
string
Protocol
::
getDataAsString
(){
string
str
(
data
.
begin
(),
data
.
end
());
return
str
;
}
void
Protocol
::
setData
(
vector
<
BYTE
>
data
){
this
->
data
=
data
;
}
int
Protocol
::
readMessage
(
int
sockt
){
unsigned
char
dataRec
[
MAXSIZE
+
4
];
int
ret
=
recv
(
sockt
,
dataRec
,
MAXSIZE
,
0
);
BYTE
dataRec
[
MAXSIZE
+
4
];
recv
(
sockt
,
dataRec
,
MAXSIZE
,
0
);
Message
msg
;
msg
.
c_ctrl
.
begin
=
dataRec
[
0
];
if
(
msg
.
i_ctrl
.
begin
!=
BEGIN
){
return
0
;
return
-
1
;
}
msg
.
c_ctrl
.
size
=
dataRec
[
1
];
msg
.
c_ctrl
.
seqType
=
dataRec
[
2
];
msg
.
c_ctrl
.
parity
=
dataRec
[
3
+
msg
.
i_ctrl
.
size
];
// TODO: Check parity
if
(
msg
.
i_ctrl
.
type
==
FIM
){
this
->
message
=
msg
;
return
1
;
if
(
msg
.
i_ctrl
.
type
==
ENDTX
){
return
ENDTX
;
}
unsigned
char
msgData
[
msg
.
i_ctrl
.
size
];
BYTE
msgData
[
msg
.
i_ctrl
.
size
];
memcpy
(
msgData
,
dataRec
+
3
,
msg
.
i_ctrl
.
size
);
this
->
data
.
insert
(
this
->
data
.
end
(),
msgData
,
msgData
+
msg
.
i_ctrl
.
size
);
this
->
message
=
msg
;
return
-
1
;
return
msg
.
i_ctrl
.
type
;
}
Protocol
::
Protocol
(){
...
...
This diff is collapsed.
Click to expand it.
Protocol.h
+
5
−
2
View file @
002e600f
...
...
@@ -6,13 +6,16 @@ class Protocol{
private:
Message
message
;
vector
<
unsigned
char
>
data
;
vector
<
BYTE
>
data
;
int
timeout
;
public:
Message
getMessage
();
void
setMessage
(
Message
message
);
int
readMessage
(
int
socket
);
vector
<
BYTE
>
getData
();
void
setData
(
vector
<
BYTE
>
data
);
string
getDataAsString
();
int
readMessage
(
int
sockt
);
Protocol
();
};
...
...
This diff is collapsed.
Click to expand it.
definitions.h
+
10
−
7
View file @
002e600f
...
...
@@ -7,10 +7,10 @@
using
namespace
std
;
#define MAXSIZE 64
#define MINSIZE 60
#define MAXSIZE 64
//number maximum of bytes in data field
#define MINSIZE 60
//number minimum of bytes in data field
#define BEGIN 0x7E
#define BEGIN 0x7E
//begin delimiter value
#define DEVICE "lo"
#define NACK 0
...
...
@@ -20,10 +20,13 @@ using namespace std;
#define PUT 5
#define GET 6
#define OK 8
#define TAM 9
#define TELA 10
#define ERRO 14
#define FIM 15
#define SIZE 9
#define OUTPUT 10
#define DATA 13
#define ERROR 14
#define ENDTX 15
#define BYTE unsigned char
typedef
struct
{
int
begin
:
8
,
...
...
This diff is collapsed.
Click to expand it.
dirFunctions.cpp
+
0
−
13
View file @
002e600f
...
...
@@ -3,9 +3,7 @@
#include
<unistd.h>
#include
<string.h>
#include
<vector>
#include
<numeric>
//accumulate
#include
<stdio.h>
//popen
#include
<iterator>
using
namespace
std
;
...
...
@@ -28,15 +26,4 @@ string ls(string args){
}
pclose
(
lsOut
);
return
output
;
//TODO: #1
// struct dirent *entry;
// DIR *dir = opendir(path.c_str());
// if(dir != NULL){
// while((entry=readdir(dir)) != NULL){
// cout << entry->d_name << endl;
// }
// closedir(dir);
// }else{
// cout<<"Error: could not open directory."<<endl;
// }
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server.cpp
+
26
−
12
View file @
002e600f
#include
"definitions.h"
#include
"dirFunctions.h"
#include
"ConexaoRawSocket.c"
int
main
(){
int
sockt
=
ConexaoRawSocket
(
DEVICE
);
Protocol
protocol
;
while
(
true
){
int
ret
=
protocol
.
readMessage
(
sockt
);
if
(
ret
){
if
(
ret
==
1
){
//End of transmission
int
status
=
protocol
.
readMessage
(
sockt
);
if
(
status
>
0
){
if
(
status
==
ENDTX
){
protocol
=
Protocol
();
if
(
protocol
.
getMessage
().
i_ctrl
.
type
==
DATA
){
//TODO: send ACK
}
}
else
if
(
status
==
CD
){
cd
(
protocol
.
getDataAsString
());
}
else
if
(
status
==
LS
){
string
output
=
ls
(
protocol
.
getDataAsString
());
//TODO: send output back
}
else
if
(
status
==
PUT
){
//TODO
}
else
if
(
status
==
GET
){
//TODO
//intesristing link: http://stackoverflow.com/questions/15138353/reading-the-binary-file-into-the-vector-of-unsigned-chars
}
//TODO: Check window sequence and blablabla
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment