Exemplo n.º 1
0
BotRwxModel* 
bot_rwx_model_create( const char *fname )
{
    BotRwxModel *model = calloc(1, sizeof(BotRwxModel)); 

    tokenize_t *tok = tokenize_create( fname );
    int status;

    if (NULL==tok) {
        perror(fname);
        free(model);
        return NULL;
    }

    parse_require( tok, "ModelBegin" );
    parse_require( tok, "ClumpBegin" );

    while (tokenize_next(tok)!=EOF) {
        if( 0 == strcmp( tok->token, "ClumpBegin" ) ) {
            BotRwxClump *clump = (BotRwxClump*)calloc(1, sizeof(BotRwxClump));
            model->clumps = g_list_append( model->clumps, clump );

            status = parse_clump( clump, tok );
            if( 0 != status ) {
                tokenize_destroy(tok);
                bot_rwx_model_destroy(model);
                return NULL;
            }
        } else if( 0 == strcmp( tok->token, "ClumpEnd" ) ) {
            parse_require( tok, "ModelEnd" );
            break;
        }
    }

    tokenize_destroy( tok );
    return model;
}
Exemplo n.º 2
0
static int 
parse_clump( BotRwxClump *clump, tokenize_t *tok )
{
    // get clump name
    parse_require( tok, "#Layer" );
    parse_require( tok, ":" );
    tokenize_next( tok );
    clump->name = strdup( tok->token );

    // defaults
    clump->color[0] = clump->color[1] = clump->color[2] = 0;
    clump->opacity = 1;
    clump->ambient = 1;
    clump->diffuse = 1;
    clump->specular = 0;

    int nvbuf = 20000;
    BotRwxVertex *vbuf = (BotRwxVertex*)calloc(1, nvbuf*sizeof(BotRwxVertex));

    // clump color
    tokenize_next( tok );
    while( 0 != strcmp( tok->token, "#texbegin" ) ) {

        if( ! strcmp( tok->token, "Color" ) ) {
            tokenize_next( tok );
            parse_double( tok, &clump->color[0] );
            parse_double( tok, &clump->color[1] );
            parse_double( tok, &clump->color[2] );
        } else if( ! strcmp( tok->token, "Surface" ) ) {
            tokenize_next( tok );
//            parse_double( tok, &clump->surface[0] );
//            parse_double( tok, &clump->surface[1] );
//            parse_double( tok, &clump->surface[2] );
            parse_double( tok, &clump->ambient );
            parse_double( tok, &clump->diffuse );
            parse_double( tok, &clump->specular );
        } else if( ! strcmp( tok->token, "Diffuse" ) ) {
            tokenize_next( tok );
            parse_double( tok, &clump->diffuse );
        } else if( ! strcmp( tok->token, "Specular" ) ) {
            tokenize_next( tok );
            parse_double( tok, &clump->specular );
        } else if( ! strcmp( tok->token, "Opacity" ) ) {
            tokenize_next( tok );
            parse_double( tok, &clump->opacity );
        } else {
            tokenize_next( tok );
        }
    }

    // expect the clump name
    parse_require( tok, clump->name );

    // start with a single vertex that should never be used.
    clump->nvertices = 1;

    // parse the list of vertices
    while( tokenize_next( tok ) != EOF ) {
        if( ! strcmp( tok->token, "Vertex" ) ) {
            parse_vertex( tok, vbuf + clump->nvertices );

            if( vbuf[clump->nvertices].id != clump->nvertices ) {
                parse_error( tok, "expected vertex %d (got %d)!\n", 
                        clump->nvertices, vbuf[clump->nvertices].id );
            }
            
            clump->nvertices++;

            if( clump->nvertices >= nvbuf ) {
                nvbuf += 10000;
                vbuf = (BotRwxVertex*)realloc(vbuf, nvbuf*sizeof(BotRwxVertex));
            }
        } else if( ! strcmp( tok->token, "#texend" ) ) {
            // expect the clump name
            parse_require( tok, clump->name );
            break;
        } else {
            parse_error( tok, "expected Vertex or #texend token!" );
        }
    }

    clump->vertices = 
        (BotRwxVertex*)malloc(clump->nvertices*sizeof(BotRwxVertex));
    memcpy( clump->vertices, vbuf, clump->nvertices*sizeof(BotRwxVertex) );
    free( vbuf );

    int ntbuf = 20000;
    BotRwxTriangle *tbuf = 
        (BotRwxTriangle*)calloc(1, ntbuf*sizeof(BotRwxTriangle));

    // parse the list of triangles
    tokenize_next( tok );
    while( 1 ) {
//    while( tokenize_next( tok ) != EOF ) {
        if( ! strcmp( tok->token, "Triangle" ) ) {
            parse_triangle( tok, tbuf + clump->ntriangles );
            clump->ntriangles++;

            if( clump->ntriangles >= ntbuf ) {
                ntbuf += 10000;
                tbuf = (BotRwxTriangle*)realloc(tbuf, 
                        ntbuf*sizeof(BotRwxTriangle));
            }
        } else if( ! strcmp( tok->token, "ClumpEnd" ) ) {
            break;
        }
    }

    clump->triangles = 
        (BotRwxTriangle*)malloc(clump->ntriangles*sizeof(BotRwxTriangle));
    memcpy( clump->triangles, tbuf, clump->ntriangles*sizeof(BotRwxTriangle) );
    free( tbuf );

    return 0;
}
Exemplo n.º 3
0
int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
{
	contact_t* c;
	int st, mode;
	str aor;
	int ret;
	sip_uri_t *u;
	rr_t *route;
	struct sip_uri puri;
	param_hooks_t hooks;
	param_t *params;
	contact_t *contact;
	int use_ob = 1, use_regid = 1;

	u = parse_to_uri(_m);
	if(u==NULL)
		goto error;

	rerrno = R_FINE;
	ret = 1;

	if (parse_message(_m) < 0) {
		goto error;
	}

	if (check_contacts(_m, &st) > 0) {
		goto error;
	}

	if (parse_supported(_m) == 0) {
		if (!(get_supported(_m)	& F_OPTION_TAG_OUTBOUND)
				&& reg_outbound_mode == REG_OUTBOUND_REQUIRE) {
			LM_WARN("Outbound required by server and not supported by UAC\n");
			rerrno = R_OB_UNSUP;
			goto error;
		}
	}

	if (parse_require(_m) == 0) {
		if ((get_require(_m) & F_OPTION_TAG_OUTBOUND)
				&& reg_outbound_mode == REG_OUTBOUND_NONE) {
			LM_WARN("Outbound required by UAC and not supported by server\n");
			rerrno = R_OB_REQD;
			goto error;
		}
	}

	if (reg_outbound_mode != REG_OUTBOUND_NONE
			&& _m->contact && _m->contact->parsed
			&& !(parse_headers(_m, HDR_VIA2_F, 0) == -1 || _m->via2 == 0
				|| _m->via2->error != PARSE_OK)) {
		/* Outbound supported on server, and more than one Via: - not the first hop */

		if (!(parse_headers(_m, HDR_PATH_F, 0) == -1 || _m->path == 0)) {
			route = (rr_t *)0;
			if (parse_rr_body(_m->path->body.s, _m->path->body.len, &route) < 0) {
				LM_ERR("Failed to parse Path: header body\n");
				goto error;
			}
			if (parse_uri(route->nameaddr.uri.s, route->nameaddr.uri.len, &puri) < 0) {
				LM_ERR("Failed to parse Path: URI\n");
				goto error;
			}
			if (parse_params(&puri.params, CLASS_URI, &hooks, &params) != 0) {
				LM_ERR("Failed to parse Path: URI parameters\n");
				goto error;
			}
			if (!hooks.uri.ob) {
				/* No ;ob parameter to top Path: URI - no outbound */
				use_ob = 0;
			}

		} else {
			/* No Path: header - no outbound */
			use_ob = 0;

		}

		contact = ((contact_body_t *) _m->contact->parsed)->contacts;
		if (!contact) {
			LM_ERR("empty Contact:\n");
			goto error;
		}

		if ((use_ob == 0) && (reg_regid_mode == REG_REGID_OUTBOUND)) {
			if ((get_supported(_m) & F_OPTION_TAG_OUTBOUND)
					&& contact->reg_id) {
				LM_WARN("Outbound used by UAC but not supported by edge proxy\n");
				rerrno = R_OB_UNSUP_EDGE;
				goto error;
			} else {
				/* ignore ;reg-id parameter */
				use_regid = 0;
			}
		}
	}

	get_act_time();
	c = get_first_contact(_m);

	if (extract_aor((_uri)?_uri:&get_to(_m)->uri, &aor, NULL) < 0) {
		LM_ERR("failed to extract Address Of Record\n");
		goto error;
	}

	mem_only = is_cflag_set(REG_SAVE_MEM_FL)?FL_MEM:FL_NONE;

	if (c == 0) {
		if (st) {
			if (star(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error;
			else ret=3;
		} else {
			if (no_contacts(_m, (udomain_t*)_d, &aor, &u->host) < 0) goto error;
			else ret=4;
		}
	} else {
		mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0;
		if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode, use_regid)) < 0)
			goto error;
		ret = (ret==0)?1:ret;
	}

	update_stat(accepted_registrations, 1);

	/* Only send reply upon request, not upon reply */
	if ((is_route_type(REQUEST_ROUTE) || is_route_type(FAILURE_ROUTE))
			&& !is_cflag_set(REG_SAVE_NORPL_FL) && (reg_send_reply(_m) < 0))
		return -1;

	return ret;
error:
	update_stat(rejected_registrations, 1);
	if (is_route_type(REQUEST_ROUTE) && !is_cflag_set(REG_SAVE_NORPL_FL) )
		reg_send_reply(_m);

	return 0;
}