static PyObject* ccmapninfo(PyObject *xyz_data,PyObject *ninfo_data) { int i,j; PyObject *xyz_item1,*xyz_item2,*ninfo_item,*out_list,*out_list2; long ninfo_max=PyList_Size(ninfo_data); long icon,jcon; double nlength; double nowcontact=0.0,nowlength=0.0; long max=PyList_Size(xyz_data); out_list=PyList_New(max); long d2_list[max][max]; for(i=0;i<max;i++){ for(j=0;j<max;j++){ d2_list[j][i]=0; } } for(i=0;i<ninfo_max;i++){ ninfo_item=PyList_GetItem(ninfo_data,i); icon=PyInt_AsLong(PyList_GetItem(ninfo_item,0)); jcon=PyInt_AsLong(PyList_GetItem(ninfo_item,1)); nlength=PyFloat_AsDouble(PyList_GetItem(ninfo_item,2)); xyz_item1=PyList_GetItem(xyz_data,icon-1); xyz_item2=PyList_GetItem(xyz_data,jcon-1); nowlength=clength(PyFloat_AsDouble(PyList_GetItem(xyz_item1,0)), PyFloat_AsDouble(PyList_GetItem(xyz_item1,1)), PyFloat_AsDouble(PyList_GetItem(xyz_item1,2)), PyFloat_AsDouble(PyList_GetItem(xyz_item2,0)), PyFloat_AsDouble(PyList_GetItem(xyz_item2,1)), PyFloat_AsDouble(PyList_GetItem(xyz_item2,2))); if(nowlength<nlength*1.2){ d2_list[icon-1][jcon-1]=1; d2_list[jcon-1][icon-1]=1; } } for(i=0;i<max;i++){ out_list2=PyList_New(max); for(j=0;j<max;j++){ PyList_SetItem(out_list2,j,PyInt_FromLong(d2_list[i][j])); } PyList_SetItem(out_list,i,out_list2); } return out_list; }
//-------------------------------------------------------------------------------------------------- void generateResponse(int socket, char* filename, int lengthfile) { char response[512]; char *status = STATUS_200; char *server = "Server: FNU Pramono/1.0 (WIN 32)\r\n"; char *connection_status = "Connection: closed\r\n"; file_extension fe = determineTypeOfFile(filename); char *string_fe = changeExtensionToString (fe); strcpy(response, status); strcat(response, datetime()); strcat(response, server); strcat(response, lastModified(filename)); strcat(response, clength(lengthfile)); strcat(response, string_fe); strcat(response, connection_status); printf("\n\nresponse: %s\n\n", response); }
int geo_find2(geo_ctx_t* geo_ctx, uint32_t ip, geo_result_t* result) { assert(geo_ctx->ptr != NULL); geo_head_t* geo_head = (geo_head_t*)geo_ctx->ptr; geo_item_t* items = (geo_item_t*)(geo_ctx->ptr + geo_head->geo_item_offset); /** printf("### geo_head: const_count:%u," "const_table_offset:%u," "geo_item_count:%u," "geo_item_offset:%u\n" "filesize: %u\n", geo_head->const_count, geo_head->const_table_offset, geo_head->geo_item_count, geo_head->geo_item_offset, geo_head->filesize); **/ if(geo_head->filesize != geo_ctx->size){ printf("INFO: geo data file changed! filesize(%u) change to : %u\n", geo_ctx->size, geo_head->filesize); geo_ctx->size = geo_head->filesize; } int size = geo_head->geo_item_count; if(size < 1){ return -1; } int High = size - 1; int Low = 0; int M; #define IP_EQ(ip, node) (ip>=node.ip_begin && ip <=node.ip_end) geo_item_t* find_item = NULL; while(Low<=High) { M = (Low + High)/2; if(ip<items[M].ip_begin){ High = M-1; }else if(ip>items[M].ip_end){ Low = M+1; }else if(IP_EQ(ip, items[M])) { find_item = &items[M]; break; } } if(find_item == NULL){ return -1; } result->ip_begin = find_item->ip_begin; result->ip_end = find_item->ip_end; const_index_t* indexs = (const_index_t*)(geo_ctx->ptr + sizeof(geo_head_t)); const char* buf = geo_ctx->ptr + geo_head->const_table_offset; result->province = cvalue(indexs, buf, find_item->province); result->province_len = clength(indexs, find_item->province)-1; result->city= cvalue(indexs, buf, find_item->city); result->city_len = clength(indexs, find_item->city)-1; result->isp = cvalue(indexs, buf, find_item->isp); result->isp_len = clength(indexs, find_item->isp)-1; return 0; }