Exemplo n.º 1
0
/**
 * Mark clients as having sent status as specified by PRSTATUS
 */
void set_proxy_status(struct finfo_t *finfo, const unsigned char *data,
                      int hostidx, int nak_count)
{
    struct prstatus_h *prstatus;
    uint32_t *addrlist;
    int clientcnt, clientidx, dupmsg, i;

    prstatus = (struct prstatus_h *)data;
    addrlist = (uint32_t *)(data + sizeof(struct prstatus_h));

    clientcnt = ntohs(prstatus->destcount);
    for (i = 0; i < clientcnt; i++) {
        clientidx = find_client(addrlist[i]);
        if (clientidx == -1) {
            log1(0, 0, "Client %s via proxy %s not found",
                       inet_ntoa(to_addr(addrlist[i])), destlist[hostidx].name);
        } else if (destlist[clientidx].proxyidx != hostidx) {
            log1(0, 0, "Client %s found via proxy %s, expected proxy %s",
                        destlist[clientidx].name,
                        destlist[destlist[clientidx].proxyidx].name,
                        destlist[hostidx].name);
        } else if (!client_error(clientidx)) {
            dupmsg = (destlist[clientidx].status == DEST_ACTIVE);
            destlist[clientidx].status = DEST_ACTIVE;
            log(0, 0, "  For client%s %s", dupmsg ? "+" : "",
                       destlist[clientidx].name);
            if (!dupmsg) {
                finfo->deststate[clientidx].naks += nak_count;
            }
        }
    }
}
Exemplo n.º 2
0
bool Sound::play(void)
{
  bool success=false;
  int rc;

  if (!tune || ! (tune->size() > 0)) {
    log2 ("no tune file set, or a play is in progress (tune, playing)", tune, playing);
  }
  else {
    // Call external tool with the sound file
    playing = true;

    string sound_cmdline;
    sound_cmdline  = "/usr/bin/aplay ";
    sound_cmdline += tune->c_str();
    sound_cmdline += " &";
    log1 ("Playing sound cmdline:", sound_cmdline);

    // protect against eventual race condition
    tune_tmp=tune;
    tune = NULL;
    delete (tune_tmp);

    rc = system (sound_cmdline.c_str());
    log1 ("Sound played (return code)", rc);
    success = (rc == 0 ? true : false);
    playing = false;
  }

  return success;
}
Exemplo n.º 3
0
/**
 * Do basic checking on a received packet, like checking the version
 * and making sure the size matches the size in the header.
 * Returns 1 on success, 0 on fail.
 */
int validate_packet(const unsigned char *packet, int len,
                    const struct finfo_t *finfo)
{
    struct uftp_h *header;

    header = (struct uftp_h *)packet;
    if ((header->uftp_id != UFTP_VER_NUM) &&
            (header->uftp_id != UFTP_3_0_VER)) {
        log1(0, 0, "Invalid version %02X", header->uftp_id);
        return 0;
    }
    if (len - sizeof(struct uftp_h) != ntohs(header->blsize)) {
        log1(0, 0, "Invalid packet size %d, expected %d",
                    len - sizeof(struct uftp_h), ntohs(header->blsize));
        return 0;
    }
    if (ntohl(header->group_id) != finfo->group_id) {
        log1(0, 0, "Invalid group ID %08X, expected %08X",
                    ntohl(header->group_id), finfo->group_id);
        return 0;
    }
    if ((header->func == ENCRYPTED) && (keytype == KEY_NONE)) {
        log1(0, 0, "Received encrypted packet with encryption disabled");
        return 0;
    }
    return 1;
}
Exemplo n.º 4
0
w_Targs* cpiPython::SQL (int id, w_Targs* args) // (char *query)
{
	char *query;
	string q;
	long limit;
	if (!lib_begin || !lib_pack || !lib_unpack || !lib_packprint || !mQuery) return NULL;
	if (!lib_unpack(args, "sl", &query, &limit)) return NULL;
	if (!query) return NULL;
	if (limit < 1) limit = 100;
	log4("PY: SQL   query: %s\n", query);
	q = string() + query;
	mQuery->OStream() << q;
	if (mQuery->Query() < 0) { mQuery->Clear(); return lib_pack("lllp", (long)0, (long)0, (long)0, (void*)NULL); }  // error
	int rows = mQuery->StoreResult();
	if (limit < rows) rows = limit;
	if (rows < 1) { mQuery->Clear(); return lib_pack("lllp", (long)1, (long)0, (long)0, (void*)NULL); }
	int cols = mQuery->Cols();
	char * nil = (char*)"NULL";
	char ** res = (char **) calloc (cols*rows, sizeof(char*));
	if (!res) { log1("PY: SQL   malloc failed\n"); mQuery->Clear(); return lib_pack("lllp", (long)0, (long)0, (long)0, (void*)NULL); }
	for (int r = 0 ; r < rows; r++)
	{
		mQuery->DataSeek(r);
		MYSQL_ROW row;
		row = mQuery->Row();
		if (!row)
		{ log1("PY: SQL   failed to fetch row: %d\n", r); mQuery->Clear(); free(res); return lib_pack("lllp", (long)0, (long)0, (long)0, (void*)NULL); }

		for (int i = 0; i < cols; i++)
			res[(r*cols)+i] = strdup( (row[i]) ? row[i] : nil );
	}
	mQuery->Clear();
	return lib_pack("lllp", (long)1, (long)rows, (long)cols, (void*)res);
}
Exemplo n.º 5
0
/**
 * Process an KEY_REQ message
 */
void handle_key_req(const union sockaddr_u *src,
                    const unsigned char *packet, unsigned packetlen)
{
    const struct key_req_h *keyreq;
    struct timeval current_timestamp;
    char destname[INET6_ADDRSTRLEN];
    int rval;

    keyreq = (const struct key_req_h *)(packet + sizeof(struct uftp_h));

    if ((rval = getnameinfo((const struct sockaddr *)src, family_len(*src),
            destname, sizeof(destname), NULL, 0, NI_NUMERICHOST)) != 0) {
        log1(0, 0, 0, "getnameinfo failed: %s", gai_strerror(rval));
    }
    if ((packetlen < sizeof(struct uftp_h) + (keyreq->hlen * 4U)) ||
            ((keyreq->hlen * 4U) < sizeof(struct key_req_h))) {
        log1(0,0,0,"Rejecting KEY_REQ from %s: invalid message size", destname);
        return;
    }
    log2(0, 0, 0, "Received KEY_REQ from %s", destname);

    gettimeofday(&current_timestamp, NULL);
    if (diff_sec(current_timestamp, last_key_req) > KEY_REQ_LIMIT) {
        send_proxy_key();
    }
}
Exemplo n.º 6
0
static void SetCachedVariant( DBVARIANT* s /* new */, DBVARIANT* d /* cached */ )
{
	char* szSave = ( d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ ) ? d->pszVal : NULL;

	memcpy( d, s, sizeof( DBVARIANT ));
	if (( s->type == DBVT_UTF8 || s->type == DBVT_ASCIIZ ) && s->pszVal != NULL ) {
		if ( szSave != NULL )
			d->pszVal = (char*)HeapReAlloc(hCacheHeap,0,szSave,strlen(s->pszVal)+1);
		else
			d->pszVal = (char*)HeapAlloc(hCacheHeap,0,strlen(s->pszVal)+1);
		strcpy(d->pszVal,s->pszVal);
	}
	else if ( szSave != NULL )
		HeapFree(hCacheHeap,0,szSave);

#ifdef DBLOGGING
	switch( d->type ) {
		case DBVT_BYTE:	log1( "set cached byte: %d", d->bVal ); break;
		case DBVT_WORD:	log1( "set cached word: %d", d->wVal ); break;
		case DBVT_DWORD:	log1( "set cached dword: %d", d->dVal ); break;
		case DBVT_UTF8:
		case DBVT_ASCIIZ: log1( "set cached string: '%s'", d->pszVal ); break;
		default:				log1( "set cached crap: %d", d->type ); break;
	}
#endif
}
Exemplo n.º 7
0
Arquivo: libQF.c Projeto: cran/MixSim
   static double truncation(double u, double tausq)
   /* bound integration error due to truncation at u */
   {
      double sum1, sum2, prod1, prod2, prod3, lj, ncj,
         x, y, err1, err2;
      int j, nj, s;

      counter();
      sum1  = 0.0; prod2 = 0.0;  prod3 = 0.0;  s = 0;
      sum2 = (sigsq + tausq) * square(u); prod1 = 2.0 * sum2;
      u = 2.0 * u;
      for (j=0; j<r; j++ )
      {
         lj = lb[j];  ncj = nc[j]; nj = n[j];
         x = square(u * lj);
         sum1 = sum1 + ncj * x / (1.0 + x);
         if (x > 1.0)
         {
            prod2 = prod2 + nj * log(x);
            prod3 = prod3 + nj * log1(x, TRUE );
            s = s + nj;
         }
         else  prod1 = prod1 + nj * log1(x, TRUE );
      }
      sum1 = 0.5 * sum1;
      prod2 = prod1 + prod2;  prod3 = prod1 + prod3;
      x = exp1(-sum1 - 0.25 * prod2) / pi;
      y = exp1(-sum1 - 0.25 * prod3) / pi;
      err1 =  ( s  ==  0 )  ? 1.0 : x * 2.0 / s;
      err2 =  ( prod3 > 1.0 )  ? 2.5 * y : 1.0;
      if (err2 < err1) err1 = err2;
      x = 0.5 * sum2;
      err2 =  ( x  <=  y )  ? 1.0  : y / x;
      return  ( err1 < err2 )  ? err1  :  err2;
   }
