Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

thd_logafni.c File Reference

#include "niml.h"

Go to the source code of this file.


Defines

#define AFNI_SERVER   "tcp:afni.nimh.nih.gov:80"
#define AFNI_REQUEST

Functions

void AFNI_serverlog (char *str)

Define Documentation

#define AFNI_REQUEST
 

Value:

"HEAD /AFNIlogpath HTTP/1.0\r\n"  \
                     "User-Agent: %s\r\n\r\n"
Format for AFNI logging request.

Definition at line 12 of file thd_logafni.c.

Referenced by AFNI_serverlog().

#define AFNI_SERVER   "tcp:afni.nimh.nih.gov:80"
 

Stream name to connect to AFNI server.

Definition at line 8 of file thd_logafni.c.

Referenced by AFNI_serverlog().


Function Documentation

void AFNI_serverlog char *    str
 

Log the input string to the AFNI server. Sends an HTTP request with the input string as the 'user agent', which will be saved in the Web server logs. --------------------------------------------------------------------------

Definition at line 21 of file thd_logafni.c.

References AFNI_noenv(), AFNI_REQUEST, AFNI_SERVER, malloc, NI_sleep(), NI_stream_closenow(), NI_stream_open(), NI_stream_write(), and NI_stream_writecheck().

00022 {
00023    pid_t child_pid ;
00024    NI_stream ns ;
00025    int nbuf=0 , jj ;
00026    char *sbuf , *rbuf , *ss ;
00027 
00028    if( str == NULL || *str == '\0'      ) return ;
00029    if( AFNI_noenv("AFNI_VERSION_CHECK") ) return ;
00030 
00031    /*-- start the child process --*/
00032 
00033    child_pid = fork() ;
00034    if( child_pid != (pid_t)0 ) return ;   /* parent is done */
00035 
00036    /*-- child will never return alive! --*/
00037 
00038    /* open stream to server */
00039 
00040    ns = NI_stream_open( AFNI_SERVER , "w" ) ;
00041    if( ns == (NI_stream)NULL ) _exit(0) ;
00042 
00043    /* copy input string, replace bad chars with spaces */
00044 
00045    sbuf = strdup(str) ;
00046    for( ss=sbuf ; *ss != '\0' ; ss++ ) if( !isgraph(*ss) ) *ss = ' ' ;
00047 
00048    /* truncate trailing spaces */
00049 
00050    nbuf = strlen(sbuf) ;
00051    for( ss=sbuf+(nbuf-1) ; isspace(*ss) ; ss-- ) *ss = '\0' ;
00052 
00053    /* build request to AFNI server */
00054 
00055    nbuf = strlen(sbuf)+strlen(AFNI_REQUEST)+32 ;
00056    rbuf = (char *)malloc(nbuf) ;
00057    sprintf(rbuf,AFNI_REQUEST,sbuf) ;
00058 
00059    /* wait for stream to get good for writing */
00060 
00061    jj = NI_stream_writecheck( ns , 1234 ) ;
00062    if( jj < 1 ) _exit(0) ;
00063 
00064    /* send the request */
00065 
00066    NI_stream_write( ns , rbuf , strlen(rbuf) ) ;
00067 
00068    /* don't read response: wait a decent interval, close connection, quit */
00069 
00070    NI_sleep(1) ; NI_stream_closenow(ns) ; _exit(0) ;
00071 }
 

Powered by Plone

This site conforms to the following standards: