Codebase list cyrus-imapd / debian/2.4.17+caldav_beta9-1 imap / pushstats.c
debian/2.4.17+caldav_beta9-1

Tree @debian/2.4.17+caldav_beta9-1 (Download .tar.gz)

pushstats.c @debian/2.4.17+caldav_beta9-1raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
/* pushstats.c -- automatically generated from pushstats.snmp by snmpgen */



#ifdef USING_SNMPGEN



/* We disable this code for now since it doesn't actually work and wastes

 * resources.  At some point in time, we'll make it work again as it would 

 * be useful to gather aggregate statistics on what commands are being used 

 * so we can better tune the server.  This change closes bug #1191. 

 * New bug 1267 opened to re-enable the feature.

 */



#ifdef HAVE_UNISTD_H

#include <unistd.h>

#endif

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <sys/un.h>

#include <fcntl.h>

#include <stdarg.h>



#include "index.h"

#include "pushstats.h"



extern int close(int);



int variable_value[1+1];

int variable_tmpvalue[1+1];



int varvalue(pushstats_variable_t var)

{

    if (variable_tmpvalue[var]!=-1)

        return variable_tmpvalue[var];



    return variable_value[var];

}



const char *snmp_getdescription(pushstats_t evt)

{

    switch (evt) {

        case MYRIGHTS_COUNT: return "Number of myrights";
        case BBOARD_COUNT: return "Number of bboard";
        case SCAN_COUNT: return "Number of list";
        case LSUB_COUNT: return "Number of lsub";
        case AUTHENTICATION_YES: return "Successful authentication of given mechanism";
        case GETQUOTAROOT_COUNT: return "Number of getquotaroot";
        case STATUS_COUNT: return "Number of status";
        case FETCH_COUNT: return "Number of fetch";
        case STARTTLS_COUNT: return "Number of starttls";
        case LOGIN_COUNT: return "Number of login";
        case UNSUBSCRIBE_COUNT: return "Number of unsubscribe";
        case GETANNOTATION_COUNT: return "Number of getannotation";
        case SERVER_NAME_VERSION: return "Name and version string for server";
        case LISTRIGHTS_COUNT: return "Number of listrights";
        case AUTHENTICATION_NO: return "Failed authentication of given mechanism";
        case SORT_COUNT: return "Number of sort";
        case EXAMINE_COUNT: return "Number of examine";
        case EXPUNGE_COUNT: return "Number of expunge";
        case SERVER_UPTIME: return "Amount of time server has been running";
        case CHECK_COUNT: return "Number of check";
        case CAPABILITY_COUNT: return "Number of capability";
        case RENAME_COUNT: return "Number of rename";
        case LIST_COUNT: return "Number of list";
        case ID_COUNT: return "Number of id";
        case GETQUOTA_COUNT: return "Number of getquota";
        case IDLE_COUNT: return "Number of idle";
        case COMPRESS_COUNT: return "Number of compress";
        case DELETE_COUNT: return "Number of delete";
        case SETANNOTATION_COUNT: return "Number of setannotation";
        case GETACL_COUNT: return "Number of getacl";
        case SELECT_COUNT: return "Number of select";
        case UNSELECT_COUNT: return "Number of unselect";
        case SETACL_COUNT: return "Number of setacl";
        case CLOSE_COUNT: return "Number of close";
        case NOOP_COUNT: return "Number of noop";
        case GETUIDS_COUNT: return "Number of getuids";
        case SEARCH_COUNT: return "Number of search";
        case NAMESPACE_COUNT: return "Number of namespace";
        case THREAD_COUNT: return "Number of thread";
        case SETQUOTA_COUNT: return "Number of setquota";
        case LOGOUT_COUNT: return "Number of logout";
        case CREATE_COUNT: return "Number of create";
        case SUBSCRIBE_COUNT: return "Number of subscribe";
        case TOTAL_CONNECTIONS: return "Count of the total number of connections since the beginning of time";
        case ACTIVE_CONNECTIONS: return "Count of the active number of connections";
        case DELETEACL_COUNT: return "Number of deleteacl";
        case STORE_COUNT: return "Number of store";
        case FIND_COUNT: return "Number of find";
        case AUTHENTICATE_COUNT: return "Number of authenticate";
        case PARTIAL_COUNT: return "Number of partial";
        case APPEND_COUNT: return "Number of append";
        case COPY_COUNT: return "Number of copy";

    }

    return NULL;

}



const char *snmp_getoid(const char *name __attribute__((unused)),

			pushstats_t evt, char *buf, int buflen)

{

    switch (evt) {

        case MYRIGHTS_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.27"); return buf;
        case BBOARD_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.2"); return buf;
        case SCAN_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.32"); return buf;
        case LSUB_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.25"); return buf;
        case AUTHENTICATION_YES: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.2.%d.0",varvalue(VARIABLE_AUTH)); return buf;
        case GETQUOTAROOT_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.18"); return buf;
        case STATUS_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.41"); return buf;
        case FETCH_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.13"); return buf;
        case STARTTLS_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.33"); return buf;
        case LOGIN_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.22"); return buf;
        case UNSUBSCRIBE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.44"); return buf;
        case GETANNOTATION_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.16"); return buf;
        case SERVER_NAME_VERSION: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.3.0"); return buf;
        case LISTRIGHTS_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.26"); return buf;
        case AUTHENTICATION_NO: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.2.%d.1",varvalue(VARIABLE_AUTH)); return buf;
        case SORT_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.42"); return buf;
        case EXAMINE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.12"); return buf;
        case EXPUNGE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.11"); return buf;
        case SERVER_UPTIME: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.3.1"); return buf;
        case CHECK_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.4"); return buf;
        case CAPABILITY_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.3"); return buf;
        case RENAME_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.31"); return buf;
        case LIST_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.24"); return buf;
        case ID_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.20"); return buf;
        case GETQUOTA_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.17"); return buf;
        case IDLE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.21"); return buf;
        case COMPRESS_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.8"); return buf;
        case DELETE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.9"); return buf;
        case SETANNOTATION_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.39"); return buf;
        case GETACL_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.15"); return buf;
        case SELECT_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.35"); return buf;
        case UNSELECT_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.45"); return buf;
        case SETACL_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.38"); return buf;
        case CLOSE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.7"); return buf;
        case NOOP_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.28"); return buf;
        case GETUIDS_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.19"); return buf;
        case SEARCH_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.36"); return buf;
        case NAMESPACE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.29"); return buf;
        case THREAD_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.43"); return buf;
        case SETQUOTA_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.40"); return buf;
        case LOGOUT_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.23"); return buf;
        case CREATE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.6"); return buf;
        case SUBSCRIBE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.37"); return buf;
        case TOTAL_CONNECTIONS: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.1.1"); return buf;
        case ACTIVE_CONNECTIONS: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.1.2"); return buf;
        case DELETEACL_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.10"); return buf;
        case STORE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.34"); return buf;
        case FIND_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.14"); return buf;
        case AUTHENTICATE_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.0"); return buf;
        case PARTIAL_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.30"); return buf;
        case APPEND_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.1"); return buf;
        case COPY_COUNT: snprintf(buf,buflen,"1.3.6.1.4.1.3.2.2.3.1.4.5"); return buf;

    }

    return NULL;

}



#define SOCK_PATH "/tmp/.snmp_door"



static int mysock = -1;

static struct sockaddr_un remote;

static int sockaddr_len = 0;



static void snmp_send(char *str)

{

    if (mysock == -1) return;



    if (sendto(mysock, str, strlen(str), 0, (struct sockaddr *) &remote, sockaddr_len) == -1) {

	return;

    }



    return;

}



int snmp_connect(void)

{

    int s;

    int fdflags;

    int lup;



    if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {

	return 1;

    }



    for (lup=0;lup < 1+1; lup++)

        variable_tmpvalue[lup] = -1;



    remote.sun_family = AF_UNIX;

    strlcpy(remote.sun_path, SOCK_PATH, sizeof(remote.sun_path));

    sockaddr_len = strlen(remote.sun_path) + sizeof(remote.sun_family);



    /* put us in non-blocking mode */

    fdflags = fcntl(s, F_GETFD, 0);

    if (fdflags != -1) fdflags = fcntl(s, F_SETFL, O_NONBLOCK | fdflags);

    if (fdflags == -1) { close(s); return -1; }



    mysock = s;

    snmp_send("R 1.3.6.1.4.1.3.2.2.3.1.1\n");
    snmp_send("R 1.3.6.1.4.1.3.2.2.3.1.2\n");
    snmp_send("R 1.3.6.1.4.1.3.2.2.3.1.3\n");
    snmp_send("R 1.3.6.1.4.1.3.2.2.3.1.4\n");

    return 0;

}