Exemplo n.º 8
0
/* Send a packet to a specific mac address and ip address by creating our own ip packet */
static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadcast)
{
	const uint8_t *chaddr;
	uint32_t ciaddr;

	// Was:
	//if (force_broadcast) { /* broadcast */ }
	//else if (dhcp_pkt->ciaddr) { /* unicast to dhcp_pkt->ciaddr */ }
	//else if (dhcp_pkt->flags & htons(BROADCAST_FLAG)) { /* broadcast */ }
	//else { /* unicast to dhcp_pkt->yiaddr */ }
	// But this is wrong: yiaddr is _our_ idea what client's IP is
	// (for example, from lease file). Client may not know that,
	// and may not have UDP socket listening on that IP!
	// We should never unicast to dhcp_pkt->yiaddr!
	// dhcp_pkt->ciaddr, OTOH, comes from client's request packet,
	// and can be used.

	if (force_broadcast
	 || (dhcp_pkt->flags & htons(BROADCAST_FLAG))
	 || dhcp_pkt->ciaddr == 0
	) {
		log1("Broadcasting packet to client");
		ciaddr = INADDR_BROADCAST;
		chaddr = MAC_BCAST_ADDR;
	} else {
		log1("Unicasting packet to client ciaddr");
		ciaddr = dhcp_pkt->ciaddr;
		chaddr = dhcp_pkt->chaddr;
	}

	udhcp_send_raw_packet(dhcp_pkt,
		/*src*/ server_config.server_nip, SERVER_PORT,
		/*dst*/ ciaddr, CLIENT_PORT, chaddr,
		server_config.ifindex);
}
Exemplo n.º 9
0
int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac, uint16_t *mtu)
{
	/* char buffer instead of bona-fide struct avoids aliasing warning */
	char ifr_buf[sizeof(struct ifreq)];
	struct ifreq *const ifr = (void *)ifr_buf;

	int fd;
	struct sockaddr_in *our_ip;

	memset(ifr, 0, sizeof(*ifr));
	fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);

	ifr->ifr_addr.sa_family = AF_INET;
	strncpy_IFNAMSIZ(ifr->ifr_name, interface);
	if (nip) {
		if (ioctl_or_perror(fd, SIOCGIFADDR, ifr,
			"is interface %s up and configured?", interface)
		) {
			close(fd);
			return -1;
		}
		our_ip = (struct sockaddr_in *) &ifr->ifr_addr;
		*nip = our_ip->sin_addr.s_addr;
		log1("IP %s", inet_ntoa(our_ip->sin_addr));
	}

	if (ifindex) {
		if (ioctl_or_warn(fd, SIOCGIFINDEX, ifr) != 0) {
			close(fd);
			return -1;
		}
		log1("Adapter index %d", ifr->ifr_ifindex);
		*ifindex = ifr->ifr_ifindex;
	}

	if (mac) {
		if (ioctl_or_warn(fd, SIOCGIFHWADDR, ifr) != 0) {
			close(fd);
			return -1;
		}
		memcpy(mac, ifr->ifr_hwaddr.sa_data, 6);
		log1("MAC %02x:%02x:%02x:%02x:%02x:%02x",
			mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
	}

	if (mtu) {
		if (ioctl_or_warn(fd, SIOCGIFMTU, ifr) != 0) {
			close(fd);
			return -1;
		}
		log1("Adapter mtu %d", ifr->ifr_mtu);
		*mtu = ifr->ifr_mtu;
	}

	close(fd);
	return 0;
}
Exemplo n.º 10
0
/**
 * Print the final statistics for the given file
 */
void print_status(const struct finfo_t *finfo, struct timeval start_time)
{
    struct timeval done_time;
    double elapsed_time;
    int i;

    if (sync_mode) {
        print_sync_status(finfo, start_time);
        return;
    }

    if (finfo->file_id == 0) {
        log0(0, 0, "Group complete");
        return;
    }

    log0(0, 0, "Transfer status:");
    for (done_time = start_time, i = 0; i < destcount; i++) {
        if (destlist[i].clientcnt >= 0) {
            continue;
        }
        clog0(0, 0, "Host: %-15s  Status: ", destlist[i].name);
        switch (destlist[i].status) {
        case DEST_MUTE:
            slog0("Mute");
            break;
        case DEST_LOST:
            slog0("Lost connection");
            break;
        case DEST_ABORT:
            slog0("Aborted");
            break;
        case DEST_DONE:
            if (destlist[i].comp_status == COMP_STAT_REJECTED) {
                slog0("Rejected");
                break;
            }
            if (diff_usec(finfo->deststate[i].time, done_time) > 0) {
                done_time = finfo->deststate[i].time;
            }
            elapsed_time = (double)diff_usec(finfo->deststate[i].time,
                                             start_time) / 1000000;
            slog0("Completed   time: %7.3f seconds    NAKs: %d",
                 elapsed_time, finfo->deststate[i].naks);
            break;
        default:
            slog0("Unknown  code: %d", destlist[i].status);
            break;
        }
    }
    elapsed_time = (double)diff_usec(done_time, start_time) / 1000000;
    log1(0, 0, "Total elapsed time: %.3f seconds", elapsed_time);
    log1(0, 0, "Overall throughput: %.2f KB/s",
               (elapsed_time != 0) ? (finfo->size / elapsed_time / 1024) : 0);
}
Exemplo n.º 11
0
void cls(uint8_t	Port)
{
	if(Port==1)
	{
		log1(ESC_ERASE_DISPLAY);
		log1(ESC_CURSOR_POS(0,0));
	}
	else
	{
		log0(ESC_ERASE_DISPLAY);
		log0(ESC_CURSOR_POS(0,0));
	}
}
Exemplo n.º 12
0
/* Read a packet from socket fd, return -1 on read error, -2 on packet error */
int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
{
	int bytes;
	unsigned char *vendor;

	memset(packet, 0, sizeof(*packet));
	bytes = safe_read(fd, packet, sizeof(*packet));
	if (bytes < 0) {
		log1("Packet read error, ignoring");
		return bytes; /* returns -1 */
	}

	if (packet->cookie != htonl(DHCP_MAGIC)) {
		bb_info_msg("Packet with bad magic, ignoring");
		return -2;
	}
	log1("Received a packet");
	udhcp_dump_packet(packet);

	if (packet->op == BOOTREQUEST) {
		vendor = udhcp_get_option(packet, DHCP_VENDOR);
		if (vendor) {
#if 0
			static const char broken_vendors[][8] = {
				"MSFT 98",
				""
			};
			int i;
			for (i = 0; broken_vendors[i][0]; i++) {
				if (vendor[OPT_LEN - OPT_DATA] == (uint8_t)strlen(broken_vendors[i])
				 && strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - OPT_DATA]) == 0
				) {
					log1("Broken client (%s), forcing broadcast replies",
						broken_vendors[i]);
					packet->flags |= htons(BROADCAST_FLAG);
				}
			}
#else
			if (vendor[OPT_LEN - OPT_DATA] == (uint8_t)(sizeof("MSFT 98")-1)
			 && memcmp(vendor, "MSFT 98", sizeof("MSFT 98")-1) == 0
			) {
				log1("Broken client (%s), forcing broadcast replies", "MSFT 98");
				packet->flags |= htons(BROADCAST_FLAG);
			}
#endif
		}
	}

	return bytes;
}
Exemplo n.º 13
0
/**
 * Process an ABORT message
 */
void handle_abort(const unsigned char *message, int meslen, int idx,
                  struct finfo_t *finfo, const struct in_addr *hostaddr)
{
    struct abort_h *abort;
    int i;

    abort = (struct abort_h *)message;
    if (meslen != sizeof(struct abort_h)) {
        log1(0, 0, "Rejecting ABORT from %s: invalid message size",
                   (idx == -1) ? inet_ntoa(*hostaddr) : destlist[idx].name);
        return;
    }
    if (idx == -1) {
        log1(0, 0, "Transfer aborted by %s: %s",
                    inet_ntoa(*hostaddr), abort->message);
        return;
    }

    if (abort->host != 0) {
        idx = find_client(abort->host);
    }
    if (idx == -1) {
        log1(0, 0, "Transfer aborted by %s: %s",
                    inet_ntoa(*hostaddr), abort->message);
    } else {
        destlist[idx].status = DEST_ABORT;
        log1(0, 0, "Transfer aborted by %s: %s",
                    destlist[idx].name, abort->message);
    }
    if (quit_on_error) {
        log0(0, 0, "Aboring all clients");
        send_abort(finfo, "A client aborted, aborting all",
                &receive_dest, NULL, 0);
        // If encryption enabled, send ABORT both encrypted and unencrypted
        // since we can't be sure what phase we're currently in.
        if (keytype != KEY_NONE) {
            send_abort(finfo, "A client aborted, aborting all",
                    &receive_dest, NULL, 1);
        }
        for (i = 0; i < destcount; i++) {
            if ((destlist[i].status == DEST_ACTIVE) ||
                    (destlist[i].status == DEST_REGISTERED) ||
                    (destlist[i].status == DEST_STATUS)) {
                destlist[i].status = DEST_ABORT;
            }
        }
    }
}
Exemplo n.º 14
0
Arquivo: libQF.c Projeto: cran/MixSim
   static void integrate(int nterm, double interv, double tausq, BOOL mainx)
   /*  carry out integration with nterm terms, at stepsize
      interv.  if (! mainx) multiply integrand by
         1.0-exp(-0.5*tausq*u^2) */
   {
      double inpi, u, sum1, sum2, sum3, x, y, z;
      int k, j, nj;
      inpi = interv / pi;
      for ( k = nterm; k>=0; k--)
      {
         u = (k + 0.5) * interv;
         sum1 = - 2.0 * u * c;  sum2 = fabs(sum1);
         sum3 = - 0.5 * sigsq * square(u);
         for ( j = r-1; j>=0; j--)
         {
            nj = n[j];  x = 2.0 * lb[j] * u;  y = square(x);
            sum3 = sum3 - 0.25 * nj * log1(y, TRUE );
            y = nc[j] * x / (1.0 + y);
            z = nj * atan(x) + y;
            sum1 = sum1 + z;   sum2 = sum2 + fabs(z);
            sum3 = sum3 - 0.5 * x * y;
         }
         x = inpi * exp1(sum3) / u;
	 if ( !  mainx )
         x = x * (1.0 - exp1(-0.5 * tausq * square(u)));
         sum1 = sin(0.5 * sum1) * x;  sum2 = 0.5 * sum2 * x;
         intl = intl + sum1; ersm = ersm + sum2;
      }
   }
Exemplo n.º 15
0
bool cpiPython::CallAll(int func, w_Targs* args)  // the default handler: returns true unless the calback returns 0
{
	if (!online) return true;
	w_Targs* result;
	bool ret = true;
	long l;
	if (func != W_OnTimer) log2("PY: CallAll %s: parameters %s\n", lib_hookname(func), lib_packprint(args))  // no ';' since this would break 'else'
	else log4("PY: CallAll %s\n", lib_hookname(func));
	if(Size())
	{
		tvPythonInterpreter::iterator it;
		for(it = mPython.begin(); it != mPython.end(); ++it)
		{
			result = (*it)->CallFunction(func, args);
			if(!result)
			{
				// callback doesn't exist or a failure
				if (func != W_OnTimer) log4("PY: CallAll %s: returned NULL\n", lib_hookname(func));
				continue;
			}
			if(lib_unpack(result, "l", &l))  // default return value is 1L meaning: further processing,
			{
				if (func != W_OnTimer) log3("PY: CallAll %s: returned l:%ld\n", lib_hookname(func), l);
				if (!l) ret = false;  // 0L means no more processing outside this plugin
			}
			else   // something unknown was returned... we will let the hub call other plugins
			{
				log1("PY: CallAll %s: unexpected return value %s\n", lib_hookname(func), lib_packprint(result));
			}
			free(result);
		}
	}
	free(args); // WARNING: args is freed, do not try to access it after calling CallAll!
	return ret;
}
Exemplo n.º 16
0
int _tmain(int argc, _TCHAR* argv[])
{
    ::CoInitialize(0);
    log1();
    ::CoUninitialize();
	return 0;
}
Exemplo n.º 17
0
bool cpiPython::OnParsedMsgChat(cConnDC *conn, cMessageDC *msg)
{
	if (!online) return true;
	if((conn != NULL) && (conn->mpUser != NULL) && (msg != NULL))
	{
		int func = W_OnParsedMsgChat;
		w_Targs* args = lib_pack( "ss", conn->mpUser->mNick.c_str(), msg->ChunkString(eCH_CH_MSG).c_str());
		log2("PY: Call %s: parameters %s\n", lib_hookname(func), lib_packprint(args));
		bool ret = true;
		w_Targs *result;
		long l;
		char *nick = NULL;
		char *message = NULL;

		if(Size())
		{
			tvPythonInterpreter::iterator it;
			for(it = mPython.begin(); it != mPython.end(); ++it)
			{
				result = (*it)->CallFunction(func, args);
				if(!result)
				{
					log3("PY: Call %s: returned NULL\n", lib_hookname(func));
					continue;
				}
				if(lib_unpack(result, "l", &l))  // default return value is 1L meaning: further processing,
				{
					log3("PY: Call %s: returned l:%ld\n", lib_hookname(func), l);
					if (!l) ret = false;  // 0L means no more processing outside this plugin
				}
				else if (lib_unpack(result, "ss", &nick, &message))  // script wants to change nick or contents of the message
				{
					// normally you would use SendDataToAll and return 0 from your script
					// but this kind of message modification allows you to process it not by just one but as many scripts as you want
					log2("PY: modifying message - Call %s: returned %s\n", lib_hookname(func), lib_packprint(result));
					if (nick)
					{
						string &nick0 = msg->ChunkString(eCH_CH_NICK);
						nick0 = nick;
						msg->ApplyChunk(eCH_CH_NICK);
					}
					if (message)
					{
						string &message0 = msg->ChunkString(eCH_CH_MSG);
						message0 = message;
						msg->ApplyChunk(eCH_CH_MSG);
					}
					ret = true;  // we've changed the message so we want the hub to process it and send it
				}
				else   // something unknown was returned... we will let the hub call other plugins
					log1("PY: Call %s: unexpected return value: %s\n", lib_hookname(func), lib_packprint(result));
				free(result);
			}
		}
		free(args);
		return ret;

	}
	return true;
}
Exemplo n.º 18
0
/* @Core */
Mat PDCounter::detect(Mat& input) {
    string log1("Begin detecting...\n");
    Mat output = input.clone();
    for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) {
        (*it).detect(output, Trackers);// NO parallel
    }
    string log2("All areas are detected...\n");

    string lost = i_to_s(Trackers.tracking(output)); // NO parallel

    string log3("Tracking completed...\nThe trackers lost " + lost + " pedestrians in this frame.\n");

    if (showPedestrian) {
        drawFounds(output, Trackers.getCurrRects(), PEDESTRIAN_COLOR);
    }
    if (showArea) {
        for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) {
            drawArea(output, (*it).getArea(), AREA_COLOR);
        }
    }
    if (showTrajectory) {
        for (int i = 0; i < Trackers.getSize(); i++) {
            drawTrajectory(output, Trackers[i].getTrajectory(), Trajectory_COLOR);
        }
    }
    string log4("Drawing completed");
    lastLog = log1 + log2 + log3 + log4;
    return output;
}
Exemplo n.º 19
0
static int dispatch_request(const command* table1, const command* table2,
			    int log)
{
  const command* cmd;

  cmd = find_command(table1);
  if (!cmd && table2) cmd = find_command(table2);
  if (!cmd) {
    if (log) log2(request, req_param ? req_param : "(no parameter)");
    return respond(502, 1, "Command not supported.");
  }
  
  if (req_param) {
    if (log) log2(cmd->name, cmd->hideparam ? "XXXXXXXX" : req_param);
    if (cmd->fn1)
      return cmd->fn1();
    return respond(501, 1, "Command requires no parameter");
  }
  else {
    if (log) log1(cmd->name);
    if (cmd->fn0)
      return cmd->fn0();
    return respond(504, 1, "Command requires a parameter");
  }
}
Exemplo n.º 20
0
static __inline void LoadSection(const int i,DWORD ofs)
{
    cacheSectionInfo[i].ofsBase=ofs-ofs%CACHESECTIONSIZE;
    log1("readsect %08x",ofs);
    SetFilePointer(hDbFile,cacheSectionInfo[i].ofsBase,NULL,FILE_BEGIN);
    ReadFile(hDbFile,pDbCache+i*CACHESECTIONSIZE,CACHESECTIONSIZE,&ofs,NULL);
}
Exemplo n.º 21
0
/* Send a packet to gateway_nip using the kernel ip stack */
static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
{
	log1("Forwarding packet to relay");

	udhcp_send_kernel_packet(dhcp_pkt,
			server_config.server_nip, SERVER_PORT,
			dhcp_pkt->gateway_nip, SERVER_PORT);
}
Exemplo n.º 22
0
tReadWriteMutex::tReadWriteMutex(const int _max):semaphore(_max), write_user_login("")
{
    max=_max;

    QString s="Blocker ";
    tLog log1(s);
    log=log1;
}
Exemplo n.º 23
0
int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac)
{
	int fd;
	struct ifreq ifr;
	struct sockaddr_in *our_ip;

	memset(&ifr, 0, sizeof(ifr));
	fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);

	ifr.ifr_addr.sa_family = AF_INET;
	strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
	if (nip) {
		if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr,
			"is interface %s up and configured?", interface)
		) {
			close(fd);
			return -1;
		}
		our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
		*nip = our_ip->sin_addr.s_addr;
		log1("IP %s", inet_ntoa(our_ip->sin_addr));
	}

	if (ifindex) {
		if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) {
			close(fd);
			return -1;
		}
		log1("Adapter index %d", ifr.ifr_ifindex);
		*ifindex = ifr.ifr_ifindex;
	}

	if (mac) {
		if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) {
			close(fd);
			return -1;
		}
		memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
		log1("MAC %02x:%02x:%02x:%02x:%02x:%02x",
			mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
	}

	close(fd);
	return 0;
}
Exemplo n.º 24
0
/* NOINLINE: limit stack usage in caller */
static NOINLINE void send_NAK(struct dhcp_packet *oldpacket)
{
	struct dhcp_packet packet;

	init_packet(&packet, oldpacket, DHCPNAK);

	log1("Sending NAK");
	send_packet(&packet, /*force_bcast:*/ 1);
}
Exemplo n.º 25
0
void die_controls() {
  if (control_last.s) {
    log3("alert: cannot start: unable to read controls (", control_last.s, ")\n");
  }
  else {
    log1("alert: cannot start: unable to read controls\n");
  }
  _exit(111);
}
Exemplo n.º 26
0
/**
 * Save the state of a failed transfer so it can restarted later.
 */
void write_restart_file(int listidx)
{
    struct file_t *fileinfo;
    struct client_restart_t restart;
    char restart_name[MAXPATHNAME];
    int fd;

    // Don't bother if we're not using a temp directory.
    if (!strcmp(tempdir, "")) {
        return;
    }

    log1(group_list[listidx].group_id, 0, "Writing restart file");
    memset(&restart, 0, sizeof(restart));
    fileinfo = &group_list[listidx].fileinfo;
    if (group_list[listidx].phase != PHASE_MIDGROUP) {
        restart.blocks = fileinfo->blocks;
        restart.sections = fileinfo->sections;
        restart.size = fileinfo->size;
        strcpy(restart.name, fileinfo->name);
    }

    snprintf(restart_name, sizeof(restart_name), "%s%c_group_%08X_restart",
             tempdir, PATH_SEP, group_list[listidx].group_id);
    if ((fd = open(restart_name, OPENWRITE | O_CREAT | O_TRUNC, 0644)) == -1) {
        syserror(group_list[listidx].group_id, 0,
                 "Failed to create restart file");
        return;
    }

    if (file_write(fd, &restart, sizeof(restart)) == -1) {
        log0(group_list[listidx].group_id, 0,
                "Failed to write header for restart file");
        goto errexit;
    }
    if (fileinfo->blocks && fileinfo->naklist) {
        if (file_write(fd, fileinfo->naklist, fileinfo->blocks) == -1) {
            log0(group_list[listidx].group_id, 0,
                    "Failed to write NAK list for restart file");
            goto errexit;
        }
    }
    if (fileinfo->sections && fileinfo->section_done) {
        if (file_write(fd, fileinfo->section_done, fileinfo->sections) == -1) {
            log0(group_list[listidx].group_id, 0,
                    "Failed to write section_done list for restart file");
            goto errexit;
        }
    }
    close(fd);
    return;

errexit:
    close(fd);
    unlink(restart_name);
}
Exemplo n.º 27
0
INT_PTR utils_setSafetyMode(WPARAM wParam, LPARAM lParam) {
    int safeMode = (int)wParam;

	log1("db_setSafetyMode: %s", safeMode?"On":"Off");
    if (safeMode) 
        sql_exec(g_sqlite, "PRAGMA synchronous = NORMAL;");
    else
        sql_exec(g_sqlite, "PRAGMA synchronous = OFF;");
	return 0;
}
Exemplo n.º 28
0
bool cpiPython::AutoLoad()
{
	if (log_level < 1) { if(Log(0)) LogStream() << "Open dir: " << mScriptDir << endl; }
	log1( "PY: Autoload   Loading scripts from dir: %s\n", mScriptDir.c_str() );
	string pathname, filename;
	DIR *dir = opendir(mScriptDir.c_str());
	if(!dir)
	{
		if (log_level < 1) { if(Log(1)) LogStream() << "Open dir error" << endl; }
		log1( "PY: Autoload   Failed to open directory\n" );
		return false;
	}
	struct dirent *dent = NULL;

	while(NULL != (dent=readdir(dir)))
	{
		filename = dent->d_name;
		if((filename.size() > 4) && (StrCompare(filename,filename.size()-3,3,".py")==0))
		{
			pathname = mScriptDir + filename;
			cPythonInterpreter *ip = new cPythonInterpreter (pathname);
			if(!ip) continue;

			mPython.push_back(ip);
			if(ip->Init())
			{
				if (log_level < 1) { if(Log(1)) LogStream() << "Success loading Python script: " << filename << endl; }
				log1( "PY: Autoload   Success loading script: [ %d ] %s\n", ip->id, filename.c_str() );
			}
			else
			{
				if (log_level < 1) { if(Log(1)) LogStream() << "Failed loading Python script: " << filename << endl; }
				log1( "PY: Autoload   Failed loading script: [ %d ] %s\n", ip->id, filename.c_str() );
				mPython.pop_back();
				delete ip;
			}
		}
	}

	closedir(dir);
	return true;
}
Exemplo n.º 29
0
void FAST_FUNC read_leases(const char *file)
{
	struct dyn_lease lease;
	int64_t written_at, time_passed;
	int fd;
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
	unsigned i = 0;
#endif

	fd = open_or_warn(file, O_RDONLY);
	if (fd < 0)
		return;

	if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at))
		goto ret;
	written_at = SWAP_BE64(written_at);

	time_passed = time(NULL) - written_at;
	/* Strange written_at, or lease file from old version of udhcpd
	 * which had no "written_at" field? */
	if ((uint64_t)time_passed > 12 * 60 * 60)
		goto ret;

	while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
