/* */ #include "chbgeo_svr.h" int Vofd = 0; int Wofd = 0; int MaxIdleTime = 300; char* MyIPaddr = NULL; char* MyIPaddrNum = NULL; char* ClIPaddr = NULL; char* ClIPaddrNum = NULL; tList* Allow_IPaddr = NULL; pid_t RootPID = 0; char* Hosts_Allow_File = "/usr/local/etc/chb_svr/hosts.allow"; int main(int argc, char** argv) { int i, j, cdlen; unsigned short vport=0; struct sockaddr_in cl_addr; struct sigaction sa; Buffer conffile, imgfile, pidfile; // 引数処理 conffile = make_Buffer(LNAME); imgfile = make_Buffer(LNAME); pidfile = make_Buffer(LNAME); for (i=1; istate>=5) { if (!strcasecmp("GET", rcv[0].buf)) { double lon = atof(rcv[1].buf); double lat = atof(rcv[2].buf); int ysize = atoi(rcv[3].buf); int xsize = atoi(rcv[4].buf); DEBUG_MODE print_message("CHB_SVR: (lon, lat) = (%f, %f), (width, height) = (%d, %d)\n", lon, lat, xsize, ysize); FSGraph alt = get_terrain_altitude(*ptr_ifd, lon, lat, xsize, ysize); if (alt.state==0) { unsigned long len = alt.xs*alt.ys*4; tcp_send(Wofd, (char*)alt.gp, len); } else { tcp_send_mesgln(Wofd, "ERROR"); } free_FSGraph(&alt); } else { tcp_send_mesgln(Wofd, "ERROR"); } } else { tcp_send_mesgln(Wofd, "ERROR"); } free_Buffer(rcv); freeNull(ClIPaddr); freeNull(ClIPaddrNum); close(Wofd); Wofd = 0; } // not reachable socket_close(Vofd); Vofd = 0; freeNull(MyIPaddr); exit(0); } FSGraph get_terrain_altitude(TIFF_ifd* ifd, double lon, double lat, int xsize, int ysize) { TIFF_ifd* ptr = NULL; FSGraph alt; MSGraph* mp = (MSGraph*)(ifd->ex_value); memset(&alt, 0, sizeof(FSGraph)); alt.state = -1; ptr= find_tiff_ifd(ifd, TIFF_TAG_WIDTH); int width = get_tiff_uint_field(ptr, 0); ptr = find_tiff_ifd(ifd, TIFF_TAG_HEIGHT); int height = get_tiff_uint_field(ptr, 0); ptr= find_tiff_ifd(ifd, TIFF_TAG_GEO_PXL_SCALE); double dlon = get_tiff_double_field(ptr, 0); double dlat = get_tiff_double_field(ptr, 1); ptr = find_tiff_ifd(ifd, TIFF_TAG_GEO_TIEPOINT); double mpxo = get_tiff_double_field(ptr, 0); double mpyo = get_tiff_double_field(ptr, 1); double lono = get_tiff_double_field(ptr, 3); double lato = get_tiff_double_field(ptr, 4); int mpxs = (int)( (lon - lono)/dlon + mpxo); int mpys = (int)(-(lat - lato)/dlat + mpyo); int mpxe = mpxs + xsize - 1; int mpye = mpys + ysize - 1; if (mpxs>=0 && mpxe=0 && mpyexs; for (i=0; igp)[xx]); } else { alt.gp[ii] = ((float*)mp->gp)[xx]; } } } } return alt; } ////////////////////////////////////////////////////////////////////////// // プログラムの終了 // void sigterm_process(int sig) { DEBUG_MODE print_message("SIGTERM_PROCESS: sigterm_process is called.\n"); // Socket if (Wofd>0) socket_close(Wofd); if (Vofd>0) socket_close(Vofd); Wofd = 0; Vofd = 0; exit(sig); }