@@ -5,21 +5,24 @@ unsigned FDn;
5
5
static void * mainloopthread (void * loop );
6
6
pthread_t thr ;
7
7
8
- gchar * filter_str (gchar * str ) {
8
+ gchar * filter_str (gchar * str )
9
+ {
9
10
gchar * ch = strchr (str , '\n' );
10
- if (ch )
11
+ if (ch )
11
12
str [ch - str ] = 0 ;
12
13
g_strstrip (str );
13
14
return str ;
14
15
}
15
16
16
- int fileexists (const char * path ) { /* TODO remove/rewrite */
17
+ int fileexists (const char * path ) /* TODO remove/rewrite */
18
+ {
17
19
if (strcmp (path , "/log" ) == 0 ) return 1 ;
18
20
if (strncmp (path , "/roster/" , 8 ) == 0 ) return 1 ;
19
21
return 0 ;
20
22
}
21
23
22
- rosteritem * getri (const char * path ) {
24
+ rosteritem * getri (const char * path )
25
+ {
23
26
char * p ;
24
27
rosteritem * ri ;
25
28
@@ -36,7 +39,8 @@ rosteritem * getri(const char *path) {
36
39
return ri ;
37
40
}
38
41
39
- FD * addfd (rosteritem * ri ) {
42
+ FD * addfd (rosteritem * ri )
43
+ {
40
44
FD * fd ;
41
45
int * id ;
42
46
@@ -50,19 +54,22 @@ FD * addfd(rosteritem *ri) {
50
54
return fd ;
51
55
}
52
56
53
- void destroyfd (FD * fd ) {
57
+ void destroyfd (FD * fd )
58
+ {
54
59
// g_array_free(fd->readbuf, TRUE); /* TODO? */
55
60
g_array_free (fd -> writebuf , TRUE);
56
61
g_free (fd );
57
62
}
58
63
59
64
/* FS calls */
60
65
61
- static int fstruncate (const char * path , off_t size ) {
66
+ static int fstruncate (const char * path , off_t size )
67
+ {
62
68
return 0 ;
63
69
}
64
70
65
- static int fsrmdir (const char * path ) {
71
+ static int fsrmdir (const char * path )
72
+ {
66
73
if (strcmp (path , "/config" ) == 0 ) {
67
74
g_hash_table_destroy (config );
68
75
config = g_hash_table_new_full (g_str_hash , g_str_equal , NULL , g_free );
@@ -81,17 +88,17 @@ static int fsrmdir(const char *path) {
81
88
ri = getri (path );
82
89
if (ri ) {
83
90
if (ri -> type == MUC ) {
84
- partmuc (path , NULL , "TODO here must be default leave message :-)" );
85
- g_hash_table_remove (roster , path );
86
- }
87
- else logstr ("Roster items removal isn't implemented\n" );; /* TODO */
91
+ partmuc (path , NULL , "TODO here must be default leave message :-)" );
92
+ g_hash_table_remove (roster , path );
93
+ } else logstr ("Roster items removal isn't implemented\n" );; /* TODO */
88
94
return 0 ;
89
95
} else return - ENOENT ;
90
96
}
91
97
return - EPERM ;
92
98
}
93
99
94
- static int fscreate (const char * path , mode_t mode , struct fuse_file_info * fi ) {
100
+ static int fscreate (const char * path , mode_t mode , struct fuse_file_info * fi )
101
+ {
95
102
/* TODO add roster items */
96
103
if (strncmp (path , "/roster/" , 8 ) == 0 ) {
97
104
path += 8 ;
@@ -100,12 +107,14 @@ static int fscreate(const char *path, mode_t mode, struct fuse_file_info *fi) {
100
107
return 0 ;
101
108
}
102
109
103
- static int fsmknod (const char * path , mode_t mode , dev_t type ) {
110
+ static int fsmknod (const char * path , mode_t mode , dev_t type )
111
+ {
104
112
/* TODO */
105
113
return 0 ;
106
114
}
107
115
108
- static int fsmkdir (const char * path , mode_t mode ) {
116
+ static int fsmkdir (const char * path , mode_t mode )
117
+ {
109
118
if (strcmp (path , "/roster" ) == 0 ) {
110
119
logstr ("Make roster!\n" );
111
120
if (connection && lm_connection_is_open (connection )) {
@@ -135,7 +144,7 @@ static int fsgetattr(const char *path, struct stat *stbuf)
135
144
return 0 ;
136
145
}
137
146
if (strcmp (path , "/log" ) == 0 ) {
138
- stbuf -> st_mode = S_IFREG | 0666 ;
147
+ stbuf -> st_mode = S_IFREG | 0666 ;
139
148
stbuf -> st_nlink = 1 ;
140
149
stbuf -> st_size = LogBuf -> len ;
141
150
return 0 ;
@@ -147,10 +156,10 @@ static int fsgetattr(const char *path, struct stat *stbuf)
147
156
return 0 ;
148
157
}
149
158
if (strcmp (path , "/rawxmpp" ) == 0 ) {
150
- stbuf -> st_mode = S_IFREG | 0222 ;
159
+ stbuf -> st_mode = S_IFREG | 0222 ;
151
160
stbuf -> st_nlink = 1 ;
152
161
return 0 ;
153
- }
162
+ }
154
163
}
155
164
if ((strcmp (path , "/config" ) == 0 ) ||
156
165
(strcmp (path , "/" ) == 0 )) {
@@ -187,7 +196,7 @@ static int fsgetattr(const char *path, struct stat *stbuf)
187
196
}
188
197
189
198
static int fsreaddir (const char * path , void * buf , fuse_fill_dir_t filler ,
190
- off_t offset , struct fuse_file_info * fi )
199
+ off_t offset , struct fuse_file_info * fi )
191
200
{
192
201
(void ) offset ;
193
202
(void ) fi ;
@@ -218,11 +227,10 @@ static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
218
227
filler (buf , "ssl" , NULL , 0 );
219
228
220
229
}
221
- if (strcmp (path , "/roster" ) == 0 )
222
- {
230
+ if (strcmp (path , "/roster" ) == 0 ) {
223
231
filler (buf , "." , NULL , 0 );
224
232
filler (buf , ".." , NULL , 0 );
225
-
233
+
226
234
GHashTableIter iter ;
227
235
rosteritem * ri ;
228
236
g_hash_table_iter_init (& iter , roster );
@@ -233,7 +241,7 @@ static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
233
241
if (strncmp (path , "/roster/" , 8 ) == 0 ) {
234
242
path += 8 ;
235
243
rosteritem * ri ;
236
-
244
+
237
245
ri = getri (path );
238
246
if (ri ) {
239
247
filler (buf , "." , NULL , 0 );
@@ -244,7 +252,7 @@ static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
244
252
GHashTableIter iter ;
245
253
gchar * res ;
246
254
g_hash_table_iter_init (& iter , ri -> resources );
247
- while (g_hash_table_iter_next (& iter , (gpointer ) & res , NULL ))
255
+ while (g_hash_table_iter_next (& iter , (gpointer ) & res , NULL ))
248
256
filler (buf , res , NULL , 0 );
249
257
}
250
258
}
@@ -256,24 +264,25 @@ static int fsopen(const char *path, struct fuse_file_info *fi)
256
264
{
257
265
/* FDs are introduced only for writing ops */
258
266
if ((fi -> flags & O_WRONLY ) || (fi -> flags & O_RDWR )) {
259
- if (strncmp (path , "/roster/" , 8 ) == 0 ) {
267
+ if (strncmp (path , "/roster/" , 8 ) == 0 ) {
260
268
rosteritem * ri ;
261
269
262
- path += 8 ;
263
- ri = getri (path );
270
+ path += 8 ;
271
+ ri = getri (path );
264
272
if (ri ) {
265
273
/* TODO */
266
- }
274
+ }
267
275
}
268
276
}
269
277
/* TODO */
270
278
return 0 ;
271
279
}
272
280
273
- static char * get_option (const char * option ) {
281
+ static char * get_option (const char * option )
282
+ {
274
283
if (strcmp (option , "server" ) == 0 ) {
275
284
const char * r = lm_connection_get_server (connection );
276
- if (r )
285
+ if (r )
277
286
return strdup (r );
278
287
} else if (strcmp (option , "ssl" ) == 0 ) {
279
288
if (ssl ) {
@@ -301,7 +310,7 @@ static char *get_option(const char *option) {
301
310
}
302
311
303
312
static int fsread (const char * path , char * buf , size_t size , off_t offset ,
304
- struct fuse_file_info * fi )
313
+ struct fuse_file_info * fi )
305
314
{
306
315
if (strcmp (path , "/log" ) == 0 ) {
307
316
// write(fi->fh, LogBuf->data+offset, size);
@@ -362,23 +371,24 @@ static int fsread(const char *path, char *buf, size_t size, off_t offset,
362
371
}
363
372
364
373
// FIXME fuse with set_option
365
- static char * prepare_option (const char * option , const char * buf , size_t size ) {
374
+ static char * prepare_option (const char * option , const char * buf , size_t size )
375
+ {
366
376
char * val ;
367
377
368
378
// bool options
369
379
if ((strcmp (option , "events" ) == 0 ) ||
370
- (strcmp (option , "raw_logs" )== 0 )) {
380
+ (strcmp (option , "raw_logs" )== 0 )) {
371
381
val = strdup ("1" ); // just something :)
372
382
} else {
373
383
val = filter_str (strndup (buf , size ));
374
-
384
+
375
385
bool pr ;
376
- if (strcmp (option , "show" ) == 0 &&
377
- strcmp (val , "" ) &&
378
- strcmp (val , "away" ) &&
379
- strcmp (val , "chat" ) &&
380
- strcmp (val , "dnd" ) &&
381
- strcmp (val , "xa" )) {
386
+ if (strcmp (option , "show" ) == 0 &&
387
+ strcmp (val , "" ) &&
388
+ strcmp (val , "away" ) &&
389
+ strcmp (val , "chat" ) &&
390
+ strcmp (val , "dnd" ) &&
391
+ strcmp (val , "xa" )) {
382
392
logf ("Failed to set %s to incorrect value %s\n" , option , val );
383
393
return 0 ;
384
394
} else if (strcmp (option , "ssl" ) == 0 ) {
@@ -392,7 +402,7 @@ static char *prepare_option(const char *option, const char *buf, size_t size) {
392
402
return 0 ;
393
403
}
394
404
} else if ((pr = (strcmp (option , "priority" ) == 0 )) ||
395
- ((strcmp (option , "port" ) == 0 ))) {
405
+ ((strcmp (option , "port" ) == 0 ))) {
396
406
/* Suggest a better way to validate the integer */
397
407
char * not_ok ;
398
408
long long i = strtoll (val , & not_ok , 10 );
@@ -417,7 +427,8 @@ static char *prepare_option(const char *option, const char *buf, size_t size) {
417
427
return val ;
418
428
}
419
429
420
- static void set_option (char * option , char * val ) {
430
+ static void set_option (char * option , char * val )
431
+ {
421
432
bool used = false;
422
433
423
434
// FIXME: in the case of ssl, the argument is not a string but a number
@@ -451,9 +462,9 @@ static void set_option(char *option, char *val) {
451
462
used = true;
452
463
}
453
464
if (connection_state == ONLINE && (
454
- strcmp (option , "priority" ) == 0 ||
455
- strcmp (option , "show" ) == 0 ||
456
- strcmp (option , "status" ) == 0 ))
465
+ strcmp (option , "priority" ) == 0 ||
466
+ strcmp (option , "show" ) == 0 ||
467
+ strcmp (option , "status" ) == 0 ))
457
468
xmpp_send_presence ();
458
469
if (!used ) {
459
470
if (strcmp (option , "ssl" )) {
@@ -478,7 +489,7 @@ static int fswrite(const char *path, const char *buf, size_t size, off_t offset,
478
489
msg = g_malloc (msg_len + 1 );
479
490
memcpy (msg , buf , msg_len );
480
491
msg [msg_len ] = 0 ;
481
- if (res && (strncmp (res , "__nick" , 6 ) == 0 ))
492
+ if (res && (strncmp (res , "__nick" , 6 ) == 0 ))
482
493
xmpp_muc_change_nick (get_jid (path ), msg );
483
494
else
484
495
xmpp_send (path , msg );
@@ -503,12 +514,14 @@ static int fswrite(const char *path, const char *buf, size_t size, off_t offset,
503
514
return 0 ;
504
515
}
505
516
506
- static int fssetxattr (const char * path , const char * a , const char * aa , size_t size , int aaa ) {
517
+ static int fssetxattr (const char * path , const char * a , const char * aa , size_t size , int aaa )
518
+ {
507
519
/* Stub. Do we need this? */
508
520
return 0 ;
509
521
}
510
522
511
- static int fsunlink (const char * path ) {
523
+ static int fsunlink (const char * path )
524
+ {
512
525
if (strncmp (path , "/roster/" , 8 ) == 0 ) {
513
526
path += 8 ;
514
527
char * sl = strchr (path , '/' );
@@ -532,8 +545,9 @@ static int fsunlink(const char *path) {
532
545
return 0 ;
533
546
}
534
547
535
- static void fsdestroy (void * privdata ) {
536
- if (connection )
548
+ static void fsdestroy (void * privdata )
549
+ {
550
+ if (connection )
537
551
xmpp_disconnect ();
538
552
free_all ();
539
553
if (main_loop ) {
@@ -543,18 +557,21 @@ static void fsdestroy(void *privdata) {
543
557
return ;
544
558
}
545
559
546
- static void * mainloopthread (void * loop ) {
560
+ static void * mainloopthread (void * loop )
561
+ {
547
562
xmpp_connect ();
548
563
g_main_loop_run (main_loop );
549
564
return NULL ;
550
565
}
551
566
552
- static void * fsinit (struct fuse_conn_info * conn ) {
567
+ static void * fsinit (struct fuse_conn_info * conn )
568
+ {
553
569
FDt = g_hash_table_new_full (g_int_hash , g_int_equal , g_free , (GDestroyNotify )destroyfd ); //TODO check the cast
554
570
return NULL ;
555
571
}
556
572
557
- int fuseinit (int argc , char * * argv ) {
573
+ int fuseinit (int argc , char * * argv )
574
+ {
558
575
int ret ;
559
576
// fifo = open("fs/log", O_WRONLY | O_NONBLOCK);
560
577
ret = fuse_main (argc , argv , & fuseoper , NULL );
0 commit comments