void wdHandleCollision(World* W) { CollisionInfo Info; Node* it = lstFirst(&W->Polygons); Node* it2; //On met à FALSE tous les collide while(!nodeEnd(it)) { polySetCollided((Polygon*)nodeGetData(it), FALSE); it=nodeGetNext(it); } it = lstFirst(&W->Polygons); while(!nodeEnd(it)) { List LExtracted = gridGetPolygonList(&W->CollisionGrid, (Polygon*) nodeGetData(it)); it2 = lstFirst(&LExtracted); while(!nodeEnd(it2)) { if(!polyHasCollided((Polygon*)nodeGetData(it2)))//it != it2) { Info = polyCollide( (Polygon*) nodeGetData(it), (Polygon*) nodeGetData(it2)); if(Info.P1 != NULL) /* Il y a collision */ polyHandleCollision(Info); } it2 = nodeGetNext(it2); } lstFree(&LExtracted); polySetCollided((Polygon*)nodeGetData(it), TRUE); it = nodeGetNext(it); } }
BST_ERR_ENUM_UINT8 BST_OS_DeleteMbx( BST_OS_MBX_T *pstMbx ) { BST_OS_MAIL_T *pstContent; BST_OS_LOCKCNT_T tThreadLockCnt; BST_ASSERT_NULL_RTN( pstMbx, BST_ERR_INVALID_PTR ); BST_ASSERT_NULL_RTN( pstMbx->hSem, BST_ERR_INVALID_PTR ); BST_OS_DeleteSem( pstMbx->hSem ); tThreadLockCnt = BST_OS_ThreadLock(); for (;;) { if( 0 == lstCount( &pstMbx->hList ) ) { break; } pstContent = (BST_OS_MAIL_T *)lstGet( &pstMbx->hList ); BST_OS_FREE( pstContent ); } lstFree( &pstMbx->hList); BST_OS_FREE( pstMbx ); BST_OS_ThreadUnLock( tThreadLockCnt ); /*lint -e438*/ return( BST_NO_ERROR_MSG ); /*lint +e438*/ }
void etherOutputHookDelete ( FUNCPTR outputHook ) { HOOK_ENTRY *pHookEnt; extern LIST outputHookList; NODE index; for (pHookEnt = (HOOK_ENTRY *)lstFirst(&outputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&index)) { index = pHookEnt->node; if (pHookEnt->routine == outputHook) { lstDelete(&outputHookList, &pHookEnt->node); free(pHookEnt); } } if (lstCount(&outputHookList) <= 0) { etherOutputHookRtn = NULL; lstFree(&outputHookList); } }
void objFree(Object* Obj) { Node* N; while(lstCount(&Obj->CoordTex) > 0) { N = lstFirst(&Obj->CoordTex); delVec2((Vec2*) nodeGetData(N)); lstRem(&Obj->CoordTex, N); } lstFree(&Obj->CoordTex); // Peu utile Obj->Shape = NULL; Obj->Tex = 0; }
void endObjectUnload ( END_OBJ* pEnd ) { if (pEnd->txSem != NULL) semDelete (pEnd->txSem); lstFree (&pEnd->multiList); if (pEnd->pSnarf != NULL) { KHEAP_FREE (pEnd->pSnarf); } pEnd->dummyBinding = NULL; pEnd->pSnarf = NULL; pEnd->pTyped = NULL; pEnd->pPromisc = NULL; pEnd->pStop = NULL; pEnd->nProtoSlots = 0; }
BST_OS_MBX_T *BST_OS_CreateMbx( BST_VOID *pvArg, BST_UINT32 ulSize ) { BST_OS_MBX_T *pstMbx; pstMbx = BST_OS_MALLOC( BST_OS_SIZEOF(BST_OS_MBX_T) ); BST_ASSERT_NULL_RTN( pstMbx, BST_NULL_PTR ); pstMbx->hSem = BST_NULL_PTR; lstInit( &pstMbx->hList ); pstMbx->hSem = BST_OS_CreateSem( pvArg, 0U ); if( BST_NULL_PTR == pstMbx->hSem ) { BST_DBG_LOG("Create Mail Box Fail.\n"); lstFree( &pstMbx->hList ); BST_OS_FREE(pstMbx); /*lint -e438*/ return BST_NULL_PTR; /*lint +e438*/ } return( pstMbx ); }
static int Pier(long connect) { ASSERT(!connect); void** gc = NULL; pid_t my_pid = getpid(); char** lstEnv = getEnv(); ASSERT(lstEnv == NULL); char* Rpath = String(RUN_PATH "/%ld.0", connect); ASSERT(Rpath == NULL); gcCollect(&gc, &Rpath); if (-1 == mkdir(Rpath, 00700)) { ASSERT(errno != EEXIST); errno = 0; } char* Rfifo = String(RUN_PATH "/%ld.0/%ld", connect, my_pid); ASSERT(Rfifo == NULL); gcCollect(&gc, &Rfifo); ASSERT(-1 == MkFifo(Rfifo)); char* Wfifo = String(RUN_PATH "/%ld", connect); ASSERT(Wfifo == NULL); gcCollect(&gc, &Wfifo); char* lock_name = String(RUN_PATH "/%ld.lock", connect); ASSERT(lock_name == NULL); gcCollect(&gc, &lock_name); int Lfd = open(lock_name, O_RDWR); if (-1 == Lfd) { char* answer = String("Status: 434 Requested host unavailable" NL NL \ "434 Requested host unavailable."); gcCollect(&gc, &answer); Write(STDOUT, answer, strlen(answer)); lstFree(lstEnv); gcClean(gc); unlink(Rfifo); return 0; } if(-1 == lockf(Lfd, F_LOCK, 0L)) { char* answer = String("Status: 434 Requested host unavailable" NL NL \ "434 Requested host unavailable."); gcCollect(&gc, &answer); Write(STDOUT, answer, strlen(answer)); lstFree(lstEnv); gcClean(gc); unlink(Rfifo); return 0; } int Wfd = open(Wfifo, O_WRONLY | O_SYNC, 0); if (-1 == Wfd) { char* answer = String("Status: 434 Requested host unavailable" NL NL \ "434 Requested host unavailable."); gcCollect(&gc, &answer); Write(STDOUT, answer, strlen(answer)); lstFree(lstEnv); gcClean(gc); unlink(Rfifo); return 0; } /* int i = 0; char** lstEnv2 = getEnv(); for (; lstEnv2[i]; ++i) { TRACE("%s\n", lstEnv2[i]); } */ char* header = String("%d" NL, my_pid); ASSERT(header == NULL); gcCollect(&gc, &header); ASSERT(-1 == replaceStrFormat(&header, "", "%s %s %s" NL, getenv("REQUEST_METHOD") ? getenv("REQUEST_METHOD") : "GET", getenv("REQUEST_URI"), getenv("SERVER_PROTOCOL") ? getenv("SERVER_PROTOCOL") : "HTTP/1.1")); char** lstHttpEnv = lstEgrep(lstEnv, "^HTTP_.+$"); if (lstHttpEnv) { addHeader(&header, lstHttpEnv); } char** lstContentEnv = lstEgrep(lstEnv, "^CONTENT_.+$"); if (lstContentEnv) { addHeader(&header, lstContentEnv); } ASSERT(-1 == replaceStrFormat(&header, "", NL)); errno = 0; int n = Write(Wfd, header, strlen(header)); ASSERT(errno); int n_read = 0; size_t total = 0; char buf[PIPE_BUF] = {'\0', }; errno = 0; while((n_read = read(0, buf, sizeof(buf)))) { if(-1 == n_read) { if(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK || errno == EPIPE) { errno = 0; continue; } break; } errno = 0; int n = Write(Wfd, buf, n_read); ASSERT(errno); total += n; } ASSERT(-1 == close(Wfd)); //TRACE("\n%d %d >>\n", getpid(), time(NULL)); int Rfd = open(Rfifo, O_RDONLY, 0); ASSERT(-1 == Rfd); n_read = 0; total = 0; errno = 0; while((n_read = read(Rfd, buf, sizeof(buf)))) { if(-1 == n_read) { if(errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK || errno == EPIPE) { errno = 0; continue; } break; } errno = 0; int n = Write(STDOUT, buf, n_read); ASSERT(errno); total += n_read; } //TRACE("\n%d %d <<\n", getpid(), time(NULL)); ASSERT(-1 == close(Rfd)); ASSERT(-1 == lockf(Lfd, F_ULOCK, 0L)); ASSERT(-1 == close(Lfd)); ASSERT(-1 == unlink(Rfifo)); lstFree(lstEnv); lstFree(lstHttpEnv); lstFree(lstContentEnv); gcClean(gc); return 0; }
void plPhysics(Player* P, World* W) { /* Mise à jour spécifique de Player */ P->RdUStatus = P->RdRStatus = P->RdDStatus = P->RdLStatus = P->VxURStatus = P->VxULStatus = P->VxDLStatus = P->VxDRStatus = nullCollisionInfo(); polyResolve(plGetShape(P)); //for (i=0; i<10; i++) polyResolve(P->BodyPolygons[i]); for (int i=0; i<12; i++) { vxResolve(P->vxBodyParts[i], 0.5f, 0.5f); rdResolve(P->BodyRigids[i]); } float dif = vxGetPosition(P->VxDL).x - vxGetOldPos(P->VxDL).x; if (dif >= 0.f && ABS(dif) > 0.2f) P->Dir = DIR_RIGHT; else P->Dir = DIR_LEFT; List LExtracted = gridGetPolygonList(&W->CollisionGrid, P->Shape); Node* it; CollisionInfo Info; P->State = PL_NOSTATE; P->Normal = vec2(0.f, 0.f); it = lstFirst(&LExtracted); while(!nodeEnd(it)) { Info = polyCollide(plGetShape(P), (Polygon*) nodeGetData(it)); if(Info.P1 != NULL) { //printf("Collision\n"); if (Info.Edge == plGetRdD(P)) { P->GroundAngle = vec2Angle(Info.Normal)-M_PI_2; P->Normal = vec2Prod(Info.Normal, -1.f); P->State = P->State | PL_HAS_SUPPORT; if(P->Normal.y < -0.5f) P->State = P->State | PL_ON_GROUND; } else if(Info.V == plGetVxDL(P) || Info.V == plGetVxDR(P)) { P->GroundAngle = vec2Angle(Info.Normal)-M_PI_2; P->Normal = Info.Normal; P->State = P->State | PL_HAS_SUPPORT; if(P->Normal.y < -0.5f) P->State = P->State | PL_ON_GROUND; } /* Test des propriétés de la collision */ if(Info.Edge == plGetRdU(P)) P->RdUStatus = Info; else if(Info.Edge == plGetRdR(P)) P->RdRStatus = Info; else if(Info.Edge == plGetRdD(P)) P->RdDStatus = Info; else if(Info.Edge == plGetRdL(P)) P->RdLStatus = Info; if(Info.V == plGetVxUL(P)) P->VxULStatus = Info; else if(Info.V == plGetVxUR(P)) P->VxURStatus = Info; else if(Info.V == plGetVxDR(P)) P->VxDRStatus = Info; else if(Info.V == plGetVxDL(P)) P->VxDLStatus = Info; polyHandleCollision(Info); } it = nodeGetNext(it); } lstFree(&LExtracted); }
int Authorization(Socket_t* soc, const char* get, const char* login, const char* pass) { TRACE("CLIENT>Authorisation..."); char* login_pass_encripted = ptBasicRow(login, pass); if(NULL == login_pass_encripted) { ERROR("aBase64Encode(%s %s)", login, pass); return -1; } char* Header2 = malloc(snprintf(NULL, 0, TMPL_AUTH_HEADER, get/*, login_pass_encripted*/) + 1); if(NULL == Header2) { ERROR("malloc()"); free(login_pass_encripted); return -1; } sprintf(Header2, TMPL_AUTH_HEADER, get/*, login_pass_encripted*/); int nw = SSL_write(soc->fn, Header2, strlen(Header2)); if(nw <= 0) { char err_buf[256] = {'\0', }; TRACE("***ERROR*** SSL_write() return:%d error:%s\n", nw, ERR_error_string(ERR_get_error(), err_buf)); /* char err_buf[120] = {'\0'}; char* err_error_string = ERR_error_string(ERR_get_error(), err_buf); (void)err_error_string; ERROR("ERROR:%s:%d:SSL %s\n", __FILE__, __LINE__, err_error_string); */ free(Header2); free(login_pass_encripted); return -1; } //TRACE("CLIENT>SSL_write() %d bites", nw); //TDATA(" REQUEST>\n%s\n", Header2); size_t content_len = 0; char* buf = NULL; int i = 0; int rval = -1; while (-1 != GetRowFromSocket(&buf, soc)) { i++; if (-1 == chopStr(buf)) { free(buf); buf = NULL; break; } if (0 == strlen(buf)) { free(buf); buf = NULL; break; } if (strcasestr(buf, "Content-Length: ")) { content_len = atoll(buf + strlen("Content-Length: ")); } if (i == 1) { char** lst = lstSplitStr(' ', buf); if (lst) { if (lstSize(lst) == 3 && strcasestr(lst[1], "200") && strcasestr(lst[2], "OK")) { rval = 1; } else { rval = 0; } lstFree(lst); } } free(buf); buf = NULL; } free(buf); buf = NULL; if (!i) { ERROR("GetRowFromSocket()"); free(Header2); free(login_pass_encripted); TRACE("CLIENT>Authorisation failed"); return -1; } if (content_len) { GetBufFromSocket(&buf, soc, content_len); if (!buf) { ERROR("GetBufFromSocket()"); free(Header2); free(login_pass_encripted); TRACE("CLIENT>Authorisation %s", (rval == 1) ? "success" : "fail"); return rval; } free(buf); } free(Header2); free(login_pass_encripted); TRACE("CLIENT>Authorisation %s", (rval == 1) ? "success" : "fail"); return rval; }
STATUS usrNetBridgeInit ( char* pPortString, /* interfaces to be configured as bridge ports */ /* e.g., "fei0,fei1,elPci0" */ char* pAddr, /* IP address for this bridge */ int mask, /* netmask for this bridge */ char* pAddrv6, /* IPv6 address for this bridge */ int prefixLen /* IPv6 prefix length for this bridge */ ) { LIST bridgePortList; /* list of BRIDGE_NODEs */ BRIDGE_NODE* pFirstNode; /* first node in the list */ /* Initialize the list */ lstInit(&bridgePortList); /* Parse the port string and populate the list */ if (portsStringParse(pPortString, &bridgePortList) != OK) { printf("portsStringParse failed!\n"); lstFree(&bridgePortList); return ERROR; } /* Initialize the bridge */ if (bridgeInit() != OK) { printf("bridgeInit failed!\n"); lstFree(&bridgePortList); return ERROR; } /* Initialize the bridge ports */ if (bridgePortsInit(&bridgePortList) != OK) { printf("bridgePortsInit failed!\n"); lstFree(&bridgePortList); return ERROR; } /* Initialize the mirror interface. * * NOTE: The first bridge port's device name and number is used * to initialize the mirror interface. */ pFirstNode = (BRIDGE_NODE*) lstFirst(&bridgePortList); if (mirrorInit(pFirstNode->devName, pFirstNode->unit, pAddr, mask, pAddrv6, prefixLen) != OK) { printf("mirrorInit failed!\n"); lstFree(&bridgePortList); return ERROR; } /* Cleanup */ lstFree(&bridgePortList); return OK; }
void etherInputHookDelete ( FUNCPTR inputHook, char *pName, int unit ) { HOOK_ENTRY *pHookEnt; HOOK_ENTRY *pTarget = NULL; BOOL unbindFlag = TRUE; /* Remove handler if hook found? */ if (pName != NULL) /* END case */ { for (pHookEnt = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&pHookEnt->node)) { /* Ignore BSD device hook entries. */ if (pHookEnt->pCookie == NULL) continue; if (STREQ(pHookEnt->name, pName) && (pHookEnt->unit == unit)) { if (pHookEnt->routine == inputHook) { /* * Found matching hook entry to remove. Keep searching * for other hooks on this device if needed. */ pTarget = pHookEnt; if (!unbindFlag) /* Another hook already found? */ break; } else { /* * Different hook on same driver - do not unbind. * Stop searching if target hook entry already found. */ unbindFlag = FALSE; if (pTarget) break; } } } if (pTarget) /* Remove hook entry if match found. */ { if (unbindFlag) /* Remove binding if last hook for device. */ { if (muxTkDrvCheck (pName)) { muxUnbind (pTarget->pCookie, MUX_PROTO_SNARF, nptEtherInputHookRtn); } else { muxUnbind (pTarget->pCookie, MUX_PROTO_SNARF, endEtherInputHookRtn); } } lstDelete (&inputHookList, &pTarget->node); free (pTarget); } } else /* 4.4 case */ { for (pHookEnt = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookEnt != NULL; pHookEnt = pTarget) { if (pHookEnt->pCookie) /* Ignore END device hook entries. */ continue; pTarget = (HOOK_ENTRY *)lstNext(&pHookEnt->node); if (pHookEnt->routine == inputHook) { lstDelete(&inputHookList, &pHookEnt->node); free(pHookEnt); } } } if (lstCount(&inputHookList) <= 0) { etherInputHookActive = FALSE; /* No END driver hooks installed. */ etherInputHookRtn = NULL; /* No BSD driver hooks installed. */ lstFree (&inputHookList); } }