+/*
+ * trace ends
+ * this function will put the trace to sockets and logfile, if requested
+ */
+void _end_trace(const char *__file, int __line)
+{
+ char *string;
+ FILE *fp;
+ struct admin_list *admin;
+ struct admin_queue *response, **responsep; /* response pointer */
+ int __attribute__((__unused__)) ret;
+
+ if (!trace.name[0])
+ PERROR("trace not started in file %s line %d\n", __file, __line);
+
+ if (options.deb || options.log[0]) {
+ string = print_trace(1, -1, NULL, NULL, NULL, 0);
+ if (string) {
+ /* process debug */
+ if (options.deb)
+ debug(NULL, NULL, 0, "TRACE", string);
+ /* process log */
+ if (options.log[0]) {
+ fp = fopen(options.log, "a");
+ if (fp) {
+ ret = fwrite(string, strlen(string), 1, fp);
+ fclose(fp);
+ }
+ }
+ }
+ }
+
+ /* process admin */
+ admin = admin_first;
+ while(admin) {
+ if (admin->trace.detail) {
+ string = print_trace(admin->trace.detail, admin->trace.port, admin->trace.interface, admin->trace.caller, admin->trace.dialing, admin->trace.category);
+ if (string) {
+ /* seek to end of response list */
+ response = admin->response;
+ responsep = &admin->response;
+ while(response) {
+ responsep = &response->next;
+ response = response->next;
+ }
+
+ /* create state response */
+ response = (struct admin_queue *)MALLOC(sizeof(struct admin_queue)+sizeof(admin_message));
+ memuse++;
+ response->num = 1;
+ /* message */
+ response->am[0].message = ADMIN_TRACE_RESPONSE;
+ SCPY(response->am[0].u.trace_rsp.text, string);
+
+ /* attach to response chain */
+ *responsep = response;
+ responsep = &response->next;
+ admin->fd.when |= LCR_FD_WRITE;
+ }
+ }
+ admin = admin->next;
+ }
+// fwrite(string, strlen(string), 1, fp);
+
+ memset(&trace, 0, sizeof(struct trace));
+}
+