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

Go to the documentation of this file.
00001 #include "niml.h"
00002 
00003 #undef  AFNI_SERVER
00004 #undef  AFNI_REQUEST
00005 
00006 /*! Stream name to connect to AFNI server. */
00007 
00008 #define AFNI_SERVER  "tcp:afni.nimh.nih.gov:80"
00009 
00010 /*! Format for AFNI logging request. */
00011 
00012 #define AFNI_REQUEST "HEAD /AFNIlogpath HTTP/1.0\r\n"  \
00013                      "User-Agent: %s\r\n\r\n"
00014 
00015 /*------------------------------------------------------------------------*/
00016 /*! Log the input string to the AFNI server.  Sends an HTTP request with
00017     the input string as the 'user agent', which will be saved in the
00018     Web server logs.
00019 --------------------------------------------------------------------------*/
00020 
00021 void AFNI_serverlog( char *str )
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: