int regex_content(const char * regex, const char * string1, std::list<std::string> &urls) { regex_t preg; int cflags = REG_ICASE; size_t size = 0; int errcode = 0; char errbuf[1024] = {0}; size_t errbuf_size = 1024; errcode = regcomp(&preg, regex, cflags); if (errcode != 0) { size = regerror(errcode, &preg, errbuf, errbuf_size); plog(error, "errcode = %d, %s(%lu)\n", errcode, errbuf, size); return 1; } regmatch_t pmatch[1]; size_t nmatch = 1; int eflags = REG_NOTBOL; while (errcode == 0) { do { errcode = regexec(&preg, string1, nmatch, pmatch, eflags); if (errcode == 0) { char sub_url[1024]; memset(sub_url, 0, sizeof sub_url); memcpy(sub_url, string1 + pmatch[0].rm_so, pmatch[0].rm_eo - pmatch[0].rm_so); if (strstr(sub_url, ".js")) { break; } if (strstr(sub_url, ".png")) { break; } if (strstr(sub_url, ".jpg")) { break; } if (strstr(sub_url, ".css")) { break; } if (strstr(sub_url, ".ico")) { break; } if (strstr(sub_url, "img")) { break; } if (strstr(sub_url, "cgi")) { break; } if (strstr(sub_url, "gif")) { break; } if (strstr(sub_url, "action.do")) { break; } if (strstr(sub_url, ".php")) { break; } if (strstr(sub_url, ".asp")) { break; } if (strstr(sub_url, ".aspx")) { break; } if (strstr(sub_url, ".jsp")) { break; } if (strstr(sub_url, "sta")) { break; } if (strstr(sub_url, "ccnt")) { break; } if (strstr(sub_url, ".svg")) { break; } if (strstr(sub_url, "?")) { break; } if (strstr(sub_url, ".org")) { break; } urls.push_back(sub_url); } } while (false); string1 += pmatch[0].rm_so + 1; } urls.unique(); regfree(&preg); return 0; }
void Vwr::CameraManipulator::setNewPosition(osg::Vec3d cameraTargetPoint, osg::Vec3d cameraInterestPoint, std::list<osg::ref_ptr<Data::Node> > selectedCluster, std::list<osg::ref_ptr<Data::Edge> > selectedEdges) { movingAutomatically = true; this->cameraTargetPoint = cameraTargetPoint; this->cameraInterestPoint = cameraInterestPoint; //cout << "Camera targetPoint: " << cameraTargetPoint.x() << " " << cameraTargetPoint.y() << " " << cameraTargetPoint.z() << "\n"; //cout << "Camera interest targetPoint: " << cameraInterestPoint.x() << " " << cameraInterestPoint.y() << " " << cameraInterestPoint.z() << "\n"; std::list<osg::ref_ptr<Data::Edge> >::iterator i; // prida hrany medzi body zaujmu for (i = selectedEdges.begin(); i != selectedEdges.end(); ++i) { selectedCluster.push_back((*i)->getSrcNode()); selectedCluster.push_back((*i)->getDstNode()); } selectedCluster.unique(); this->selectedCluster = selectedCluster; automaticMovementInitialized = false; }
// construct a list "file_to_delete" of old files. // Return number of files added to list, or negative for error. // int add_antiques_to_list(int days) { char command[256]; char single_line[1024]; FILE *fp; int dirlen=strlen(config.upload_dir); struct passwd *apache_info=getpwnam(config.httpd_user); int del_time=time(0)-86400*days; int nfiles=0; if (!apache_info) { log_messages.printf(MSG_CRITICAL, "default httpd_user '%s' found - add <httpd_user> entry in config.xml\n", config.httpd_user ); return -1; } log_messages.printf(MSG_DEBUG, "Searching for antique files older than %d days\n", days ); sprintf(command, "find %s -type f -mtime +%d -follow | head -%d", config.upload_dir, days, antique_limit); // Now execute the command, read output on a stream. We could use // find to also exec a 'delete' command. But we want to log all // file names into the log, and do lots of sanity checking, so // this way is better. // if (!(fp=popen(command, "r"))) { log_messages.printf(MSG_CRITICAL, "command %s failed\n", command ); return -2; } while (fgets(single_line, 1024, fp)) { char pathname[1024]; char *fname_at_end=NULL; int nchars=strlen(single_line); struct stat statbuf; const char *err=NULL; FILE_RECORD fr; // We can interrupt this at any point. // pclose() is called when process exits. check_stop_daemons(); // Do serious sanity checking on the path before // adding the file!! // if (!err && nchars > 1022) err="line too long"; if (!err && nchars < dirlen + 1) err="path shorter than upload directory name"; if (!err && single_line[nchars-1] != '\n') err="no newline terminator in line"; if (!err && strncmp(config.upload_dir, single_line, dirlen)) err="upload directory not in path"; if (!err && single_line[dirlen] != '/') err="no slash separator in path"; if (!err) single_line[nchars-1]='\0'; if (!err && stat(single_line, &statbuf)) err="stat failed"; if (!err && statbuf.st_mtime > del_time) err="file too recent"; if (!err && apache_info->pw_uid != statbuf.st_uid) err="file not owned by httpd user"; if (!err && !(fname_at_end=rindex(single_line+dirlen, '/'))) err="no trailing filename"; if (!err) fname_at_end++; if (!err && !strlen(fname_at_end)) err="trailing filename too short"; // skip NFS file system markers of form .nfs* // if (!err && !strncmp(fname_at_end, ".nfs", 4)) { log_messages.printf(MSG_CRITICAL, "Ignoring antique (stale) NFS lockfile %s\n", single_line ); continue; } if (!err && get_file_path(fname_at_end, config.upload_dir, config.uldl_dir_fanout, pathname)) err="get_file_path() failed"; if (!err && strcmp(pathname, single_line)) err="file in wrong hierarchical upload subdirectory"; if (err) { log_messages.printf(MSG_CRITICAL, "Can't list %s for deletion: %s\n", single_line, err ); // This file deleting business is SERIOUS. Give up at the // first sign of ANYTHING amiss. // pclose(fp); return -3; } // insert this file onto the list fr.date_modified = statbuf.st_mtime; fr.name = fname_at_end; files_to_delete.push_back(fr); nfiles++; } // while (fgets(single_line, 1024, fp)) { pclose(fp); log_messages.printf(MSG_DEBUG, "Found %d antique files to delete\n", nfiles ); files_to_delete.sort(); files_to_delete.unique(); return nfiles; }
void removesingle::remove_duplicate(std::list<production>& plist) { plist.unique(p_equal()); }
int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list) { /* * Use libdevinfo for determining all physical interfaces. */ di_node_t Root; Root = di_init("/", DINFOCACHE); if (Root != DI_NODE_NIL) { di_walk_minor(Root, DDI_NT_NET, 0, &list, vboxSolarisAddPhysHostIface); di_fini(Root); } /* * Use libdlpi for determining all DLPI interfaces. */ if (VBoxSolarisLibDlpiFound()) g_pfnLibDlpiWalk(vboxSolarisAddLinkHostIface, &list, 0); /* * This gets only the list of all plumbed logical interfaces. * This is needed for zones which cannot access the device tree * and in this case we just let them use the list of plumbed interfaces * on the zone. */ int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (Sock > 0) { struct lifnum IfNum; memset(&IfNum, 0, sizeof(IfNum)); IfNum.lifn_family = AF_INET; int rc = ioctl(Sock, SIOCGLIFNUM, &IfNum); if (!rc) { struct lifreq Ifaces[24]; struct lifconf IfConfig; memset(&IfConfig, 0, sizeof(IfConfig)); IfConfig.lifc_family = AF_INET; IfConfig.lifc_len = sizeof(Ifaces); IfConfig.lifc_buf = (caddr_t)&(Ifaces[0]); rc = ioctl(Sock, SIOCGLIFCONF, &IfConfig); if (!rc) { for (int i = 0; i < IfNum.lifn_count; i++) { /* * Skip loopback interfaces. */ if (!strncmp(Ifaces[i].lifr_name, "lo", 2)) continue; #if 0 rc = ioctl(Sock, SIOCGLIFADDR, &(Ifaces[i])); if (rc >= 0) { memcpy(Info.IPAddress.au8, ((struct sockaddr *)&Ifaces[i].lifr_addr)->sa_data, sizeof(Info.IPAddress.au8)); // SIOCGLIFNETMASK struct arpreq ArpReq; memcpy(&ArpReq.arp_pa, &Ifaces[i].lifr_addr, sizeof(struct sockaddr_in)); /* * We might fail if the interface has not been assigned an IP address. * That doesn't matter; as long as it's plumbed we can pick it up. * But, if it has not acquired an IP address we cannot obtain it's MAC * address this way, so we just use all zeros there. */ rc = ioctl(Sock, SIOCGARP, &ArpReq); if (rc >= 0) memcpy(&Info.MACAddress, ArpReq.arp_ha.sa_data, sizeof(Info.MACAddress)); char szNICDesc[LIFNAMSIZ + 256]; char *pszIface = Ifaces[i].lifr_name; strcpy(szNICDesc, pszIface); vboxSolarisAddLinkHostIface(pszIface, &list); } #endif char *pszIface = Ifaces[i].lifr_name; vboxSolarisAddLinkHostIface(pszIface, &list); } } } close(Sock); } /* * Weed out duplicates caused by dlpi_walk inconsistencies across Nevadas. */ list.sort(vboxSolarisSortNICList); list.unique(vboxSolarisSameNIC); return VINF_SUCCESS; }
//------------------------------------------------------------ //------------------------------------------------------------ //------------------------------------------------------------ void triangulate(std::list<Point> &pts, std::vector<Triangle> &tri, bool clockwise = false, double tol=.001){ pts.unique(); while ( !pts.empty() && pts.front() == pts.back() ){ pts.pop_back(); } if ( pts.size() < 3 ) return; //cycle by 1 to have a better looking output... pts.push_back(pts.front()); pts.pop_front(); std::list<Point>::iterator a,b,c,m; int sign = (clockwise ? -1 : 1 ); a = pts.end(); --a; b = pts.begin(); c = b; ++c; //now a,b,c are 3 consecutive points. if ( pts.size() == 3 ) { Triangle abc; abc.a = (*a); abc.b = (*b); abc.c = (*c); abc.area = sign *( cross((*b) - (*a),(*c) - (*b))/2) ; if ( abc.area >0 ){ tri.push_back(abc); pts.clear(); } return; } bool found = false; while( c != pts.end() ){ double abac = cross((*b)-(*a),(*c)-(*a)); if ( fabs(abac)<tol && dot( *b-*a, *c-*b ) <= 0) { //this is a degenerated triangle. Remove it and continue. pts.erase(b); triangulate(pts,tri,clockwise); return; } m = c; ++m; while ( m != pts.end() && !found && m!=a){ bool pointing_inside; double abam = cross((*b)-(*a),(*m)-(*a)); double bcbm = cross((*c)-(*b),(*m)-(*b)); if ( sign * abac > 0 ){ pointing_inside = ( sign * abam >= 0 ) && ( sign * bcbm >= 0 ); }else { pointing_inside = ( sign * abam >=0 ) || ( sign * bcbm >=0); } if ( pointing_inside ){ std::list<Point>::iterator p=c,q=++p; Point inter; while ( q != pts.end() && !intersect(*b,*m,*p,*q,inter) ){ p=q; ++q; } if ( q == pts.end() ){ found = true; }else{ ++m; } }else{ ++m; } } if ( found ){ std::list<Point>pts_beg; pts.insert(b,*b); pts.insert(m,*m); pts_beg.splice(pts_beg.begin(), pts, b, m); triangulate(pts_beg,tri,clockwise); triangulate(pts,tri,clockwise); return; }else{ a = b; b = c; ++c; } } //we should never reach this point. }