Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
savoirfairelinux
jami-daemon
Commits
4103655d
Commit
4103655d
authored
16 years ago
by
Emmanuel Milou
Browse files
Options
Downloads
Patches
Plain Diff
Add REST code to build the request to server
parent
660bb518
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sflphone-gtk/src/reqaccount.c
+130
-0
130 additions, 0 deletions
sflphone-gtk/src/reqaccount.c
sflphone-gtk/src/reqaccount.h
+27
-0
27 additions, 0 deletions
sflphone-gtk/src/reqaccount.h
with
157 additions
and
0 deletions
sflphone-gtk/src/reqaccount.c
0 → 100644
+
130
−
0
View file @
4103655d
/*
* Copyright (C) 2009 Jean Schurger <jean@schurger.org>
* and Savoir-Faire Linux inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* To test:
*
* cc -o reqhttp reqhttp.c -DBUILD_EXAMPLE
*
*/
#include
<stdio.h>
#include
<errno.h>
#include
<signal.h>
#include
<string.h>
#include
<strings.h>
/* bzero */
#include
<netdb.h>
#include
<netinet/in.h>
#include
<sys/socket.h>
#include
"reqaccount.h"
int
req
(
char
*
host
,
int
port
,
char
*
req
,
char
*
ret
)
{
int
s
;
struct
sockaddr_in
servSockAddr
;
struct
hostent
*
servHostEnt
;
long
hostAddr
;
long
status
;
int
length
,
i
;
FILE
*
f
;
char
buf
[
1024
];
bzero
(
&
servSockAddr
,
sizeof
(
servSockAddr
));
hostAddr
=
inet_addr
(
host
);
if
((
long
)
hostAddr
!=
(
long
)
-
1
)
bcopy
(
&
hostAddr
,
&
servSockAddr
.
sin_addr
,
sizeof
(
hostAddr
));
else
{
servHostEnt
=
gethostbyname
(
host
);
if
(
servHostEnt
==
NULL
)
{
strcpy
(
ret
,
"gethostbyname"
);
return
-
1
;
}
bcopy
(
servHostEnt
->
h_addr
,
&
servSockAddr
.
sin_addr
,
servHostEnt
->
h_length
);
}
servSockAddr
.
sin_port
=
htons
(
port
);
servSockAddr
.
sin_family
=
AF_INET
;
if
((
s
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
{
strcpy
(
ret
,
"socket"
);
return
-
1
;
}
if
(
connect
(
s
,
(
const
struct
sockaddr
*
)
&
servSockAddr
,
(
socklen_t
)
sizeof
(
servSockAddr
))
<
0
)
{
strcpy
(
ret
,
"connect"
);
return
-
1
;
}
f
=
fdopen
(
s
,
"r+"
);
fprintf
(
f
,
"%s HTTP/1.1
\r\n
"
,
req
);
fprintf
(
f
,
"Host: %s
\r\n
"
,
host
);
fputs
(
"User-Agent: SFLphone
\r\n
"
,
f
);
fputs
(
"
\r\n
"
,
f
);
while
(
strncmp
(
fgets
(
buf
,
sizeof
(
buf
),
f
),
"
\r\n
"
,
2
))
{
const
char
*
len_h
=
"content-length"
;
const
char
*
status_h
=
"HTTP/1.1"
;
if
(
strncasecmp
(
buf
,
len_h
,
strlen
(
len_h
))
==
0
)
length
=
atoi
(
buf
+
strlen
(
len_h
)
+
1
);
if
(
strncasecmp
(
buf
,
status_h
,
strlen
(
status_h
))
==
0
)
status
=
atoi
(
buf
+
strlen
(
status_h
)
+
1
);
}
for
(
i
=
0
;
i
<
length
;
i
++
)
ret
[
i
]
=
fgetc
(
f
);
if
(
status
!=
200
)
{
sprintf
(
ret
,
"http error: %ld"
,
status
);
return
-
1
;
}
fclose
(
f
);
shutdown
(
s
,
2
);
close
(
s
);
return
0
;
}
rest_account
get_rest_account
(
char
*
host
)
{
char
ret
[
4096
];
rest_account
ra
;
bzero
(
ret
,
sizeof
(
ret
));
if
(
req
(
host
,
80
,
"GET /rest/accountcreator"
,
ret
)
!=
-
1
)
{
strcpy
(
ra
.
user
,
strtok
(
ret
,
"
\n
"
));
strcpy
(
ra
.
passwd
,
strtok
(
NULL
,
"
\n
"
));
\
ra
.
success
=
1
;
}
else
{
ra
.
success
=
0
;
strcpy
(
ra
.
reason
,
ret
);
}
return
ra
;
}
#ifdef BUILD_EXAMPLE
int
main
(
void
)
{
rest_account
acc
=
get_rest_account
(
"sip.sflphone.org"
);
if
(
acc
.
success
)
{
puts
(
acc
.
user
);
puts
(
acc
.
passwd
);
}
else
{
printf
(
"FAILED: %s
\n
"
,
acc
.
reason
);
}
}
#endif
This diff is collapsed.
Click to expand it.
sflphone-gtk/src/reqaccount.h
0 → 100644
+
27
−
0
View file @
4103655d
/*
* Copyright (C) 2009 Jean Schurger <jean@schurger.org>
* and Savoir-Faire Linux inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
typedef
struct
{
char
success
;
char
reason
[
200
];
char
user
[
200
];
char
passwd
[
200
];
}
rest_account
;
rest_account
get_rest_account
(
char
*
host
);
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