eXpress “1.5”

src/update_check.h

00001 
00008 #include <signal.h>
00009 #include <strings.h>
00010 #include <sys/socket.h>
00011 #include <netinet/in.h>
00012 #include <netdb.h>
00013 
00014 int NUM_SEPS = 3;
00015 int CONNECT_TIMEOUT = 5;
00016 
00017 static int sTimeout = 0;
00018 
00019 static void AlarmHandler(int sig)
00020 
00021 {
00022 
00023    sTimeout = 1;
00024 
00025 }
00026 
00027 bool error(const char *msg)
00028 {
00029    return false;
00030 }
00031 
00032 int parse_version_str(char* version_str)
00033 {
00034    int version_int = 0;
00035    char* token = strtok(version_str,".");
00036     for(int i = 0; i < NUM_SEPS; ++i)
00037     {
00038       version_int += atoi(token)*(int)pow(100.,NUM_SEPS-i);
00039    }
00040    return version_int;
00041 }
00042 
00043 bool get_current_version(char* curr_version)
00044 {
00045     int sockfd, portno, n;
00046     struct sockaddr_in serv_addr;
00047     struct hostent *server;
00048    
00049     portno = 80;
00050     sockfd = socket(AF_INET, SOCK_STREAM, 0);
00051     if (sockfd < 0)
00052 
00053         return error("ERROR opening socket");
00054    
00055     server = gethostbyname("bio.math.berkeley.edu");
00056     if (server == NULL)
00057 
00058         return error("ERROR, no such host");
00059 
00060     bzero((char *) &serv_addr, sizeof(serv_addr));
00061     serv_addr.sin_family = AF_INET;
00062     bcopy((char *)server->h_addr,
00063 
00064         (char *)&serv_addr.sin_addr.s_addr,
00065         server->h_length);
00066     serv_addr.sin_port = htons(portno);
00067 
00068    signal(SIGALRM, AlarmHandler);
00069 
00070    sTimeout = 0;
00071 
00072    alarm(CONNECT_TIMEOUT);
00073 
00074    
00075    int ret;
00076    ret = connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
00077    if (ret < 0 || sTimeout)
00078    {
00079       return error("ERROR connecting");
00080    }
00081    
00082    char buffer[1024];
00083    strcpy(buffer, "GET /eXpress/curr_xprs_version HTTP/1.1\nHost: bio.math.berkeley.edu\n\n");
00084    n = (int)write(sockfd,buffer,1024);
00085    
00086     if (n < 0)
00087 
00088       return error("ERROR writing to socket");
00089    bzero(curr_version, sizeof(curr_version));
00090     n = (int)read(sockfd,buffer,1024);
00091     if (n < 0)
00092 
00093       return error("ERROR reading from socket");
00094 
00095    char* token;
00096    token = strtok(buffer, "$");
00097    token = strtok(NULL, "$");
00098    if (token==NULL)
00099       return error("ERROR parsing response");
00100    
00101    strcpy(curr_version, token);
00102       
00103    return true;
00104 }
00105 
00106 void check_version(const char* this_version)
00107 {
00108    char curr_version[256];
00109     memset(curr_version, 0, sizeof(curr_version));
00110    if (get_current_version(curr_version))
00111    {
00112       if (strcmp(curr_version, this_version)==0) {
00113          fprintf(stderr, "You are using eXpress v%s, which is the most recent release.\n\n", PACKAGE_VERSION);
00114       } else {
00115          fprintf(stderr, "WARNING: Your version of eXpress is not up-to-date. It is recommended that you upgrade to v%s to benefit from the most recent features and bug fixes (http://bio.math.berkeley.edu/eXpress).\n\n", curr_version);
00116     }
00117    } else {
00118       fprintf(stderr, "WARNING: Could not connect to update server to verify current version. Please check at the eXpress website (http://bio.math.berkeley.edu/eXpress).\n\n");
00119    }
00120 }
 All Classes Functions Variables