//FIXME: what if it matches some static lease?
		uint32_t y = ntohl(lease.lease_nip);
		if (y >= server_config.start_ip && y <= server_config.end_ip) {
			signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
			if (expires <= 0)
				continue;
			/* NB: add_lease takes "relative time", IOW,
			 * lease duration, not lease deadline. */
			if (add_lease(lease.lease_mac, lease.lease_nip,
					expires,
					lease.hostname, sizeof(lease.hostname)
				) == 0
			) {
				bb_error_msg("too many leases while loading %s", file);
				break;
			}
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
			i++;
#endif
		}
	}
	log1("Read %d leases", i);
 ret:
	close(fd);
}
Exemplo n.º 30
0
Arquivo: libQF.c Projeto: cran/MixSim
 static double   errbd(double u, double* cx)
 /*  find bound on tail probability using mgf, cutoff
    point returned to *cx */
 {
    double sum1, lj, ncj, x, y, xconst; int j, nj;
    counter();
    xconst = u * sigsq;  sum1 = u * xconst;  u = 2.0 * u;
    for (j=r-1; j>=0; j--)
    {
       nj = n[j]; lj = lb[j]; ncj = nc[j];
       x = u * lj; y = 1.0 - x;
       xconst = xconst + lj * (ncj / y + nj) / y;
       sum1 = sum1 + ncj * square(x / y)
          + nj * (square(x) / y + log1(-x, FALSE ));
    }
    *cx = xconst; return exp1(-0.5 * sum1);
 }