Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
mediawiki-fs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hugo Hörnquist
mediawiki-fs
Commits
c51ceff4
Commit
c51ceff4
authored
May 15, 2019
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start work on C++ port.
parent
d29643a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
162 additions
and
0 deletions
+162
-0
Makefile
Makefile
+7
-0
mediawikifs.cpp
mediawikifs.cpp
+130
-0
mediawikifs.h
mediawikifs.h
+25
-0
No files found.
Makefile
0 → 100644
View file @
c51ceff4
LIBS
=
$(
shell
pkg-config
--libs
libcurl fuse
)
CFLAGS
=
$(
shell
pkg-config
--cflags
libcurl fuse
)
-ggdb
\
-std
=
c++2a
-Wall
-Wextra
-pedantic
\
-D_FILE_OFFSET_BITS
=
64
all
:
g++
$(LIBS)
$(CFLAGS)
-o
mfs mediawikifs.cpp
mediawikifs.cpp
0 → 100644
View file @
c51ceff4
#include "mediawikifs.h"
#include <map>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <sys/types.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include <fuse.h>
static
std
::
string
str
;
static
CURL
*
curl
;
page
*
get_page
(
const
char
*
path
)
{
static
std
::
map
<
const
char
*
,
page
>
pages
;
page
*
p
=
&
pages
[
path
];
if
(
p
->
init
)
return
p
;
str
=
""
;
CURLcode
code
;
code
=
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
if
(
code
!=
CURLE_OK
)
ERR
(
"Set url"
);
code
=
curl_easy_perform
(
curl
);
if
(
code
!=
CURLE_OK
)
ERR
(
"Perform %i"
,
code
);
p
->
init
=
true
;
p
->
name
=
path
;
p
->
data
=
str
;
p
->
size
=
str
.
size
();
p
->
timestamp
=
1
;
return
p
;
}
size_t
handle_data
(
void
*
buffer
,
size_t
,
size_t
nmemb
,
void
*
)
{
str
+=
(
char
*
)
buffer
;
return
nmemb
;
}
int
getattr_callback
(
const
char
*
path
,
struct
stat
*
st
)
{
if
(
strcmp
(
path
,
"/"
)
==
0
)
{
// TODO get size of map
return
2
;
}
page
*
p
=
get_page
(
path
);
st
->
st_mode
=
0444
;
st
->
st_size
=
p
->
size
;
// st->st_mtime
return
0
;
}
int
open_callback
(
const
char
*
/*path*/
,
struct
fuse_file_info
*
/*f*/
)
{
return
0
;
}
int
read_callback
(
const
char
*
path
,
char
*
buf
,
size_t
size
,
off_t
offset
,
struct
fuse_file_info
*
/*f*/
)
{
page
*
p
=
get_page
(
path
);
std
::
string
*
s
=
&
p
->
data
;
ssize_t
len
=
s
->
size
();
if
(
offset
>=
len
)
return
0
;
if
(
offset
+
(
off_t
)
size
>
len
)
{
memcpy
(
buf
,
s
->
c_str
()
+
offset
,
len
-
offset
);
return
len
-
offset
;
}
memcpy
(
buf
,
s
->
c_str
()
+
offset
,
size
);
return
size
;
}
int
readdir_callback
(
const
char
*
path
,
void
*
buf
,
fuse_fill_dir_t
filler
,
off_t
/* offset */
,
struct
fuse_file_info
*
/*f*/
)
{
if
(
strcmp
(
path
,
"/"
)
!=
0
)
{
return
1
;
}
filler
(
buf
,
"."
,
NULL
,
0
);
filler
(
buf
,
".."
,
NULL
,
0
);
filler
(
buf
,
"Tottaly a file"
,
NULL
,
0
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
CURLcode
code
;
code
=
curl_global_init
(
CURL_GLOBAL_DEFAULT
);
if
(
code
!=
CURLE_OK
)
ERR
(
"Global init"
);
curl
=
curl_easy_init
();
if
(
curl
==
NULL
)
ERR
(
"curl"
);
code
=
curl_easy_setopt
(
curl
,
CURLOPT_WRITEFUNCTION
,
handle_data
);
if
(
code
!=
CURLE_OK
)
ERR
(
"Write data"
);
struct
fuse_operations
fops
;
fops
.
getattr
=
getattr_callback
;
fops
.
open
=
open_callback
;
fops
.
read
=
read_callback
;
fops
.
readdir
=
readdir_callback
;
// page* p = get_page("Bishibosh");
// std::cout << p->data << std::endl;
return
fuse_main
(
argc
,
argv
,
&
fops
,
NULL
);
// puts(str.c_str());
// curl_easy_cleanup (curl);
}
mediawikifs.h
0 → 100644
View file @
c51ceff4
#define FUSE_USE_VERSION 28
#include <string>
#include <sys/types.h>
#include <fuse.h>
#define url "https://datorhandbok.lysator.liu.se/index.php/Special:Exportera/Bishibosh"
#define ERR(s, ...) fprintf(stderr, "\x1b[0;31mERR\x1b[m " s "\n", ## __VA_ARGS__)
struct
page
{
bool
init
=
false
;
std
::
string
name
;
size_t
size
;
uint64_t
timestamp
;
std
::
string
data
;
};
extern
"C"
{
int
getattr_callback
(
const
char
*
,
struct
stat
*
);
int
open_callback
(
const
char
*
,
struct
fuse_file_info
*
);
int
read_callback
(
const
char
*
,
char
*
,
size_t
,
off_t
,
struct
fuse_file_info
*
);
int
readdir_callback
(
const
char
*
,
void
*
,
fuse_fill_dir_t
,
off_t
,
struct
fuse_file_info
*
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment