Made listener_print be CONST
[freeradius.git] / src / main / detail.c
index 75d7f7b..5fdb575 100644 (file)
@@ -272,6 +272,9 @@ static int detail_open(rad_listen_t *this)
 
        data->client_ip.af = AF_UNSPEC;
        data->timestamp = 0;
+       data->offset = 0;
+       data->packets = 0;
+       data->tries = 0;
 
        return 1;
 }
@@ -367,6 +370,7 @@ int detail_recv(rad_listen_t *listener,
 
                case STATE_HEADER:
                do_header:
+                       data->tries = 0;
                        if (!data->fp) {
                                data->state = STATE_UNOPENED;
                                goto open_file;
@@ -457,6 +461,8 @@ int detail_recv(rad_listen_t *listener,
         *      Read a header, OR a value-pair.
         */
        while (fgets(buffer, sizeof(buffer), data->fp)) {
+               data->offset = ftell(data->fp); /* for statistics */
+
                /*
                 *      Badly formatted file: delete it.
                 *
@@ -566,11 +572,25 @@ int detail_recv(rad_listen_t *listener,
         */
        if (ferror(data->fp)) goto cleanup;
 
+       data->tries = 0;
+       data->packets++;
+
        /*
         *      Process the packet.
         */
  alloc_packet:
-       rad_assert(data->state == STATE_QUEUED);
+       data->tries++;
+       
+       /*
+        *      The writer doesn't check that the record was
+        *      completely written.  If the disk is full, this can
+        *      result in a truncated record.  When that happens,
+        *      treat it as EOF.
+        */
+       if (data->state != STATE_QUEUED) {
+               radlog(L_ERR, "Truncated record: treating it as EOF for detail file %s", data->filename_work);
+               goto cleanup;     
+       }
 
        /*
         *      We're done reading the file, but we didn't read
@@ -672,6 +692,17 @@ int detail_recv(rad_listen_t *listener,
                vp->vp_integer += time(NULL) - data->timestamp;
        }
 
+       /*
+        *      Set the transmission count.
+        */
+       vp = pairfind(packet->vps, PW_PACKET_TRANSMIT_COUNTER);
+       if (!vp) {
+               vp = paircreate(PW_PACKET_TRANSMIT_COUNTER, PW_TYPE_INTEGER);
+               rad_assert(vp != NULL);
+               pairadd(&packet->vps, vp);
+       }
+       vp->vp_integer = data->tries;
+
        *pfun = rad_accounting;
 
        if (debug_flag) {
@@ -709,13 +740,17 @@ void detail_free(rad_listen_t *this)
        listen_detail_t *data = this->data;
 
        free(data->filename);
+       data->filename = NULL;
        pairfree(&data->vps);
 
-       if (data->fp != NULL) fclose(data->fp);
+       if (data->fp != NULL) {
+               fclose(data->fp);
+               data->fp = NULL;
+       }
 }
 
 
-int detail_print(rad_listen_t *this, char *buffer, size_t bufsize)
+int detail_print(const rad_listen_t *this, char *buffer, size_t bufsize)
 {
        if (!this->server) {
                return snprintf(buffer, bufsize, "%s",
@@ -790,6 +825,7 @@ static const CONF_PARSER detail_config[] = {
        { NULL, -1, 0, NULL, NULL }             /* end the list */
 };
 
+extern int check_config;
 
 /*
  *     Parse a detail section.
@@ -801,6 +837,8 @@ int detail_parse(CONF_SECTION *cs, rad_listen_t *this)
        RADCLIENT       *client;
        char buffer[2048];
 
+       if (check_config) return 0;
+
        if (!this->data) {
                this->data = rad_malloc(sizeof(*data));
                memset(this->data, 0, sizeof(*data));