int snmp_close(void)

{

    if (mysock > -1)

	close(mysock);



    return 0;

}



int snmp_increment_args(pushstats_t cmd, int incr, ...)

{

    char tosend[256]; /* xxx UDP max size??? */

    char buf[256];



      va_list ap; /* varargs thing */

      pushstats_variable_t vval;

      int ival;



      if (mysock == -1) return 1;



      va_start(ap, incr);



      do {

          vval = va_arg(ap, pushstats_variable_t); /* get the next arg */



          if (vval!=VARIABLE_LISTEND)

          {

              ival = va_arg(ap, int); /* get the next arg */

              variable_tmpvalue[vval] = ival;              

          }



      } while ( vval != VARIABLE_LISTEND);



      va_end(ap);



    snprintf(tosend, sizeof(tosend),"C %s %d\n",snmp_getoid(NULL,cmd,buf,sizeof(buf)), incr);



    if (sendto(mysock, tosend, strlen(tosend), 0, (struct sockaddr *) &remote, sockaddr_len) == -1) {

	return 1;

    }



    /* set tmp variables back */

    va_start(ap, incr);



      do {

          vval = va_arg(ap, pushstats_variable_t); /* get the next arg */



          if (vval!=VARIABLE_LISTEND)

          {

              ival = va_arg(ap, int); /* get the next arg */

              variable_tmpvalue[vval] = -1;              

          }



      } while ( vval != VARIABLE_LISTEND);



      va_end(ap);



    return 0;

}



int snmp_increment(pushstats_t cmd, int incr)

{

    char tosend[256]; /* xxx UDP max size??? */

    char buf[256];



    if (mysock == -1) return 1;



    snprintf(tosend, sizeof(tosend),"C %s %d\n",snmp_getoid(NULL,cmd,buf,sizeof(buf)), incr);



    if (sendto(mysock, tosend, strlen(tosend), 0, (struct sockaddr *) &remote, sockaddr_len) == -1) {

	return 1;

    }



    return 0;

}



int snmp_set(pushstats_t cmd, int value)

{

    char tosend[256];

    char buf[256];



    if (mysock == -1) return 1;



    snprintf(tosend, sizeof(tosend),"I %s %d\n",snmp_getoid(NULL,cmd,buf,sizeof(buf)), value);



    if (sendto(mysock, tosend, strlen(tosend), 0, (struct sockaddr *) &remote, sockaddr_len) == -1) {

	return 1;

    }



    return 1;

}



int snmp_set_str(pushstats_t cmd, char *value)

{

    char tosend[256];

    char buf[256];



    if (mysock == -1) return 1;



    snprintf(tosend, sizeof(tosend),"S %s %s\n",snmp_getoid(NULL,cmd,buf,sizeof(buf)), value);



    if (sendto(mysock, tosend, strlen(tosend), 0, (struct sockaddr *) &remote, sockaddr_len) == -1) {

	return 1;

    }



    return 1;

}



int snmp_set_time(pushstats_t cmd, time_t t)

{

    char tosend[256];

    char buf[256];



    if (mysock == -1) return 1;



    snprintf(tosend, sizeof(tosend),"T %s %lu\n",snmp_getoid(NULL,cmd,buf,sizeof(buf)), t);



    if (sendto(mysock, tosend, strlen(tosend), 0, (struct sockaddr *) &remote, sockaddr_len) == -1) {

	return 1;

    }



    return 1;

}



/* should use SNMPDEFINE's as parameter */

int snmp_set_oid(pushstats_t cmd, char *str)

{

   return snmp_set_str(cmd,str);

}



void snmp_setvariable(pushstats_variable_t name, int value)

{

    variable_value[name] = value;

}



#endif