Toggle navigation
Toggle navigation
This project
Loading...
Sign in
조성현
/
graph-visualization
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
조성현
2017-06-20 17:52:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c7605bb6320483f14b1ee57d4e30c9b55017d56f
c7605bb6
1 parent
327ed007
중간저장3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
6 deletions
PaperGraph/curl_processor.cpp
PaperGraph/curl_processor.h
PaperGraph/main.cpp
PaperGraph/curl_processor.cpp
View file @
c7605bb
...
...
@@ -3,18 +3,37 @@
//////////////////////////////////////////////////////////////////
// private func
//////////////////////////////////////////////////////////////////
size_t
curl_processor
::
write_callback
(
void
*
contents
,
size_t
size
,
size_t
nmemb
,
void
*
userp
)
{
//copy ptr
std
::
string
*
p_str
=
(
std
::
string
*
)
userp
;
//clear
if
(
!
p_str
->
empty
())
p_str
->
clear
();
//write
p_str
->
append
((
char
*
)
contents
,
size
*
nmemb
);
return
size
*
nmemb
;
}
//////////////////////////////////////////////////////////////////
// constructor, destructor
//////////////////////////////////////////////////////////////////
curl_processor
::
curl_processor
()
{
curl_processor
::
curl_processor
()
{
curl
=
curl_easy_init
();
if
(
!
curl
)
{
throw
std
::
exception
(
"failed to make curl object"
);
}
//set curl option
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
this
->
write_callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
&
result_buffer
);
}
curl_processor
::~
curl_processor
()
{
curl_processor
::~
curl_processor
()
{
curl_easy_cleanup
(
curl
);
}
...
...
@@ -22,3 +41,11 @@ curl_processor::~curl_processor()
//////////////////////////////////////////////////////////////////
// methods
//////////////////////////////////////////////////////////////////
void
curl_processor
::
set_url
(
const
char
*
url
)
{
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
}
bool
curl_processor
::
perform
()
{
res
=
curl_easy_perform
(
curl
);
return
(
res
==
CURLE_OK
);
}
\ No newline at end of file
...
...
PaperGraph/curl_processor.h
View file @
c7605bb
...
...
@@ -9,6 +9,11 @@ class curl_processor
private:
CURL
*
curl
;
CURLcode
res
;
std
::
string
result_buffer
;
//private func
private:
size_t
write_callback
(
void
*
contents
,
size_t
size
,
size_t
nmemb
,
void
*
userp
);
//constructor, destructor
public:
...
...
@@ -17,7 +22,9 @@ public:
//methods
public:
std
::
string
get_buffer
()
const
{
return
result_buffer
;
}
void
set_url
(
const
char
*
url
);
bool
perform
();
};
#endif // CURL_PROCESSOR_H
\ No newline at end of file
...
...
PaperGraph/main.cpp
View file @
c7605bb
...
...
@@ -2,20 +2,42 @@
#include "PaperGraphWidget.h"
#include "MainWindow.h"
size_t
write_callback
(
void
*
contents
,
size_t
size
,
size_t
nmemb
,
void
*
userp
)
{
std
::
string
*
p_str
=
(
std
::
string
*
)
userp
;
//clear
if
(
!
p_str
->
empty
())
p_str
->
clear
();
//write
p_str
->
append
((
char
*
)
contents
,
size
*
nmemb
);
return
size
*
nmemb
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
1
)
{
CURL
*
curl
;
CURLcode
res
;
std
::
string
read_buffer
;
curl
=
curl_easy_init
();
if
(
curl
)
{
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
"http://dblp.uni-trier.de/rec/bib/conf/sbrn/WedemannCD06"
);
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt
(
curl
,
CURLOPT_FOLLOWLOCATION
,
1L
);
//write option
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
write_callback
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
&
read_buffer
);
/* Perform the request, res will get the return code */
res
=
curl_easy_perform
(
curl
);
res
=
curl_easy_perform
(
curl
);
printf
(
"%s
\n
"
,
read_buffer
.
c_str
());
/* Check for errors */
if
(
res
!=
CURLE_OK
)
fprintf
(
stderr
,
"curl_easy_perform() failed: %s
\n
"
,
...
...
Please
register
or
login
to post a comment