static int parse_json(ogs_sbi_message_t *message,
        char *content_type, char *json)
{
    int rv = OGS_OK;
    cJSON *item = NULL;

    ogs_assert(message);

    if (!json)
        return OGS_OK;

    if (!content_type) {
        ogs_error("No Content-type");
        return OGS_ERROR;
    }

    ogs_log_print(OGS_LOG_TRACE, "%s", json);
    item = cJSON_Parse(json);
    if (!item) {
        ogs_error("JSON parse error");
        return OGS_ERROR;
    }

    if (content_type &&
        !strncmp(content_type, OGS_SBI_CONTENT_PROBLEM_TYPE,
            strlen(OGS_SBI_CONTENT_PROBLEM_TYPE))) {
        message->ProblemDetails = OpenAPI_problem_details_parseFromJSON(item);
    } else if (content_type &&
                !strncmp(content_type, OGS_SBI_CONTENT_PATCH_TYPE,
                    strlen(OGS_SBI_CONTENT_PATCH_TYPE))) {
        if (item) {
            OpenAPI_patch_item_t *patch_item = NULL;
            cJSON *patchJSON = NULL;
            message->PatchItemList = OpenAPI_list_create();
            cJSON_ArrayForEach(patchJSON, item) {
                if (!cJSON_IsObject(patchJSON)) {
                    rv = OGS_ERROR;
                    ogs_error("Unknown JSON");
                    goto cleanup;
                }

                patch_item = OpenAPI_patch_item_parseFromJSON(patchJSON);
                OpenAPI_list_add(message->PatchItemList, patch_item);
            }
        }
    } else {
        SWITCH(message->h.service.name)
        CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM)

            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES)
                message->NFProfile =
                    OpenAPI_nf_profile_parseFromJSON(item);
                if (!message->NFProfile) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS)
                message->SubscriptionData =
                    OpenAPI_subscription_data_parseFromJSON(item);
                if (!message->SubscriptionData) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY)
                message->NotificationData =
                    OpenAPI_notification_data_parseFromJSON(item);
                if (!message->NotificationData) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES)
                message->SearchResult =
                    OpenAPI_search_result_parseFromJSON(item);
                if (!message->SearchResult) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NAUSF_AUTH)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_UE_AUTHENTICATIONS)
                SWITCH(message->h.method)
                CASE(OGS_SBI_HTTP_METHOD_POST)
                    if (message->res_status == 0) {
                        message->AuthenticationInfo =
                            OpenAPI_authentication_info_parseFromJSON(item);
                        if (!message->AuthenticationInfo) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                            OGS_SBI_HTTP_STATUS_CREATED) {
                        message->UeAuthenticationCtx =
                        OpenAPI_ue_authentication_ctx_parseFromJSON(item);
                        if (!message->UeAuthenticationCtx) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                    break;
                CASE(OGS_SBI_HTTP_METHOD_PUT)
                    if (message->res_status == 0) {
                        message->ConfirmationData =
                            OpenAPI_confirmation_data_parseFromJSON(item);
                        if (!message->ConfirmationData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                        message->ConfirmationDataResponse =
                            OpenAPI_confirmation_data_response_parseFromJSON(
                                    item);
                        if (!message->ConfirmationDataResponse) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                    break;
                DEFAULT
                    rv = OGS_ERROR;
                    ogs_error("Unknown method [%s]", message->h.method);
                END
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NUDM_UEAU)
            SWITCH(message->h.resource.component[1])
            CASE(OGS_SBI_RESOURCE_NAME_SECURITY_INFORMATION)
                SWITCH(message->h.resource.component[2])
                CASE(OGS_SBI_RESOURCE_NAME_GENERATE_AUTH_DATA)
                    if (message->res_status == 0) {
                        message->AuthenticationInfoRequest =
                        OpenAPI_authentication_info_request_parseFromJSON(
                                item);
                        if (!message->AuthenticationInfoRequest) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                        message->AuthenticationInfoResult =
                        OpenAPI_authentication_info_result_parseFromJSON(
                                item);
                        if (!message->AuthenticationInfoResult) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                    break;
                DEFAULT
                    rv = OGS_ERROR;
                    ogs_error("Unknown resource name [%s]",
                            message->h.resource.component[2]);
                END
                break;

            CASE(OGS_SBI_RESOURCE_NAME_AUTH_EVENTS)
                message->AuthEvent = OpenAPI_auth_event_parseFromJSON(item);
                if (!message->AuthEvent) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[1]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NUDM_UECM)
            SWITCH(message->h.resource.component[1])
            CASE(OGS_SBI_RESOURCE_NAME_REGISTRATIONS)
                SWITCH(message->h.resource.component[2])
                CASE(OGS_SBI_RESOURCE_NAME_AMF_3GPP_ACCESS)
                    message->Amf3GppAccessRegistration =
                        OpenAPI_amf3_gpp_access_registration_parseFromJSON(
                                item);
                    if (!message->Amf3GppAccessRegistration) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                    break;
                DEFAULT
                    rv = OGS_ERROR;
                    ogs_error("Unknown resource name [%s]",
                            message->h.resource.component[2]);
                END
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[1]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM)
            SWITCH(message->h.resource.component[1])
            CASE(OGS_SBI_RESOURCE_NAME_AM_DATA)
                message->AccessAndMobilitySubscriptionData =
                    OpenAPI_access_and_mobility_subscription_data_parseFromJSON(
                            item);
                if (!message->AccessAndMobilitySubscriptionData) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA)
                message->SmfSelectionSubscriptionData =
                    OpenAPI_smf_selection_subscription_data_parseFromJSON(item);
                if (!message->SmfSelectionSubscriptionData) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA)
                message->UeContextInSmfData =
                    OpenAPI_ue_context_in_smf_data_parseFromJSON(item);
                if (!message->UeContextInSmfData) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            CASE(OGS_SBI_RESOURCE_NAME_SM_DATA)
                message->SessionManagementSubscriptionData =
                    OpenAPI_session_management_subscription_data_parseFromJSON(
                            item);
                if (!message->SessionManagementSubscriptionData) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[1]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NUDR_DR)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTION_DATA)
                SWITCH(message->h.resource.component[2])
                CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_DATA)
                    SWITCH(message->h.resource.component[3])
                    CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_SUBSCRIPTION)
                        if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                            message->AuthenticationSubscription =
                                OpenAPI_authentication_subscription_parseFromJSON(item);
                            if (!message->AuthenticationSubscription) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                        }
                        break;
                    CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_STATUS)
                        message->AuthEvent =
                            OpenAPI_auth_event_parseFromJSON(item);
                        if (!message->AuthEvent) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                        break;
                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown resource name [%s]",
                                message->h.resource.component[3]);
                    END
                    break;

                CASE(OGS_SBI_RESOURCE_NAME_CONTEXT_DATA)
                    message->Amf3GppAccessRegistration =
                        OpenAPI_amf3_gpp_access_registration_parseFromJSON(
                                item);
                    if (!message->Amf3GppAccessRegistration) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                    break;

                DEFAULT
                    SWITCH(message->h.resource.component[3])
                    CASE(OGS_SBI_RESOURCE_NAME_PROVISIONED_DATA)
                        SWITCH(message->h.resource.component[4])
                        CASE(OGS_SBI_RESOURCE_NAME_AM_DATA)
                            message->AccessAndMobilitySubscriptionData =
                                OpenAPI_access_and_mobility_subscription_data_parseFromJSON(item);
                            if (!message->AccessAndMobilitySubscriptionData) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                            break;

                        CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECTION_SUBSCRIPTION_DATA)
                            message->SmfSelectionSubscriptionData =
                                OpenAPI_smf_selection_subscription_data_parseFromJSON(item);
                            if (!message->SmfSelectionSubscriptionData) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                            break;

                        CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA)
                            message->UeContextInSmfData =
                                OpenAPI_ue_context_in_smf_data_parseFromJSON(
                                        item);
                            if (!message->UeContextInSmfData) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                            break;

                        CASE(OGS_SBI_RESOURCE_NAME_SM_DATA)
                            message->SessionManagementSubscriptionData =
                                OpenAPI_session_management_subscription_data_parseFromJSON(item);
                            if (!message->SessionManagementSubscriptionData) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                            break;

                        DEFAULT
                            rv = OGS_ERROR;
                            ogs_error("Unknown resource name [%s]",
                                    message->h.resource.component[4]);
                        END
                        break;

                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown resource name [%s]",
                                message->h.resource.component[3]);
                    END
                END
                break;

            CASE(OGS_SBI_RESOURCE_NAME_POLICY_DATA)
                SWITCH(message->h.resource.component[1])
                CASE(OGS_SBI_RESOURCE_NAME_UES)
                    SWITCH(message->h.resource.component[3])
                    CASE(OGS_SBI_RESOURCE_NAME_AM_DATA)

                        message->AmPolicyData =
                            OpenAPI_am_policy_data_parseFromJSON(item);
                        if (!message->AmPolicyData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                        break;

                    CASE(OGS_SBI_RESOURCE_NAME_SM_DATA)

                        message->SmPolicyData =
                            OpenAPI_sm_policy_data_parseFromJSON(item);
                        if (!message->SmPolicyData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                        break;

                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown resource name [%s]",
                                message->h.resource.component[3]);
                    END
                    break;

                DEFAULT
                    rv = OGS_ERROR;
                    ogs_error("Unknown resource name [%s]",
                            message->h.resource.component[1]);
                END
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_SM_CONTEXTS)
                SWITCH(message->h.resource.component[2])
                CASE(OGS_SBI_RESOURCE_NAME_MODIFY)
                    if (message->res_status == 0) {
                        message->SmContextUpdateData =
                            OpenAPI_sm_context_update_data_parseFromJSON(item);
                        if (!message->SmContextUpdateData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                        message->SmContextUpdatedData =
                            OpenAPI_sm_context_updated_data_parseFromJSON(item);
                        if (!message->SmContextUpdatedData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                            OGS_SBI_HTTP_STATUS_BAD_REQUEST ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_FORBIDDEN ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_NOT_FOUND ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_SERVICE_UNAVAILABLE ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT) {
                        message->SmContextUpdateError =
                            OpenAPI_sm_context_update_error_parseFromJSON(item);
                        if (!message->SmContextUpdateError) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                    break;
                CASE(OGS_SBI_RESOURCE_NAME_RELEASE)
                    if (message->res_status == 0) {
                        message->SmContextReleaseData =
                            OpenAPI_sm_context_release_data_parseFromJSON(item);
                        if (!message->SmContextReleaseData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                            OGS_SBI_HTTP_STATUS_NO_CONTENT) {
                    } else if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                        message->SmContextReleasedData =
                            OpenAPI_sm_context_released_data_parseFromJSON(
                                    item);
                        if (!message->SmContextReleasedData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                    break;
                DEFAULT
                    if (message->res_status == 0) {
                        message->SmContextCreateData =
                            OpenAPI_sm_context_create_data_parseFromJSON(item);
                        if (!message->SmContextCreateData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                            OGS_SBI_HTTP_STATUS_CREATED) {
                        message->SmContextCreatedData =
                            OpenAPI_sm_context_created_data_parseFromJSON(item);
                        if (!message->SmContextCreatedData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                            OGS_SBI_HTTP_STATUS_BAD_REQUEST ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_FORBIDDEN ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_NOT_FOUND ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_SERVICE_UNAVAILABLE ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT) {
                        message->SmContextCreateError =
                            OpenAPI_sm_context_create_error_parseFromJSON(item);
                        if (!message->SmContextCreateError) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                END
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NAMF_COMM)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXTS)
                SWITCH(message->h.resource.component[2])
                CASE(OGS_SBI_RESOURCE_NAME_N1_N2_MESSAGES)
                    if (message->res_status == 0) {
                        message->N1N2MessageTransferReqData =
                            OpenAPI_n1_n2_message_transfer_req_data_parseFromJSON(item);
                        if (!message->N1N2MessageTransferReqData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                                OGS_SBI_HTTP_STATUS_OK ||
                                message->res_status ==
                                    OGS_SBI_HTTP_STATUS_ACCEPTED) {
                        message->N1N2MessageTransferRspData =
                            OpenAPI_n1_n2_message_transfer_rsp_data_parseFromJSON(item);
                        if (!message->N1N2MessageTransferRspData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                    break;

                DEFAULT
                    rv = OGS_ERROR;
                    ogs_error("Unknown resource name [%s]",
                            message->h.resource.component[2]);
                END
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;
        CASE(OGS_SBI_SERVICE_NAME_NPCF_AM_POLICY_CONTROL)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_POLICIES)
                if (message->res_status == 0) {
                    message->PolicyAssociationRequest =
                        OpenAPI_policy_association_request_parseFromJSON(
                                item);
                    if (!message->PolicyAssociationRequest) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                } else if (message->res_status == OGS_SBI_HTTP_STATUS_CREATED) {
                    message->PolicyAssociation =
                        OpenAPI_policy_association_parseFromJSON(item);
                    if (!message->PolicyAssociation) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_SM_POLICIES)
                if (!message->h.resource.component[1]) {
                    if (message->res_status == 0) {
                        message->SmPolicyContextData =
                            OpenAPI_sm_policy_context_data_parseFromJSON(item);
                        if (!message->SmPolicyContextData) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    } else if (message->res_status ==
                            OGS_SBI_HTTP_STATUS_CREATED) {
                        message->SmPolicyDecision =
                            OpenAPI_sm_policy_decision_parseFromJSON(item);
                        if (!message->SmPolicyDecision) {
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        }
                    }
                } else {
                    SWITCH(message->h.resource.component[2])
                    CASE(OGS_SBI_RESOURCE_NAME_DELETE)
                        if (message->res_status == 0) {
                            message->SmPolicyDeleteData =
                                OpenAPI_sm_policy_delete_data_parseFromJSON(
                                        item);
                            if (!message->SmPolicyDeleteData) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                        }
                        break;
                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown resource name [%s]",
                                message->h.resource.component[2]);
                    END
                    break;
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NNSSF_NSSELECTION)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_NETWORK_SLICE_INFORMATION)
                if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                    message->AuthorizedNetworkSliceInfo =
                        OpenAPI_authorized_network_slice_info_parseFromJSON(
                                item);
                    if (!message->AuthorizedNetworkSliceInfo) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_PCF_BINDINGS)
                if (message->h.resource.component[1]) {
                    SWITCH(message->h.method)
                    CASE(OGS_SBI_HTTP_METHOD_PATCH)
                        if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                            message->PcfBinding =
                                OpenAPI_pcf_binding_parseFromJSON(item);
                            if (!message->PcfBinding) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                        }
                        break;
                    CASE(OGS_SBI_HTTP_METHOD_DELETE)
                        break;
                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown method [%s]", message->h.method);
                    END
                    break;
                } else {
                    SWITCH(message->h.method)
                    CASE(OGS_SBI_HTTP_METHOD_POST)
                        if (message->res_status == 0 ||
                            message->res_status ==
                                OGS_SBI_HTTP_STATUS_CREATED) {
                            message->PcfBinding =
                                OpenAPI_pcf_binding_parseFromJSON(item);
                            if (!message->PcfBinding) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                        }
                        break;

                    CASE(OGS_SBI_HTTP_METHOD_GET)
                        if (message->res_status == OGS_SBI_HTTP_STATUS_OK) {
                            message->PcfBinding =
                                OpenAPI_pcf_binding_parseFromJSON(item);
                            if (!message->PcfBinding) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                        }
                        break;
                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown method [%s]", message->h.method);
                    END
                    break;
                }

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_APP_SESSIONS)
                if (message->h.resource.component[1]) {
                    if (message->h.resource.component[2]) {
                        SWITCH(message->h.resource.component[2])
                        CASE(OGS_SBI_RESOURCE_NAME_DELETE)
                            /* Nothing */
                            break;
                        DEFAULT
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        END
                    } else {
                        SWITCH(message->h.method)
                        CASE(OGS_SBI_HTTP_METHOD_PATCH)
                            message->AppSessionContextUpdateDataPatch =
                                OpenAPI_app_session_context_update_data_patch_parseFromJSON(item);
                            if (!message->AppSessionContextUpdateDataPatch) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                            break;
                        DEFAULT
                            rv = OGS_ERROR;
                            ogs_error("JSON parse error");
                        END
                    }
                } else {
                    SWITCH(message->h.method)
                    CASE(OGS_SBI_HTTP_METHOD_POST)
                        if (message->res_status == 0 ||
                            message->res_status ==
                                OGS_SBI_HTTP_STATUS_CREATED) {
                            message->AppSessionContext =
                                OpenAPI_app_session_context_parseFromJSON(item);
                            if (!message->AppSessionContext) {
                                rv = OGS_ERROR;
                                ogs_error("JSON parse error");
                            }
                        }
                        break;
                    DEFAULT
                        rv = OGS_ERROR;
                        ogs_error("Unknown method [%s]", message->h.method);
                    END
                }
                break;
            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NAMF_CALLBACK)
            SWITCH(message->h.resource.component[1])
            CASE(OGS_SBI_RESOURCE_NAME_SM_CONTEXT_STATUS)
                message->SmContextStatusNotification =
                    OpenAPI_sm_context_status_notification_parseFromJSON(item);
                if (!message->SmContextStatusNotification) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[1]);
            END
            break;

        CASE(OGS_SBI_SERVICE_NAME_NSMF_CALLBACK)
            SWITCH(message->h.resource.component[0])
            CASE(OGS_SBI_RESOURCE_NAME_N1_N2_FAILURE_NOTIFY)
                message->N1N2MsgTxfrFailureNotification =
                    OpenAPI_n1_n2_msg_txfr_failure_notification_parseFromJSON(
                            item);
                if (!message->N1N2MsgTxfrFailureNotification) {
                    rv = OGS_ERROR;
                    ogs_error("JSON parse error");
                }
                break;

            CASE(OGS_SBI_RESOURCE_NAME_SM_POLICY_NOTIFY)
                SWITCH(message->h.resource.component[2])
                CASE(OGS_SBI_RESOURCE_NAME_UPDATE)
                    message->SmPolicyNotification =
                        OpenAPI_sm_policy_notification_parseFromJSON(item);
                    if (!message->SmPolicyNotification) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                    break;
                CASE(OGS_SBI_RESOURCE_NAME_TERMINATE)
                    message->TerminationNotification =
                        OpenAPI_termination_notification_parseFromJSON(item);
                    if (!message->TerminationNotification) {
                        rv = OGS_ERROR;
                        ogs_error("JSON parse error");
                    }
                    break;

                DEFAULT
                    rv = OGS_ERROR;
                    ogs_error("Unknown resource name [%s]",
                            message->h.resource.component[2]);
                END
                break;

            DEFAULT
                rv = OGS_ERROR;
                ogs_error("Unknown resource name [%s]",
                        message->h.resource.component[0]);
            END
            break;

        DEFAULT
            rv = OGS_ERROR;
            ogs_error("Not implemented API name [%s]",
                    message->h.service.name);
        END
    }

cleanup:

    cJSON_Delete(item);
    return rv;
}


static int alloc_scratch_buffers ( H264Context * h , int linesize ) {
 int alloc_size = FFALIGN ( FFABS ( linesize ) + 32 , 32 ) ;
 if ( h -> bipred_scratchpad ) return 0 ;
 h -> bipred_scratchpad = av_malloc ( 16 * 6 * alloc_size ) ;
 h -> edge_emu_buffer = av_mallocz ( alloc_size * 2 * 21 ) ;
 h -> me . scratchpad = av_mallocz ( alloc_size * 2 * 16 * 2 ) ;
 if ( ! h -> bipred_scratchpad || ! h -> edge_emu_buffer || ! h -> me . scratchpad ) {
 av_freep ( & h -> bipred_scratchpad ) ;
 av_freep ( & h -> edge_emu_buffer ) ;
 av_freep ( & h -> me . scratchpad ) ;
 return AVERROR ( ENOMEM ) ;
 }
 h -> me . temp = h -> me . scratchpad ;
 return 0 ;
 }


static void _gtpv1_u_recv_cb(short when, ogs_socket_t fd, void *data)
{
    int len;
    ssize_t size;
    char buf[OGS_ADDRSTRLEN];

    ogs_pkbuf_t *pkbuf = NULL;
    ogs_sockaddr_t from;

    ogs_gtp_header_t *gtp_h = NULL;

    uint32_t teid;
    uint8_t qfi;

    ogs_assert(fd != INVALID_SOCKET);

    pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_PKT_LEN);
    ogs_assert(pkbuf);
    ogs_pkbuf_put(pkbuf, OGS_MAX_PKT_LEN);

    size = ogs_recvfrom(fd, pkbuf->data, pkbuf->len, 0, &from);
    if (size <= 0) {
        ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
                "ogs_recv() failed");
        goto cleanup;
    }

    ogs_pkbuf_trim(pkbuf, size);

    ogs_assert(pkbuf);
    ogs_assert(pkbuf->len);

    gtp_h = (ogs_gtp_header_t *)pkbuf->data;
    if (gtp_h->version != OGS_GTP_VERSION_1) {
        ogs_error("[DROP] Invalid GTPU version [%d]", gtp_h->version);
        ogs_log_hexdump(OGS_LOG_ERROR, pkbuf->data, pkbuf->len);
        goto cleanup;
    }

    if (gtp_h->type == OGS_GTPU_MSGTYPE_ECHO_REQ) {
        ogs_pkbuf_t *echo_rsp;

        ogs_debug("[RECV] Echo Request from [%s]", OGS_ADDR(&from, buf));
        echo_rsp = ogs_gtp_handle_echo_req(pkbuf);
        ogs_expect(echo_rsp);
        if (echo_rsp) {
            ssize_t sent;

            /* Echo reply */
            ogs_debug("[SEND] Echo Response to [%s]", OGS_ADDR(&from, buf));

            sent = ogs_sendto(fd, echo_rsp->data, echo_rsp->len, 0, &from);
            if (sent < 0 || sent != echo_rsp->len) {
                ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno,
                        "ogs_sendto() failed");
            }
            ogs_pkbuf_free(echo_rsp);
        }
        goto cleanup;
    }

    teid = be32toh(gtp_h->teid);

    ogs_debug("[RECV] GPU-U Type [%d] from [%s] : TEID[0x%x]",
            gtp_h->type, OGS_ADDR(&from, buf), teid);

    qfi = 0;
    if (gtp_h->flags & OGS_GTPU_FLAGS_E) {
        /*
         * TS29.281
         * 5.2.1 General format of the GTP-U Extension Header
         * Figure 5.2.1-3: Definition of Extension Header Type
         *
         * Note 4 : For a GTP-PDU with several Extension Headers, the PDU
         *          Session Container should be the first Extension Header
         */
        ogs_gtp_extension_header_t *extension_header =
            (ogs_gtp_extension_header_t *)(pkbuf->data + OGS_GTPV1U_HEADER_LEN);
        ogs_assert(extension_header);
        if (extension_header->type ==
                OGS_GTP_EXTENSION_HEADER_TYPE_PDU_SESSION_CONTAINER) {
            if (extension_header->pdu_type ==
                OGS_GTP_EXTENSION_HEADER_PDU_TYPE_UL_PDU_SESSION_INFORMATION) {
                    ogs_debug("   QFI [0x%x]",
                            extension_header->qos_flow_identifier);
                    qfi = extension_header->qos_flow_identifier;
            }
        }
    }

    /* Remove GTP header and send packets to TUN interface */
    len = ogs_gtpu_header_len(pkbuf);
    if (len < 0) {
        ogs_error("[DROP] Cannot decode GTPU packet");
        ogs_log_hexdump(OGS_LOG_ERROR, pkbuf->data, pkbuf->len);
        goto cleanup;
    }
    if (gtp_h->type != OGS_GTPU_MSGTYPE_END_MARKER &&
        pkbuf->len <= len) {
        ogs_error("[DROP] Small GTPU packet(type:%d len:%d)", gtp_h->type, len);
        ogs_log_hexdump(OGS_LOG_ERROR, pkbuf->data, pkbuf->len);
        goto cleanup;
    }
    ogs_assert(ogs_pkbuf_pull(pkbuf, len));

    if (gtp_h->type == OGS_GTPU_MSGTYPE_GPDU) {
        smf_sess_t *sess = NULL;
        ogs_pfcp_far_t *far = NULL;

        far = ogs_pfcp_far_find_by_teid(teid);
        if (!far) {
            ogs_error("No FAR for TEID [%d]", teid);
            goto cleanup;
        }

        if (far->dst_if != OGS_PFCP_INTERFACE_CP_FUNCTION) {
            ogs_error("Invalid Destination Interface [%d]", far->dst_if);
            goto cleanup;
        }

        if (qfi) {
            ogs_error("QFI[%d] Found", qfi);
            goto cleanup;
        }

        ogs_assert(far->sess);
        sess = SMF_SESS(far->sess);
        ogs_assert(sess);

        if (sess->ipv6 && check_if_router_solicit(pkbuf) == true) {
            struct ip6_hdr *ip6_h = (struct ip6_hdr *)pkbuf->data;
            ogs_assert(ip6_h);
            send_router_advertisement(sess, ip6_h->ip6_src.s6_addr);
        }
    } else {
        ogs_error("[DROP] Invalid GTPU Type [%d]", gtp_h->type);
        ogs_log_hexdump(OGS_LOG_ERROR, pkbuf->data, pkbuf->len);
    }

cleanup:
    ogs_pkbuf_free(pkbuf);
}


static int encode_ext_header(Wmv2Context *w){ MpegEncContext * const s= &w->s; PutBitContext pb; int code; init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size); put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29 put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047)); put_bits(&pb, 1, w->mspel_bit=1); put_bits(&pb, 1, w->flag3=1); put_bits(&pb, 1, w->abt_flag=1); put_bits(&pb, 1, w->j_type_bit=1); put_bits(&pb, 1, w->top_left_mv_flag=0); put_bits(&pb, 1, w->per_mb_rl_bit=1); put_bits(&pb, 3, code=1); flush_put_bits(&pb); s->slice_height = s->mb_height / code; return 0; }


static int check_owned_directory_mode(const char *path, mode_t expected_mode)
{
	struct stat stat;
	if (lstat(path, &stat))
		return -1;

	if (!S_ISDIR(stat.st_mode))
		return -1;

	if (stat.st_uid != getuid())
		return -1;

	if ((stat.st_mode & 07777) != expected_mode)
		return -1;

	return 0;
}


START_TEST(qdict_new_test) { QDict *qdict; qdict = qdict_new(); fail_unless(qdict != NULL); fail_unless(qdict_size(qdict) == 0); fail_unless(qdict->base.refcnt == 1); fail_unless(qobject_type(QOBJECT(qdict)) == QTYPE_QDICT); // destroy doesn't exit yet free(qdict); }


static int ScaKwdTab(GmfMshSct *msh)
{
   int      KwdCod, c;
   int64_t  NexPos, EndPos, LstPos;
   char     str[ GmfStrSiz ];

   if(msh->typ & Asc)
   {
      // Scan each string in the file until the end
      while(fscanf(msh->hdl, "%s", str) != EOF)
      {
         // Fast test in order to reject quickly the numeric values
         if(isalpha(str[0]))
         {
            // Search which kwd code this string is associated with, then get its
            // header and save the curent position in file (just before the data)
            for(KwdCod=1; KwdCod<= GmfMaxKwd; KwdCod++)
               if(!strcmp(str, GmfKwdFmt[ KwdCod ][0]))
               {
                  ScaKwdHdr(msh, KwdCod);
                  break;
               }
         }
         else if(str[0] == '#')
            while((c = fgetc(msh->hdl)) != '\n' && c != EOF);
      }
   }
   else
   {
      // Get file size
      EndPos = GetFilSiz(msh);
      LstPos = -1;

      // Jump through kwd positions in the file
      do
      {
         // Get the kwd code and the next kwd position
         ScaWrd(msh, ( char *)&KwdCod);
         NexPos = GetPos(msh);

         // Make sure the flow does not move beyond the file size
         if(NexPos > EndPos)
            longjmp(msh->err, -24);

         // And check that it does not move back
         if(NexPos && (NexPos <= LstPos))
            longjmp(msh->err, -30);

         LstPos = NexPos;

         // Check if this kwd belongs to this mesh version
         if( (KwdCod >= 1) && (KwdCod <= GmfMaxKwd) )
            ScaKwdHdr(msh, KwdCod);

         // Go to the next kwd
         if(NexPos && !(SetFilPos(msh, NexPos)))
            longjmp(msh->err, -25);

      }while(NexPos && (KwdCod != GmfEnd));
   }

   return(1);
}


static void decode_micromips32_opc (CPUMIPSState *env, DisasContext *ctx, uint16_t insn_hw1) { int32_t offset; uint16_t insn; int rt, rs, rd, rr; int16_t imm; uint32_t op, minor, mips32_op; uint32_t cond, fmt, cc; insn = cpu_lduw_code(env, ctx->pc + 2); ctx->opcode = (ctx->opcode << 16) | insn; rt = (ctx->opcode >> 21) & 0x1f; rs = (ctx->opcode >> 16) & 0x1f; rd = (ctx->opcode >> 11) & 0x1f; rr = (ctx->opcode >> 6) & 0x1f; imm = (int16_t) ctx->opcode; op = (ctx->opcode >> 26) & 0x3f; switch (op) { case POOL32A: minor = ctx->opcode & 0x3f; switch (minor) { case 0x00: minor = (ctx->opcode >> 6) & 0xf; switch (minor) { case SLL32: mips32_op = OPC_SLL; goto do_shifti; case SRA: mips32_op = OPC_SRA; goto do_shifti; case SRL32: mips32_op = OPC_SRL; goto do_shifti; case ROTR: mips32_op = OPC_ROTR; do_shifti: gen_shift_imm(ctx, mips32_op, rt, rs, rd); break; default: goto pool32a_invalid; } break; case 0x10: minor = (ctx->opcode >> 6) & 0xf; switch (minor) { /* Arithmetic */ case ADD: mips32_op = OPC_ADD; goto do_arith; case ADDU32: mips32_op = OPC_ADDU; goto do_arith; case SUB: mips32_op = OPC_SUB; goto do_arith; case SUBU32: mips32_op = OPC_SUBU; goto do_arith; case MUL: mips32_op = OPC_MUL; do_arith: gen_arith(ctx, mips32_op, rd, rs, rt); break; /* Shifts */ case SLLV: mips32_op = OPC_SLLV; goto do_shift; case SRLV: mips32_op = OPC_SRLV; goto do_shift; case SRAV: mips32_op = OPC_SRAV; goto do_shift; case ROTRV: mips32_op = OPC_ROTRV; do_shift: gen_shift(ctx, mips32_op, rd, rs, rt); break; /* Logical operations */ case AND: mips32_op = OPC_AND; goto do_logic; case OR32: mips32_op = OPC_OR; goto do_logic; case NOR: mips32_op = OPC_NOR; goto do_logic; case XOR32: mips32_op = OPC_XOR; do_logic: gen_logic(ctx, mips32_op, rd, rs, rt); break; /* Set less than */ case SLT: mips32_op = OPC_SLT; goto do_slt; case SLTU: mips32_op = OPC_SLTU; do_slt: gen_slt(ctx, mips32_op, rd, rs, rt); break; default: goto pool32a_invalid; } break; case 0x18: minor = (ctx->opcode >> 6) & 0xf; switch (minor) { /* Conditional moves */ case MOVN: mips32_op = OPC_MOVN; goto do_cmov; case MOVZ: mips32_op = OPC_MOVZ; do_cmov: gen_cond_move(ctx, mips32_op, rd, rs, rt); break; case LWXS: gen_ldxs(ctx, rs, rt, rd); break; default: goto pool32a_invalid; } break; case INS: gen_bitops(ctx, OPC_INS, rt, rs, rr, rd); return; case EXT: gen_bitops(ctx, OPC_EXT, rt, rs, rr, rd); return; case POOL32AXF: gen_pool32axf(env, ctx, rt, rs); break; case 0x07: generate_exception(ctx, EXCP_BREAK); break; default: pool32a_invalid: MIPS_INVAL("pool32a"); generate_exception(ctx, EXCP_RI); break; } break; case POOL32B: minor = (ctx->opcode >> 12) & 0xf; switch (minor) { case CACHE: check_cp0_enabled(ctx); /* Treat as no-op. */ break; case LWC2: case SWC2: /* COP2: Not implemented. */ generate_exception_err(ctx, EXCP_CpU, 2); break; case LWP: case SWP: #ifdef TARGET_MIPS64 case LDP: case SDP: #endif gen_ldst_pair(ctx, minor, rt, rs, SIMM(ctx->opcode, 0, 12)); break; case LWM32: case SWM32: #ifdef TARGET_MIPS64 case LDM: case SDM: #endif gen_ldst_multiple(ctx, minor, rt, rs, SIMM(ctx->opcode, 0, 12)); break; default: MIPS_INVAL("pool32b"); generate_exception(ctx, EXCP_RI); break; } break; case POOL32F: if (env->CP0_Config1 & (1 << CP0C1_FP)) { minor = ctx->opcode & 0x3f; check_cp1_enabled(ctx); switch (minor) { case ALNV_PS: mips32_op = OPC_ALNV_PS; goto do_madd; case MADD_S: mips32_op = OPC_MADD_S; goto do_madd; case MADD_D: mips32_op = OPC_MADD_D; goto do_madd; case MADD_PS: mips32_op = OPC_MADD_PS; goto do_madd; case MSUB_S: mips32_op = OPC_MSUB_S; goto do_madd; case MSUB_D: mips32_op = OPC_MSUB_D; goto do_madd; case MSUB_PS: mips32_op = OPC_MSUB_PS; goto do_madd; case NMADD_S: mips32_op = OPC_NMADD_S; goto do_madd; case NMADD_D: mips32_op = OPC_NMADD_D; goto do_madd; case NMADD_PS: mips32_op = OPC_NMADD_PS; goto do_madd; case NMSUB_S: mips32_op = OPC_NMSUB_S; goto do_madd; case NMSUB_D: mips32_op = OPC_NMSUB_D; goto do_madd; case NMSUB_PS: mips32_op = OPC_NMSUB_PS; do_madd: gen_flt3_arith(ctx, mips32_op, rd, rr, rs, rt); break; case CABS_COND_FMT: cond = (ctx->opcode >> 6) & 0xf; cc = (ctx->opcode >> 13) & 0x7; fmt = (ctx->opcode >> 10) & 0x3; switch (fmt) { case 0x0: gen_cmpabs_s(ctx, cond, rt, rs, cc); break; case 0x1: gen_cmpabs_d(ctx, cond, rt, rs, cc); break; case 0x2: gen_cmpabs_ps(ctx, cond, rt, rs, cc); break; default: goto pool32f_invalid; } break; case C_COND_FMT: cond = (ctx->opcode >> 6) & 0xf; cc = (ctx->opcode >> 13) & 0x7; fmt = (ctx->opcode >> 10) & 0x3; switch (fmt) { case 0x0: gen_cmp_s(ctx, cond, rt, rs, cc); break; case 0x1: gen_cmp_d(ctx, cond, rt, rs, cc); break; case 0x2: gen_cmp_ps(ctx, cond, rt, rs, cc); break; default: goto pool32f_invalid; } break; case POOL32FXF: gen_pool32fxf(ctx, rt, rs); break; case 0x00: /* PLL foo */ switch ((ctx->opcode >> 6) & 0x7) { case PLL_PS: mips32_op = OPC_PLL_PS; goto do_ps; case PLU_PS: mips32_op = OPC_PLU_PS; goto do_ps; case PUL_PS: mips32_op = OPC_PUL_PS; goto do_ps; case PUU_PS: mips32_op = OPC_PUU_PS; goto do_ps; case CVT_PS_S: mips32_op = OPC_CVT_PS_S; do_ps: gen_farith(ctx, mips32_op, rt, rs, rd, 0); break; default: goto pool32f_invalid; } break; case 0x08: /* [LS][WDU]XC1 */ switch ((ctx->opcode >> 6) & 0x7) { case LWXC1: mips32_op = OPC_LWXC1; goto do_ldst_cp1; case SWXC1: mips32_op = OPC_SWXC1; goto do_ldst_cp1; case LDXC1: mips32_op = OPC_LDXC1; goto do_ldst_cp1; case SDXC1: mips32_op = OPC_SDXC1; goto do_ldst_cp1; case LUXC1: mips32_op = OPC_LUXC1; goto do_ldst_cp1; case SUXC1: mips32_op = OPC_SUXC1; do_ldst_cp1: gen_flt3_ldst(ctx, mips32_op, rd, rd, rt, rs); break; default: goto pool32f_invalid; } break; case 0x18: /* 3D insns */ fmt = (ctx->opcode >> 9) & 0x3; switch ((ctx->opcode >> 6) & 0x7) { case RSQRT2_FMT: switch (fmt) { case FMT_SDPS_S: mips32_op = OPC_RSQRT2_S; goto do_3d; case FMT_SDPS_D: mips32_op = OPC_RSQRT2_D; goto do_3d; case FMT_SDPS_PS: mips32_op = OPC_RSQRT2_PS; goto do_3d; default: goto pool32f_invalid; } break; case RECIP2_FMT: switch (fmt) { case FMT_SDPS_S: mips32_op = OPC_RECIP2_S; goto do_3d; case FMT_SDPS_D: mips32_op = OPC_RECIP2_D; goto do_3d; case FMT_SDPS_PS: mips32_op = OPC_RECIP2_PS; goto do_3d; default: goto pool32f_invalid; } break; case ADDR_PS: mips32_op = OPC_ADDR_PS; goto do_3d; case MULR_PS: mips32_op = OPC_MULR_PS; do_3d: gen_farith(ctx, mips32_op, rt, rs, rd, 0); break; default: goto pool32f_invalid; } break; case 0x20: /* MOV[FT].fmt and PREFX */ cc = (ctx->opcode >> 13) & 0x7; fmt = (ctx->opcode >> 9) & 0x3; switch ((ctx->opcode >> 6) & 0x7) { case MOVF_FMT: switch (fmt) { case FMT_SDPS_S: gen_movcf_s(rs, rt, cc, 0); break; case FMT_SDPS_D: gen_movcf_d(ctx, rs, rt, cc, 0); break; case FMT_SDPS_PS: gen_movcf_ps(rs, rt, cc, 0); break; default: goto pool32f_invalid; } break; case MOVT_FMT: switch (fmt) { case FMT_SDPS_S: gen_movcf_s(rs, rt, cc, 1); break; case FMT_SDPS_D: gen_movcf_d(ctx, rs, rt, cc, 1); break; case FMT_SDPS_PS: gen_movcf_ps(rs, rt, cc, 1); break; default: goto pool32f_invalid; } break; case PREFX: break; default: goto pool32f_invalid; } break; #define FINSN_3ARG_SDPS(prfx) \ switch ((ctx->opcode >> 8) & 0x3) { \ case FMT_SDPS_S: \ mips32_op = OPC_##prfx##_S; \ goto do_fpop; \ case FMT_SDPS_D: \ mips32_op = OPC_##prfx##_D; \ goto do_fpop; \ case FMT_SDPS_PS: \ mips32_op = OPC_##prfx##_PS; \ goto do_fpop; \ default: \ goto pool32f_invalid; \ } case 0x30: /* regular FP ops */ switch ((ctx->opcode >> 6) & 0x3) { case ADD_FMT: FINSN_3ARG_SDPS(ADD); break; case SUB_FMT: FINSN_3ARG_SDPS(SUB); break; case MUL_FMT: FINSN_3ARG_SDPS(MUL); break; case DIV_FMT: fmt = (ctx->opcode >> 8) & 0x3; if (fmt == 1) { mips32_op = OPC_DIV_D; } else if (fmt == 0) { mips32_op = OPC_DIV_S; } else { goto pool32f_invalid; } goto do_fpop; default: goto pool32f_invalid; } break; case 0x38: /* cmovs */ switch ((ctx->opcode >> 6) & 0x3) { case MOVN_FMT: FINSN_3ARG_SDPS(MOVN); break; case MOVZ_FMT: FINSN_3ARG_SDPS(MOVZ); break; default: goto pool32f_invalid; } break; do_fpop: gen_farith(ctx, mips32_op, rt, rs, rd, 0); break; default: pool32f_invalid: MIPS_INVAL("pool32f"); generate_exception(ctx, EXCP_RI); break; } } else { generate_exception_err(ctx, EXCP_CpU, 1); } break; case POOL32I: minor = (ctx->opcode >> 21) & 0x1f; switch (minor) { case BLTZ: mips32_op = OPC_BLTZ; goto do_branch; case BLTZAL: mips32_op = OPC_BLTZAL; goto do_branch; case BLTZALS: mips32_op = OPC_BLTZALS; goto do_branch; case BGEZ: mips32_op = OPC_BGEZ; goto do_branch; case BGEZAL: mips32_op = OPC_BGEZAL; goto do_branch; case BGEZALS: mips32_op = OPC_BGEZALS; goto do_branch; case BLEZ: mips32_op = OPC_BLEZ; goto do_branch; case BGTZ: mips32_op = OPC_BGTZ; do_branch: gen_compute_branch(ctx, mips32_op, 4, rs, -1, imm << 1); break; /* Traps */ case TLTI: mips32_op = OPC_TLTI; goto do_trapi; case TGEI: mips32_op = OPC_TGEI; goto do_trapi; case TLTIU: mips32_op = OPC_TLTIU; goto do_trapi; case TGEIU: mips32_op = OPC_TGEIU; goto do_trapi; case TNEI: mips32_op = OPC_TNEI; goto do_trapi; case TEQI: mips32_op = OPC_TEQI; do_trapi: gen_trap(ctx, mips32_op, rs, -1, imm); break; case BNEZC: case BEQZC: gen_compute_branch(ctx, minor == BNEZC ? OPC_BNE : OPC_BEQ, 4, rs, 0, imm << 1); /* Compact branches don't have a delay slot, so just let the normal delay slot handling take us to the branch target. */ break; case LUI: gen_logic_imm(ctx, OPC_LUI, rs, -1, imm); break; case SYNCI: break; case BC2F: case BC2T: /* COP2: Not implemented. */ generate_exception_err(ctx, EXCP_CpU, 2); break; case BC1F: mips32_op = (ctx->opcode & (1 << 16)) ? OPC_BC1FANY2 : OPC_BC1F; goto do_cp1branch; case BC1T: mips32_op = (ctx->opcode & (1 << 16)) ? OPC_BC1TANY2 : OPC_BC1T; goto do_cp1branch; case BC1ANY4F: mips32_op = OPC_BC1FANY4; goto do_cp1mips3d; case BC1ANY4T: mips32_op = OPC_BC1TANY4; do_cp1mips3d: check_cop1x(ctx); check_insn(ctx, ASE_MIPS3D); /* Fall through */ do_cp1branch: gen_compute_branch1(ctx, mips32_op, (ctx->opcode >> 18) & 0x7, imm << 1); break; case BPOSGE64: case BPOSGE32: /* MIPS DSP: not implemented */ /* Fall through */ default: MIPS_INVAL("pool32i"); generate_exception(ctx, EXCP_RI); break; } break; case POOL32C: minor = (ctx->opcode >> 12) & 0xf; switch (minor) { case LWL: mips32_op = OPC_LWL; goto do_ld_lr; case SWL: mips32_op = OPC_SWL; goto do_st_lr; case LWR: mips32_op = OPC_LWR; goto do_ld_lr; case SWR: mips32_op = OPC_SWR; goto do_st_lr; #if defined(TARGET_MIPS64) case LDL: mips32_op = OPC_LDL; goto do_ld_lr; case SDL: mips32_op = OPC_SDL; goto do_st_lr; case LDR: mips32_op = OPC_LDR; goto do_ld_lr; case SDR: mips32_op = OPC_SDR; goto do_st_lr; case LWU: mips32_op = OPC_LWU; goto do_ld_lr; case LLD: mips32_op = OPC_LLD; goto do_ld_lr; #endif case LL: mips32_op = OPC_LL; goto do_ld_lr; do_ld_lr: gen_ld(ctx, mips32_op, rt, rs, SIMM(ctx->opcode, 0, 12)); break; do_st_lr: gen_st(ctx, mips32_op, rt, rs, SIMM(ctx->opcode, 0, 12)); break; case SC: gen_st_cond(ctx, OPC_SC, rt, rs, SIMM(ctx->opcode, 0, 12)); break; #if defined(TARGET_MIPS64) case SCD: gen_st_cond(ctx, OPC_SCD, rt, rs, SIMM(ctx->opcode, 0, 12)); break; #endif case PREF: /* Treat as no-op */ break; default: MIPS_INVAL("pool32c"); generate_exception(ctx, EXCP_RI); break; } break; case ADDI32: mips32_op = OPC_ADDI; goto do_addi; case ADDIU32: mips32_op = OPC_ADDIU; do_addi: gen_arith_imm(ctx, mips32_op, rt, rs, imm); break; /* Logical operations */ case ORI32: mips32_op = OPC_ORI; goto do_logici; case XORI32: mips32_op = OPC_XORI; goto do_logici; case ANDI32: mips32_op = OPC_ANDI; do_logici: gen_logic_imm(ctx, mips32_op, rt, rs, imm); break; /* Set less than immediate */ case SLTI32: mips32_op = OPC_SLTI; goto do_slti; case SLTIU32: mips32_op = OPC_SLTIU; do_slti: gen_slt_imm(ctx, mips32_op, rt, rs, imm); break; case JALX32: offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 2; gen_compute_branch(ctx, OPC_JALX, 4, rt, rs, offset); break; case JALS32: offset = (int32_t)(ctx->opcode & 0x3FFFFFF) << 1; gen_compute_branch(ctx, OPC_JALS, 4, rt, rs, offset); break; case BEQ32: gen_compute_branch(ctx, OPC_BEQ, 4, rt, rs, imm << 1); break; case BNE32: gen_compute_branch(ctx, OPC_BNE, 4, rt, rs, imm << 1); break; case J32: gen_compute_branch(ctx, OPC_J, 4, rt, rs, (int32_t)(ctx->opcode & 0x3FFFFFF) << 1); break; case JAL32: gen_compute_branch(ctx, OPC_JAL, 4, rt, rs, (int32_t)(ctx->opcode & 0x3FFFFFF) << 1); break; /* Floating point (COP1) */ case LWC132: mips32_op = OPC_LWC1; goto do_cop1; case LDC132: mips32_op = OPC_LDC1; goto do_cop1; case SWC132: mips32_op = OPC_SWC1; goto do_cop1; case SDC132: mips32_op = OPC_SDC1; do_cop1: gen_cop1_ldst(env, ctx, mips32_op, rt, rs, imm); break; case ADDIUPC: { int reg = mmreg(ZIMM(ctx->opcode, 23, 3)); int offset = SIMM(ctx->opcode, 0, 23) << 2; gen_addiupc(ctx, reg, offset, 0, 0); } break; /* Loads and stores */ case LB32: mips32_op = OPC_LB; goto do_ld; case LBU32: mips32_op = OPC_LBU; goto do_ld; case LH32: mips32_op = OPC_LH; goto do_ld; case LHU32: mips32_op = OPC_LHU; goto do_ld; case LW32: mips32_op = OPC_LW; goto do_ld; #ifdef TARGET_MIPS64 case LD32: mips32_op = OPC_LD; goto do_ld; case SD32: mips32_op = OPC_SD; goto do_st; #endif case SB32: mips32_op = OPC_SB; goto do_st; case SH32: mips32_op = OPC_SH; goto do_st; case SW32: mips32_op = OPC_SW; goto do_st; do_ld: gen_ld(ctx, mips32_op, rt, rs, imm); break; do_st: gen_st(ctx, mips32_op, rt, rs, imm); break; default: generate_exception(ctx, EXCP_RI); break; } }


convert(
    Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither) {
    ImagingSectionCookie cookie;
    ImagingShuffler convert;
    int y;

    if (!imIn) {
        return (Imaging)ImagingError_ModeError();
    }

    if (!mode) {
        /* Map palette image to full depth */
        if (!imIn->palette) {
            return (Imaging)ImagingError_ModeError();
        }
        mode = imIn->palette->mode;
    } else {
        /* Same mode? */
        if (!strcmp(imIn->mode, mode)) {
            return ImagingCopy2(imOut, imIn);
        }
    }

    /* test for special conversions */

    if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "PA") == 0) {
        return frompalette(imOut, imIn, mode);
    }

    if (strcmp(mode, "P") == 0 || strcmp(mode, "PA") == 0) {
        return topalette(imOut, imIn, mode, palette, dither);
    }

    if (dither && strcmp(mode, "1") == 0) {
        return tobilevel(imOut, imIn, dither);
    }

    /* standard conversion machinery */

    convert = NULL;

    for (y = 0; converters[y].from; y++) {
        if (!strcmp(imIn->mode, converters[y].from) &&
            !strcmp(mode, converters[y].to)) {
            convert = converters[y].convert;
            break;
        }
    }

    if (!convert) {
#ifdef notdef
        return (Imaging)ImagingError_ValueError("conversion not supported");
#else
        static char buf[100];
        sprintf(buf, "conversion from %.10s to %.10s not supported", imIn->mode, mode);
        return (Imaging)ImagingError_ValueError(buf);
#endif
    }

    imOut = ImagingNew2Dirty(mode, imOut, imIn);
    if (!imOut) {
        return NULL;
    }

    ImagingSectionEnter(&cookie);
    for (y = 0; y < imIn->ysize; y++) {
        (*convert)((UINT8 *)imOut->image[y], (UINT8 *)imIn->image[y], imIn->xsize);
    }
    ImagingSectionLeave(&cookie);

    return imOut;
}


static inline uint32_t e1000e_tx_wb_interrupt_cause ( E1000ECore * core , int queue_idx ) {
 if ( ! msix_enabled ( core -> owner ) ) {
 return E1000_ICR_TXDW ;
 }
 return ( queue_idx == 0 ) ? E1000_ICR_TXQ0 : E1000_ICR_TXQ1 ;
 }


static int remoteDispatchClientCall ( struct qemud_server * server , struct qemud_client * client , struct qemud_client_message * msg , bool qemu_protocol ) {
 XDR xdr ;
 remote_error rerr ;
 dispatch_args args ;
 dispatch_ret ret ;
 const dispatch_data * data = NULL ;
 int rv = - 1 ;
 unsigned int len ;
 virConnectPtr conn = NULL ;
 memset ( & args , 0 , sizeof args ) ;
 memset ( & ret , 0 , sizeof ret ) ;
 memset ( & rerr , 0 , sizeof rerr ) ;
 if ( msg -> hdr . status != REMOTE_OK ) {
 remoteDispatchFormatError ( & rerr , _ ( "status (%d) != REMOTE_OK" ) , ( int ) msg -> hdr . status ) ;
 goto rpc_error ;
 }
 if ( client -> auth ) {
 if ( msg -> hdr . proc != REMOTE_PROC_AUTH_LIST && msg -> hdr . proc != REMOTE_PROC_AUTH_SASL_INIT && msg -> hdr . proc != REMOTE_PROC_AUTH_SASL_START && msg -> hdr . proc != REMOTE_PROC_AUTH_SASL_STEP && msg -> hdr . proc != REMOTE_PROC_AUTH_POLKIT ) {
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "authentication required" ) ) ;
 goto rpc_error ;
 }
 }
 if ( qemu_protocol ) data = qemuGetDispatchData ( msg -> hdr . proc ) ;
 else data = remoteGetDispatchData ( msg -> hdr . proc ) ;
 if ( ! data ) {
 remoteDispatchFormatError ( & rerr , _ ( "unknown procedure: %d" ) , msg -> hdr . proc ) ;
 goto rpc_error ;
 }
 xdrmem_create ( & xdr , msg -> buffer + msg -> bufferOffset , msg -> bufferLength - msg -> bufferOffset , XDR_DECODE ) ;
 if ( ! ( ( data -> args_filter ) ( & xdr , & args ) ) ) {
 xdr_destroy ( & xdr ) ;
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "parse args failed" ) ) ;
 goto rpc_error ;
 }
 xdr_destroy ( & xdr ) ;
 conn = client -> conn ;
 virMutexUnlock ( & client -> lock ) ;
 rv = ( data -> fn ) ( server , client , conn , & msg -> hdr , & rerr , & args , & ret ) ;
 virMutexLock ( & server -> lock ) ;
 virMutexLock ( & client -> lock ) ;
 virMutexUnlock ( & server -> lock ) ;
 xdr_free ( data -> args_filter , ( char * ) & args ) ;
 if ( rv < 0 ) goto rpc_error ;
 msg -> hdr . type = REMOTE_REPLY ;
 msg -> hdr . status = REMOTE_OK ;
 if ( remoteEncodeClientMessageHeader ( msg ) < 0 ) {
 xdr_free ( data -> ret_filter , ( char * ) & ret ) ;
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "failed to serialize reply header" ) ) ;
 goto xdr_hdr_error ;
 }
 xdrmem_create ( & xdr , msg -> buffer , msg -> bufferLength , XDR_ENCODE ) ;
 if ( xdr_setpos ( & xdr , msg -> bufferOffset ) == 0 ) {
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "failed to change XDR reply offset" ) ) ;
 goto xdr_error ;
 }
 if ( ! ( ( data -> ret_filter ) ( & xdr , & ret ) ) ) {
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "failed to serialize reply payload (probable message size limit)" ) ) ;
 goto xdr_error ;
 }
 msg -> bufferOffset += xdr_getpos ( & xdr ) ;
 len = msg -> bufferOffset ;
 if ( xdr_setpos ( & xdr , 0 ) == 0 ) {
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "failed to change XDR reply offset" ) ) ;
 goto xdr_error ;
 }
 if ( ! xdr_u_int ( & xdr , & len ) ) {
 remoteDispatchFormatError ( & rerr , "%s" , _ ( "failed to update reply length header" ) ) ;
 goto xdr_error ;
 }
 xdr_destroy ( & xdr ) ;
 xdr_free ( data -> ret_filter , ( char * ) & ret ) ;
 msg -> bufferLength = len ;
 msg -> bufferOffset = 0 ;
 qemudClientMessageQueuePush ( & client -> tx , msg ) ;
 qemudUpdateClientEvent ( client ) ;
 return 0 ;
 xdr_error : xdr_free ( data -> ret_filter , ( char * ) & ret ) ;
 xdr_destroy ( & xdr ) ;
 xdr_hdr_error : VIR_WARN ( "Failed to serialize reply for program '%d' proc '%d' as XDR" , msg -> hdr . prog , msg -> hdr . proc ) ;
 rpc_error : rv = remoteSerializeReplyError ( client , & rerr , & msg -> hdr ) ;
 if ( rv >= 0 ) VIR_FREE ( msg ) ;
 return rv ;
 }


convert(
    Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither) {
    ImagingSectionCookie cookie;
    ImagingShuffler convert;
    int y;

    if (!imIn) {
        return (Imaging)ImagingError_ModeError();
    }

    if (!mode) {
        /* Map palette image to full depth */
        if (!imIn->palette) {
            return (Imaging)ImagingError_ModeError();
        }
        mode = imIn->palette->mode;
    } else {
        /* Same mode? */
        if (!strcmp(imIn->mode, mode)) {
            return ImagingCopy2(imOut, imIn);
        }
    }

    /* test for special conversions */

    if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "PA") == 0) {
        return frompalette(imOut, imIn, mode);
    }

    if (strcmp(mode, "P") == 0 || strcmp(mode, "PA") == 0) {
        return topalette(imOut, imIn, mode, palette, dither);
    }

    if (dither && strcmp(mode, "1") == 0) {
        return tobilevel(imOut, imIn, dither);
    }

    /* standard conversion machinery */

    convert = NULL;

    for (y = 0; converters[y].from; y++) {
        if (!strcmp(imIn->mode, converters[y].from) &&
            !strcmp(mode, converters[y].to)) {
            convert = converters[y].convert;
            break;
        }
    }

    if (!convert) {
#ifdef notdef
        return (Imaging)ImagingError_ValueError("conversion not supported");
#else
        static char buf[256];
        /* FIXME: may overflow if mode is too large */
        sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode);
        return (Imaging)ImagingError_ValueError(buf);
#endif
    }

    imOut = ImagingNew2Dirty(mode, imOut, imIn);
    if (!imOut) {
        return NULL;
    }

    ImagingSectionEnter(&cookie);
    for (y = 0; y < imIn->ysize; y++) {
        (*convert)((UINT8 *)imOut->image[y], (UINT8 *)imIn->image[y], imIn->xsize);
    }
    ImagingSectionLeave(&cookie);

    return imOut;
}


static int qcow_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVQcowState *s = bs->opaque; int len, i, shift, ret; QCowHeader header; ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { be32_to_cpus(&header.magic); be32_to_cpus(&header.version); be64_to_cpus(&header.backing_file_offset); be32_to_cpus(&header.backing_file_size); be32_to_cpus(&header.mtime); be64_to_cpus(&header.size); be32_to_cpus(&header.crypt_method); be64_to_cpus(&header.l1_table_offset); if (header.magic != QCOW_MAGIC) { error_setg(errp, "Image not in qcow format"); if (header.version != QCOW_VERSION) { char version[64]; snprintf(version, sizeof(version), "QCOW version %" PRIu32, header.version); error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, bs->device_name, "qcow", version); ret = -ENOTSUP; if (header.size <= 1) { error_setg(errp, "Image size is too small (must be at least 2 bytes)"); if (header.cluster_bits < 9 || header.cluster_bits > 16) { error_setg(errp, "Cluster size must be between 512 and 64k"); if (header.crypt_method > QCOW_CRYPT_AES) { error_setg(errp, "invalid encryption method in qcow header"); s->crypt_method_header = header.crypt_method; if (s->crypt_method_header) { bs->encrypted = 1; s->cluster_bits = header.cluster_bits; s->cluster_size = 1 << s->cluster_bits; s->cluster_sectors = 1 << (s->cluster_bits - 9); s->l2_bits = header.l2_bits; s->l2_size = 1 << s->l2_bits; bs->total_sectors = header.size / 512; s->cluster_offset_mask = (1LL << (63 - s->cluster_bits)) - 1; /* read the level 1 table */ shift = s->cluster_bits + s->l2_bits; s->l1_size = (header.size + (1LL << shift) - 1) >> shift; s->l1_table_offset = header.l1_table_offset; s->l1_table = g_malloc(s->l1_size * sizeof(uint64_t)); ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)); if (ret < 0) { for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); /* alloc L2 cache */ s->l2_cache = g_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); s->cluster_cache = g_malloc(s->cluster_size); s->cluster_data = g_malloc(s->cluster_size); s->cluster_cache_offset = -1; /* read the backing file name */ if (header.backing_file_offset != 0) { len = header.backing_file_size; if (len > 1023) { len = 1023; ret = bdrv_pread(bs->file, header.backing_file_offset, bs->backing_file, len); if (ret < 0) { bs->backing_file[len] = '\0'; /* Disable migration when qcow images are used */ error_set(&s->migration_blocker, QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED, "qcow", bs->device_name, "live migration"); migrate_add_blocker(s->migration_blocker); qemu_co_mutex_init(&s->lock); return 0; fail: g_free(s->l1_table); g_free(s->l2_cache); g_free(s->cluster_cache); g_free(s->cluster_data); return ret;


void OPPROTO op_idivw_AX_T0(void) { int num, den, q, r; num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); den = (int16_t)T0; if (den == 0) { raise_exception(EXCP00_DIVZ); } q = (num / den) & 0xffff; r = (num % den) & 0xffff; EAX = (EAX & ~0xffff) | q; EDX = (EDX & ~0xffff) | r; }


static gboolean fd_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) { CharDriverState *chr = opaque; FDCharDriver *s = chr->opaque; int len; uint8_t buf[READ_BUF_LEN]; GIOStatus status; gsize bytes_read; len = sizeof(buf); if (len > s->max_size) { len = s->max_size; } if (len == 0) { return TRUE; } status = g_io_channel_read_chars(chan, (gchar *)buf, len, &bytes_read, NULL); if (status == G_IO_STATUS_EOF) { if (s->fd_in_tag) { g_source_remove(s->fd_in_tag); s->fd_in_tag = 0; } qemu_chr_be_event(chr, CHR_EVENT_CLOSED); return FALSE; } if (status == G_IO_STATUS_NORMAL) { qemu_chr_be_write(chr, buf, bytes_read); } return TRUE; }


void hmp_drive_add_node(Monitor *mon, const char *optstr) { QemuOpts *opts; QDict *qdict; Error *local_err = NULL; opts = qemu_opts_parse_noisily(&qemu_drive_opts, optstr, false); if (!opts) { return; } qdict = qemu_opts_to_qdict(opts, NULL); if (!qdict_get_try_str(qdict, "node-name")) { error_report("'node-name' needs to be specified"); goto out; } BlockDriverState *bs = bds_tree_init(qdict, &local_err); if (!bs) { error_report_err(local_err); goto out; } QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); out: qemu_opts_del(opts); }


void cpu_breakpoint_remove_all(CPUState *cpu, int mask) { #if defined(TARGET_HAS_ICE) CPUBreakpoint *bp, *next; QTAILQ_FOREACH_SAFE(bp, &cpu->breakpoints, entry, next) { if (bp->flags & mask) { cpu_breakpoint_remove_by_ref(cpu, bp); } } #endif }


static void _UTF7FromUnicodeWithOffsets ( UConverterFromUnicodeArgs * pArgs , UErrorCode * pErrorCode ) {
 UConverter * cnv ;
 const UChar * source , * sourceLimit ;
 uint8_t * target , * targetLimit ;
 int32_t * offsets ;
 int32_t length , targetCapacity , sourceIndex ;
 UChar c ;
 const UBool * encodeDirectly ;
 uint8_t bits ;
 int8_t base64Counter ;
 UBool inDirectMode ;
 cnv = pArgs -> converter ;
 source = pArgs -> source ;
 sourceLimit = pArgs -> sourceLimit ;
 target = ( uint8_t * ) pArgs -> target ;
 targetLimit = ( uint8_t * ) pArgs -> targetLimit ;
 offsets = pArgs -> offsets ;
 {
 uint32_t status = cnv -> fromUnicodeStatus ;
 encodeDirectly = status < 0x10000000 ? encodeDirectlyMaximum : encodeDirectlyRestricted ;
 inDirectMode = ( UBool ) ( ( status >> 24 ) & 1 ) ;
 base64Counter = ( int8_t ) ( status >> 16 ) ;
 bits = ( uint8_t ) status ;
 U_ASSERT ( bits <= UPRV_LENGTHOF ( toBase64 ) ) ;
 }
 sourceIndex = 0 ;
 if ( inDirectMode ) {
 directMode : length = ( int32_t ) ( sourceLimit - source ) ;
 targetCapacity = ( int32_t ) ( targetLimit - target ) ;
 if ( length > targetCapacity ) {
 length = targetCapacity ;
 }
 while ( length > 0 ) {
 c = * source ++ ;
 if ( c <= 127 && encodeDirectly [ c ] ) {
 * target ++ = ( uint8_t ) c ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ++ ;
 }
 }
 else if ( c == PLUS ) {
 * target ++ = PLUS ;
 if ( target < targetLimit ) {
 * target ++ = MINUS ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ++ ;
 }
 goto directMode ;
 }
 else {
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ++ ;
 }
 cnv -> charErrorBuffer [ 0 ] = MINUS ;
 cnv -> charErrorBufferLength = 1 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 break ;
 }
 }
 else {
 -- source ;
 * target ++ = PLUS ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 }
 inDirectMode = FALSE ;
 base64Counter = 0 ;
 goto unicodeMode ;
 }
 -- length ;
 }
 if ( source < sourceLimit && target >= targetLimit ) {
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 }
 else {
 unicodeMode : while ( source < sourceLimit ) {
 if ( target < targetLimit ) {
 c = * source ++ ;
 if ( c <= 127 && encodeDirectly [ c ] ) {
 inDirectMode = TRUE ;
 -- source ;
 if ( base64Counter != 0 ) {
 * target ++ = toBase64 [ bits ] ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex - 1 ;
 }
 }
 if ( fromBase64 [ c ] != - 1 ) {
 if ( target < targetLimit ) {
 * target ++ = MINUS ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex - 1 ;
 }
 }
 else {
 cnv -> charErrorBuffer [ 0 ] = MINUS ;
 cnv -> charErrorBufferLength = 1 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 break ;
 }
 }
 goto directMode ;
 }
 else {
 switch ( base64Counter ) {
 case 0 : * target ++ = toBase64 [ c >> 10 ] ;
 if ( target < targetLimit ) {
 * target ++ = toBase64 [ ( c >> 4 ) & 0x3f ] ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ++ ;
 }
 }
 else {
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ++ ;
 }
 cnv -> charErrorBuffer [ 0 ] = toBase64 [ ( c >> 4 ) & 0x3f ] ;
 cnv -> charErrorBufferLength = 1 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 bits = ( uint8_t ) ( ( c & 15 ) << 2 ) ;
 base64Counter = 1 ;
 break ;
 case 1 : * target ++ = toBase64 [ bits | ( c >> 14 ) ] ;
 if ( target < targetLimit ) {
 * target ++ = toBase64 [ ( c >> 8 ) & 0x3f ] ;
 if ( target < targetLimit ) {
 * target ++ = toBase64 [ ( c >> 2 ) & 0x3f ] ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ++ ;
 }
 }
 else {
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ++ ;
 }
 cnv -> charErrorBuffer [ 0 ] = toBase64 [ ( c >> 2 ) & 0x3f ] ;
 cnv -> charErrorBufferLength = 1 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 }
 else {
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ++ ;
 }
 cnv -> charErrorBuffer [ 0 ] = toBase64 [ ( c >> 8 ) & 0x3f ] ;
 cnv -> charErrorBuffer [ 1 ] = toBase64 [ ( c >> 2 ) & 0x3f ] ;
 cnv -> charErrorBufferLength = 2 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 bits = ( uint8_t ) ( ( c & 3 ) << 4 ) ;
 base64Counter = 2 ;
 break ;
 case 2 : * target ++ = toBase64 [ bits | ( c >> 12 ) ] ;
 if ( target < targetLimit ) {
 * target ++ = toBase64 [ ( c >> 6 ) & 0x3f ] ;
 if ( target < targetLimit ) {
 * target ++ = toBase64 [ c & 0x3f ] ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ++ ;
 }
 }
 else {
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ;
 * offsets ++ = sourceIndex ++ ;
 }
 cnv -> charErrorBuffer [ 0 ] = toBase64 [ c & 0x3f ] ;
 cnv -> charErrorBufferLength = 1 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 }
 else {
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex ++ ;
 }
 cnv -> charErrorBuffer [ 0 ] = toBase64 [ ( c >> 6 ) & 0x3f ] ;
 cnv -> charErrorBuffer [ 1 ] = toBase64 [ c & 0x3f ] ;
 cnv -> charErrorBufferLength = 2 ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 bits = 0 ;
 base64Counter = 0 ;
 break ;
 default : break ;
 }
 }
 }
 else {
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 break ;
 }
 }
 }
 if ( pArgs -> flush && source >= sourceLimit ) {
 if ( ! inDirectMode ) {
 if ( base64Counter != 0 ) {
 if ( target < targetLimit ) {
 * target ++ = toBase64 [ bits ] ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex - 1 ;
 }
 }
 else {
 cnv -> charErrorBuffer [ cnv -> charErrorBufferLength ++ ] = toBase64 [ bits ] ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 }
 if ( target < targetLimit ) {
 * target ++ = MINUS ;
 if ( offsets != NULL ) {
 * offsets ++ = sourceIndex - 1 ;
 }
 }
 else {
 cnv -> charErrorBuffer [ cnv -> charErrorBufferLength ++ ] = MINUS ;
 * pErrorCode = U_BUFFER_OVERFLOW_ERROR ;
 }
 }
 cnv -> fromUnicodeStatus = ( cnv -> fromUnicodeStatus & 0xf0000000 ) | 0x1000000 ;
 }
 else {
 cnv -> fromUnicodeStatus = ( cnv -> fromUnicodeStatus & 0xf0000000 ) | ( ( uint32_t ) inDirectMode << 24 ) | ( ( uint32_t ) base64Counter << 16 ) | ( uint32_t ) bits ;
 }
 pArgs -> source = source ;
 pArgs -> target = ( char * ) target ;
 pArgs -> offsets = offsets ;
 return ;
 }


static void test_bug28505 ( ) {
 my_ulonglong res ;
 myquery ( mysql_query ( mysql , "drop table if exists t1" ) ) ;
 myquery ( mysql_query ( mysql , "create table t1(f1 int primary key)" ) ) ;
 myquery ( mysql_query ( mysql , "insert into t1 values(1)" ) ) ;
 myquery ( mysql_query ( mysql , "insert into t1 values(1) on duplicate key update f1=1" ) ) ;
 res = mysql_affected_rows ( mysql ) ;
 DIE_UNLESS ( ! res ) ;
 myquery ( mysql_query ( mysql , "drop table t1" ) ) ;
 }


static void ne2000_receive(void *opaque, const uint8_t *buf, int size) { NE2000State *s = opaque; uint8_t *p; int total_len, next, avail, len, index, mcast_idx; uint8_t buf1[60]; static const uint8_t broadcast_macaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; #if defined(DEBUG_NE2000) printf("NE2000: received len=%d\n", size); #endif if (s->cmd & E8390_STOP || ne2000_buffer_full(s)) return; /* XXX: check this */ if (s->rxcr & 0x10) { /* promiscuous: receive all */ } else { if (!memcmp(buf, broadcast_macaddr, 6)) { /* broadcast address */ if (!(s->rxcr & 0x04)) return; } else if (buf[0] & 0x01) { /* multicast */ if (!(s->rxcr & 0x08)) return; mcast_idx = compute_mcast_idx(buf); if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) return; } else if (s->mem[0] == buf[0] && s->mem[2] == buf[1] && s->mem[4] == buf[2] && s->mem[6] == buf[3] && s->mem[8] == buf[4] && s->mem[10] == buf[5]) { /* match */ } else { return; } } /* if too small buffer, then expand it */ if (size < MIN_BUF_SIZE) { memcpy(buf1, buf, size); memset(buf1 + size, 0, MIN_BUF_SIZE - size); buf = buf1; size = MIN_BUF_SIZE; } index = s->curpag << 8; /* 4 bytes for header */ total_len = size + 4; /* address for next packet (4 bytes for CRC) */ next = index + ((total_len + 4 + 255) & ~0xff); if (next >= s->stop) next -= (s->stop - s->start); /* prepare packet header */ p = s->mem + index; s->rsr = ENRSR_RXOK; /* receive status */ /* XXX: check this */ if (buf[0] & 0x01) s->rsr |= ENRSR_PHY; p[0] = s->rsr; p[1] = next >> 8; p[2] = total_len; p[3] = total_len >> 8; index += 4; /* write packet data */ while (size > 0) { avail = s->stop - index; len = size; if (len > avail) len = avail; memcpy(s->mem + index, buf, len); buf += len; index += len; if (index == s->stop) index = s->start; size -= len; } s->curpag = next >> 8; /* now we can signal we have received something */ s->isr |= ENISR_RX; ne2000_update_irq(s); }


SWTPM_NVRAM_CheckHeader(unsigned char *data, uint32_t length,
                        uint32_t *dataoffset, uint16_t *hdrflags,
                        uint8_t *hdrversion, bool quiet)
{
    blobheader *bh = (blobheader *)data;

    if (length < sizeof(bh)) {
        if (!quiet)
            logprintf(STDERR_FILENO,
                      "not enough bytes for header: %u\n", length);
        return TPM_BAD_PARAMETER;
    }

    if (ntohl(bh->totlen) != length) {
        if (!quiet)
            logprintf(STDERR_FILENO,
                      "broken header: bh->totlen %u != %u\n",
                      htonl(bh->totlen), length);
        return TPM_BAD_PARAMETER;
    }

    if (bh->min_version > BLOB_HEADER_VERSION) {
        if (!quiet)
            logprintf(STDERR_FILENO,
                      "Minimum required version for the blob is %d, we "
                      "only support version %d\n", bh->min_version,
                      BLOB_HEADER_VERSION);
        return TPM_BAD_VERSION;
    }

    *hdrversion = bh->version;
    *dataoffset = ntohs(bh->hdrsize);
    *hdrflags = ntohs(bh->flags);

    return TPM_SUCCESS;
}


static void report_progress_end ( ) {
 if ( last_progress_report_length ) {
 printf ( "%*s\r" , last_progress_report_length , "" ) ;
 last_progress_report_length = 0 ;
 }
 }


static void setup_rt_frame(int sig, struct target_sigaction *ka, target_siginfo_t *info, target_sigset_t *set, CPUPPCState *env) { struct target_rt_sigframe *rt_sf; struct target_mcontext *frame; target_ulong rt_sf_addr, newsp = 0; int i, err = 0; int signal; rt_sf_addr = get_sigframe(ka, env, sizeof(*rt_sf)); if (!lock_user_struct(VERIFY_WRITE, rt_sf, rt_sf_addr, 1)) goto sigsegv; signal = current_exec_domain_sig(sig); copy_siginfo_to_user(&rt_sf->info, info); __put_user(0, &rt_sf->uc.tuc_flags); __put_user(0, &rt_sf->uc.tuc_link); __put_user((target_ulong)target_sigaltstack_used.ss_sp, &rt_sf->uc.tuc_stack.ss_sp); __put_user(sas_ss_flags(env->gpr[1]), &rt_sf->uc.tuc_stack.ss_flags); __put_user(target_sigaltstack_used.ss_size, &rt_sf->uc.tuc_stack.ss_size); __put_user(h2g (&rt_sf->uc.tuc_mcontext), &rt_sf->uc.tuc_regs); for(i = 0; i < TARGET_NSIG_WORDS; i++) { __put_user(set->sig[i], &rt_sf->uc.tuc_sigmask.sig[i]); } frame = &rt_sf->uc.tuc_mcontext; err |= save_user_regs(env, frame, TARGET_NR_rt_sigreturn); /* The kernel checks for the presence of a VDSO here. We don't emulate a vdso, so use a sigreturn system call. */ env->lr = (target_ulong) h2g(frame->tramp); /* Turn off all fp exceptions. */ env->fpscr = 0; /* Create a stack frame for the caller of the handler. */ newsp = rt_sf_addr - (SIGNAL_FRAMESIZE + 16); __put_user(env->gpr[1], (target_ulong *)(uintptr_t) newsp); if (err) goto sigsegv; /* Set up registers for signal handler. */ env->gpr[1] = newsp; env->gpr[3] = (target_ulong) signal; env->gpr[4] = (target_ulong) h2g(&rt_sf->info); env->gpr[5] = (target_ulong) h2g(&rt_sf->uc); env->gpr[6] = (target_ulong) h2g(rt_sf); env->nip = (target_ulong) ka->_sa_handler; /* Signal handlers are entered in big-endian mode. */ env->msr &= ~MSR_LE; unlock_user_struct(rt_sf, rt_sf_addr, 1); return; sigsegv: unlock_user_struct(rt_sf, rt_sf_addr, 1); qemu_log("segfaulting from setup_rt_frame\n"); force_sig(TARGET_SIGSEGV); }


IN_PROC_BROWSER_TEST_F ( ClientHintsBrowserTest , DisregardPersistenceRequestIframe ) {
 base : : HistogramTester histogram_tester ;
 ContentSettingsForOneType host_settings ;
 HostContentSettingsMapFactory : : GetForProfile ( browser ( ) -> profile ( ) ) -> GetSettingsForOneType ( CONTENT_SETTINGS_TYPE_CLIENT_HINTS , std : : string ( ) , & host_settings ) ;
 EXPECT_EQ ( 0u , host_settings . size ( ) ) ;
 ui_test_utils : : NavigateToURL ( browser ( ) , accept_ch_without_lifetime_with_iframe_url ( ) ) ;
 histogram_tester . ExpectTotalCount ( "ClientHints.UpdateEventCount" , 0 ) ;
 content : : FetchHistogramsFromChildProcesses ( ) ;
 SubprocessMetricsProvider : : MergeHistogramDeltasForTesting ( ) ;
 histogram_tester . ExpectTotalCount ( "ClientHints.UpdateSize" , 0 ) ;
 histogram_tester . ExpectTotalCount ( "ClientHints.PersistDuration" , 0 ) ;
 }


static void mongolian_variation_selectors ( hb_buffer_t * buffer ) {
 unsigned int count = buffer -> len ;
 hb_glyph_info_t * info = buffer -> info ;
 for ( unsigned int i = 1 ;
 i < count ;
 i ++ ) if ( unlikely ( hb_in_range ( info [ i ] . codepoint , 0x180Bu , 0x180Du ) ) ) info [ i ] . arabic_shaping_action ( ) = info [ i - 1 ] . arabic_shaping_action ( ) ;
 }


static int64_t rd_pick_best_sub8x8_mode ( VP9_COMP * cpi , MACROBLOCK * x , const TileInfo * const tile , int_mv * best_ref_mv , int_mv * second_best_ref_mv , int64_t best_rd , int * returntotrate , int * returnyrate , int64_t * returndistortion , int * skippable , int64_t * psse , int mvthresh , int_mv seg_mvs [ 4 ] [ MAX_REF_FRAMES ] , BEST_SEG_INFO * bsi_buf , int filter_idx , int mi_row , int mi_col ) {
 int i ;
 BEST_SEG_INFO * bsi = bsi_buf + filter_idx ;
 MACROBLOCKD * xd = & x -> e_mbd ;
 MODE_INFO * mi = xd -> mi [ 0 ] . src_mi ;
 MB_MODE_INFO * mbmi = & mi -> mbmi ;
 int mode_idx ;
 int k , br = 0 , idx , idy ;
 int64_t bd = 0 , block_sse = 0 ;
 PREDICTION_MODE this_mode ;
 VP9_COMMON * cm = & cpi -> common ;
 struct macroblock_plane * const p = & x -> plane [ 0 ] ;
 struct macroblockd_plane * const pd = & xd -> plane [ 0 ] ;
 const int label_count = 4 ;
 int64_t this_segment_rd = 0 ;
 int label_mv_thresh ;
 int segmentyrate = 0 ;
 const BLOCK_SIZE bsize = mbmi -> sb_type ;
 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup [ bsize ] ;
 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup [ bsize ] ;
 ENTROPY_CONTEXT t_above [ 2 ] , t_left [ 2 ] ;
 int subpelmv = 1 , have_ref = 0 ;
 const int has_second_rf = has_second_ref ( mbmi ) ;
 const int inter_mode_mask = cpi -> sf . inter_mode_mask [ bsize ] ;
 vp9_zero ( * bsi ) ;
 bsi -> segment_rd = best_rd ;
 bsi -> ref_mv [ 0 ] = best_ref_mv ;
 bsi -> ref_mv [ 1 ] = second_best_ref_mv ;
 bsi -> mvp . as_int = best_ref_mv -> as_int ;
 bsi -> mvthresh = mvthresh ;
 for ( i = 0 ;
 i < 4 ;
 i ++ ) bsi -> modes [ i ] = ZEROMV ;
 vpx_memcpy ( t_above , pd -> above_context , sizeof ( t_above ) ) ;
 vpx_memcpy ( t_left , pd -> left_context , sizeof ( t_left ) ) ;
 label_mv_thresh = 1 * bsi -> mvthresh / label_count ;
 for ( idy = 0 ;
 idy < 2 ;
 idy += num_4x4_blocks_high ) {
 for ( idx = 0 ;
 idx < 2 ;
 idx += num_4x4_blocks_wide ) {
 int_mv mode_mv [ MB_MODE_COUNT ] [ 2 ] ;
 int_mv frame_mv [ MB_MODE_COUNT ] [ MAX_REF_FRAMES ] ;
 PREDICTION_MODE mode_selected = ZEROMV ;
 int64_t best_rd = INT64_MAX ;
 const int i = idy * 2 + idx ;
 int ref ;
 for ( ref = 0 ;
 ref < 1 + has_second_rf ;
 ++ ref ) {
 const MV_REFERENCE_FRAME frame = mbmi -> ref_frame [ ref ] ;
 frame_mv [ ZEROMV ] [ frame ] . as_int = 0 ;
 vp9_append_sub8x8_mvs_for_idx ( cm , xd , tile , i , ref , mi_row , mi_col , & frame_mv [ NEARESTMV ] [ frame ] , & frame_mv [ NEARMV ] [ frame ] ) ;
 }
 for ( this_mode = NEARESTMV ;
 this_mode <= NEWMV ;
 ++ this_mode ) {
 const struct buf_2d orig_src = x -> plane [ 0 ] . src ;
 struct buf_2d orig_pre [ 2 ] ;
 mode_idx = INTER_OFFSET ( this_mode ) ;
 bsi -> rdstat [ i ] [ mode_idx ] . brdcost = INT64_MAX ;
 if ( ! ( inter_mode_mask & ( 1 << this_mode ) ) ) continue ;
 if ( ! check_best_zero_mv ( cpi , mbmi -> mode_context , frame_mv , this_mode , mbmi -> ref_frame ) ) continue ;
 vpx_memcpy ( orig_pre , pd -> pre , sizeof ( orig_pre ) ) ;
 vpx_memcpy ( bsi -> rdstat [ i ] [ mode_idx ] . ta , t_above , sizeof ( bsi -> rdstat [ i ] [ mode_idx ] . ta ) ) ;
 vpx_memcpy ( bsi -> rdstat [ i ] [ mode_idx ] . tl , t_left , sizeof ( bsi -> rdstat [ i ] [ mode_idx ] . tl ) ) ;
 if ( ! has_second_rf && this_mode == NEWMV && seg_mvs [ i ] [ mbmi -> ref_frame [ 0 ] ] . as_int == INVALID_MV ) {
 MV * const new_mv = & mode_mv [ NEWMV ] [ 0 ] . as_mv ;
 int step_param = 0 ;
 int thissme , bestsme = INT_MAX ;
 int sadpb = x -> sadperbit4 ;
 MV mvp_full ;
 int max_mv ;
 int sad_list [ 5 ] ;
 if ( best_rd < label_mv_thresh ) break ;
 if ( cpi -> oxcf . mode != BEST ) {
 if ( i > 0 ) {
 bsi -> mvp . as_int = mi -> bmi [ i - 1 ] . as_mv [ 0 ] . as_int ;
 if ( i == 2 ) bsi -> mvp . as_int = mi -> bmi [ i - 2 ] . as_mv [ 0 ] . as_int ;
 }
 }
 if ( i == 0 ) max_mv = x -> max_mv_context [ mbmi -> ref_frame [ 0 ] ] ;
 else max_mv = MAX ( abs ( bsi -> mvp . as_mv . row ) , abs ( bsi -> mvp . as_mv . col ) ) >> 3 ;
 if ( cpi -> sf . mv . auto_mv_step_size && cm -> show_frame ) {
 step_param = ( vp9_init_search_range ( max_mv ) + cpi -> mv_step_param ) / 2 ;
 }
 else {
 step_param = cpi -> mv_step_param ;
 }
 mvp_full . row = bsi -> mvp . as_mv . row >> 3 ;
 mvp_full . col = bsi -> mvp . as_mv . col >> 3 ;
 if ( cpi -> sf . adaptive_motion_search ) {
 mvp_full . row = x -> pred_mv [ mbmi -> ref_frame [ 0 ] ] . row >> 3 ;
 mvp_full . col = x -> pred_mv [ mbmi -> ref_frame [ 0 ] ] . col >> 3 ;
 step_param = MAX ( step_param , 8 ) ;
 }
 mi_buf_shift ( x , i ) ;
 vp9_set_mv_search_range ( x , & bsi -> ref_mv [ 0 ] -> as_mv ) ;
 bestsme = vp9_full_pixel_search ( cpi , x , bsize , & mvp_full , step_param , sadpb , cpi -> sf . mv . subpel_search_method != SUBPEL_TREE ? sad_list : NULL , & bsi -> ref_mv [ 0 ] -> as_mv , new_mv , INT_MAX , 1 ) ;
 if ( cpi -> oxcf . mode == BEST ) {
 int_mv * const best_mv = & mi -> bmi [ i ] . as_mv [ 0 ] ;
 clamp_mv ( & mvp_full , x -> mv_col_min , x -> mv_col_max , x -> mv_row_min , x -> mv_row_max ) ;
 thissme = cpi -> full_search_sad ( x , & mvp_full , sadpb , 16 , & cpi -> fn_ptr [ bsize ] , & bsi -> ref_mv [ 0 ] -> as_mv , & best_mv -> as_mv ) ;
 sad_list [ 1 ] = sad_list [ 2 ] = sad_list [ 3 ] = sad_list [ 4 ] = INT_MAX ;
 if ( thissme < bestsme ) {
 bestsme = thissme ;
 * new_mv = best_mv -> as_mv ;
 }
 else {
 best_mv -> as_mv = * new_mv ;
 }
 }
 if ( bestsme < INT_MAX ) {
 int distortion ;
 cpi -> find_fractional_mv_step ( x , new_mv , & bsi -> ref_mv [ 0 ] -> as_mv , cm -> allow_high_precision_mv , x -> errorperbit , & cpi -> fn_ptr [ bsize ] , cpi -> sf . mv . subpel_force_stop , cpi -> sf . mv . subpel_iters_per_step , cond_sad_list ( cpi , sad_list ) , x -> nmvjointcost , x -> mvcost , & distortion , & x -> pred_sse [ mbmi -> ref_frame [ 0 ] ] , NULL , 0 , 0 ) ;
 seg_mvs [ i ] [ mbmi -> ref_frame [ 0 ] ] . as_mv = * new_mv ;
 }
 if ( cpi -> sf . adaptive_motion_search ) x -> pred_mv [ mbmi -> ref_frame [ 0 ] ] = * new_mv ;
 mi_buf_restore ( x , orig_src , orig_pre ) ;
 }
 if ( has_second_rf ) {
 if ( seg_mvs [ i ] [ mbmi -> ref_frame [ 1 ] ] . as_int == INVALID_MV || seg_mvs [ i ] [ mbmi -> ref_frame [ 0 ] ] . as_int == INVALID_MV ) continue ;
 }
 if ( has_second_rf && this_mode == NEWMV && mbmi -> interp_filter == EIGHTTAP ) {
 mi_buf_shift ( x , i ) ;
 if ( cpi -> sf . comp_inter_joint_search_thresh <= bsize ) {
 int rate_mv ;
 joint_motion_search ( cpi , x , bsize , frame_mv [ this_mode ] , mi_row , mi_col , seg_mvs [ i ] , & rate_mv ) ;
 seg_mvs [ i ] [ mbmi -> ref_frame [ 0 ] ] . as_int = frame_mv [ this_mode ] [ mbmi -> ref_frame [ 0 ] ] . as_int ;
 seg_mvs [ i ] [ mbmi -> ref_frame [ 1 ] ] . as_int = frame_mv [ this_mode ] [ mbmi -> ref_frame [ 1 ] ] . as_int ;
 }
 mi_buf_restore ( x , orig_src , orig_pre ) ;
 }
 bsi -> rdstat [ i ] [ mode_idx ] . brate = set_and_cost_bmi_mvs ( cpi , xd , i , this_mode , mode_mv [ this_mode ] , frame_mv , seg_mvs [ i ] , bsi -> ref_mv , x -> nmvjointcost , x -> mvcost ) ;
 for ( ref = 0 ;
 ref < 1 + has_second_rf ;
 ++ ref ) {
 bsi -> rdstat [ i ] [ mode_idx ] . mvs [ ref ] . as_int = mode_mv [ this_mode ] [ ref ] . as_int ;
 if ( num_4x4_blocks_wide > 1 ) bsi -> rdstat [ i + 1 ] [ mode_idx ] . mvs [ ref ] . as_int = mode_mv [ this_mode ] [ ref ] . as_int ;
 if ( num_4x4_blocks_high > 1 ) bsi -> rdstat [ i + 2 ] [ mode_idx ] . mvs [ ref ] . as_int = mode_mv [ this_mode ] [ ref ] . as_int ;
 }
 if ( mv_check_bounds ( x , & mode_mv [ this_mode ] [ 0 ] . as_mv ) || ( has_second_rf && mv_check_bounds ( x , & mode_mv [ this_mode ] [ 1 ] . as_mv ) ) ) continue ;
 if ( filter_idx > 0 ) {
 BEST_SEG_INFO * ref_bsi = bsi_buf ;
 subpelmv = 0 ;
 have_ref = 1 ;
 for ( ref = 0 ;
 ref < 1 + has_second_rf ;
 ++ ref ) {
 subpelmv |= mv_has_subpel ( & mode_mv [ this_mode ] [ ref ] . as_mv ) ;
 have_ref &= mode_mv [ this_mode ] [ ref ] . as_int == ref_bsi -> rdstat [ i ] [ mode_idx ] . mvs [ ref ] . as_int ;
 }
 if ( filter_idx > 1 && ! subpelmv && ! have_ref ) {
 ref_bsi = bsi_buf + 1 ;
 have_ref = 1 ;
 for ( ref = 0 ;
 ref < 1 + has_second_rf ;
 ++ ref ) have_ref &= mode_mv [ this_mode ] [ ref ] . as_int == ref_bsi -> rdstat [ i ] [ mode_idx ] . mvs [ ref ] . as_int ;
 }
 if ( ! subpelmv && have_ref && ref_bsi -> rdstat [ i ] [ mode_idx ] . brdcost < INT64_MAX ) {
 vpx_memcpy ( & bsi -> rdstat [ i ] [ mode_idx ] , & ref_bsi -> rdstat [ i ] [ mode_idx ] , sizeof ( SEG_RDSTAT ) ) ;
 if ( num_4x4_blocks_wide > 1 ) bsi -> rdstat [ i + 1 ] [ mode_idx ] . eobs = ref_bsi -> rdstat [ i + 1 ] [ mode_idx ] . eobs ;
 if ( num_4x4_blocks_high > 1 ) bsi -> rdstat [ i + 2 ] [ mode_idx ] . eobs = ref_bsi -> rdstat [ i + 2 ] [ mode_idx ] . eobs ;
 if ( bsi -> rdstat [ i ] [ mode_idx ] . brdcost < best_rd ) {
 mode_selected = this_mode ;
 best_rd = bsi -> rdstat [ i ] [ mode_idx ] . brdcost ;
 }
 continue ;
 }
 }
 bsi -> rdstat [ i ] [ mode_idx ] . brdcost = encode_inter_mb_segment ( cpi , x , bsi -> segment_rd - this_segment_rd , i , & bsi -> rdstat [ i ] [ mode_idx ] . byrate , & bsi -> rdstat [ i ] [ mode_idx ] . bdist , & bsi -> rdstat [ i ] [ mode_idx ] . bsse , bsi -> rdstat [ i ] [ mode_idx ] . ta , bsi -> rdstat [ i ] [ mode_idx ] . tl , mi_row , mi_col ) ;
 if ( bsi -> rdstat [ i ] [ mode_idx ] . brdcost < INT64_MAX ) {
 bsi -> rdstat [ i ] [ mode_idx ] . brdcost += RDCOST ( x -> rdmult , x -> rddiv , bsi -> rdstat [ i ] [ mode_idx ] . brate , 0 ) ;
 bsi -> rdstat [ i ] [ mode_idx ] . brate += bsi -> rdstat [ i ] [ mode_idx ] . byrate ;
 bsi -> rdstat [ i ] [ mode_idx ] . eobs = p -> eobs [ i ] ;
 if ( num_4x4_blocks_wide > 1 ) bsi -> rdstat [ i + 1 ] [ mode_idx ] . eobs = p -> eobs [ i + 1 ] ;
 if ( num_4x4_blocks_high > 1 ) bsi -> rdstat [ i + 2 ] [ mode_idx ] . eobs = p -> eobs [ i + 2 ] ;
 }
 if ( bsi -> rdstat [ i ] [ mode_idx ] . brdcost < best_rd ) {
 mode_selected = this_mode ;
 best_rd = bsi -> rdstat [ i ] [ mode_idx ] . brdcost ;
 }
 }
 if ( best_rd == INT64_MAX ) {
 int iy , midx ;
 for ( iy = i + 1 ;
 iy < 4 ;
 ++ iy ) for ( midx = 0 ;
 midx < INTER_MODES ;
 ++ midx ) bsi -> rdstat [ iy ] [ midx ] . brdcost = INT64_MAX ;
 bsi -> segment_rd = INT64_MAX ;
 return INT64_MAX ;
 ;
 }
 mode_idx = INTER_OFFSET ( mode_selected ) ;
 vpx_memcpy ( t_above , bsi -> rdstat [ i ] [ mode_idx ] . ta , sizeof ( t_above ) ) ;
 vpx_memcpy ( t_left , bsi -> rdstat [ i ] [ mode_idx ] . tl , sizeof ( t_left ) ) ;
 set_and_cost_bmi_mvs ( cpi , xd , i , mode_selected , mode_mv [ mode_selected ] , frame_mv , seg_mvs [ i ] , bsi -> ref_mv , x -> nmvjointcost , x -> mvcost ) ;
 br += bsi -> rdstat [ i ] [ mode_idx ] . brate ;
 bd += bsi -> rdstat [ i ] [ mode_idx ] . bdist ;
 block_sse += bsi -> rdstat [ i ] [ mode_idx ] . bsse ;
 segmentyrate += bsi -> rdstat [ i ] [ mode_idx ] . byrate ;
 this_segment_rd += bsi -> rdstat [ i ] [ mode_idx ] . brdcost ;
 if ( this_segment_rd > bsi -> segment_rd ) {
 int iy , midx ;
 for ( iy = i + 1 ;
 iy < 4 ;
 ++ iy ) for ( midx = 0 ;
 midx < INTER_MODES ;
 ++ midx ) bsi -> rdstat [ iy ] [ midx ] . brdcost = INT64_MAX ;
 bsi -> segment_rd = INT64_MAX ;
 return INT64_MAX ;
 ;
 }
 }
 }
 bsi -> r = br ;
 bsi -> d = bd ;
 bsi -> segment_yrate = segmentyrate ;
 bsi -> segment_rd = this_segment_rd ;
 bsi -> sse = block_sse ;
 for ( k = 0 ;
 k < 4 ;
 ++ k ) bsi -> modes [ k ] = mi -> bmi [ k ] . as_mode ;
 if ( bsi -> segment_rd > best_rd ) return INT64_MAX ;
 for ( i = 0 ;
 i < 4 ;
 i ++ ) {
 mode_idx = INTER_OFFSET ( bsi -> modes [ i ] ) ;
 mi -> bmi [ i ] . as_mv [ 0 ] . as_int = bsi -> rdstat [ i ] [ mode_idx ] . mvs [ 0 ] . as_int ;
 if ( has_second_ref ( mbmi ) ) mi -> bmi [ i ] . as_mv [ 1 ] . as_int = bsi -> rdstat [ i ] [ mode_idx ] . mvs [ 1 ] . as_int ;
 x -> plane [ 0 ] . eobs [ i ] = bsi -> rdstat [ i ] [ mode_idx ] . eobs ;
 mi -> bmi [ i ] . as_mode = bsi -> modes [ i ] ;
 }
 * returntotrate = bsi -> r ;
 * returndistortion = bsi -> d ;
 * returnyrate = bsi -> segment_yrate ;
 * skippable = vp9_is_skippable_in_plane ( x , BLOCK_8X8 , 0 ) ;
 * psse = bsi -> sse ;
 mbmi -> mode = bsi -> modes [ 3 ] ;
 return bsi -> segment_rd ;
 }


static void pdf_process_SC ( fz_context * ctx , pdf_processor * proc , pdf_csi * csi , int stroke ) {
 if ( csi -> name [ 0 ] ) {
 pdf_obj * patres , * patobj , * type ;
 patres = pdf_dict_get ( ctx , csi -> rdb , PDF_NAME_Pattern ) ;
 if ( ! patres ) fz_throw ( ctx , FZ_ERROR_SYNTAX , "cannot find Pattern dictionary" ) ;
 patobj = pdf_dict_gets ( ctx , patres , csi -> name ) ;
 if ( ! patobj ) fz_throw ( ctx , FZ_ERROR_SYNTAX , "cannot find Pattern resource '%s'" , csi -> name ) ;
 type = pdf_dict_get ( ctx , patobj , PDF_NAME_PatternType ) ;
 if ( pdf_to_int ( ctx , type ) == 1 ) {
 if ( proc -> op_SC_pattern && proc -> op_sc_pattern ) {
 pdf_pattern * pat = pdf_load_pattern ( ctx , csi -> doc , patobj ) ;
 fz_try ( ctx ) {
 if ( stroke ) proc -> op_SC_pattern ( ctx , proc , csi -> name , pat , csi -> top , csi -> stack ) ;
 else proc -> op_sc_pattern ( ctx , proc , csi -> name , pat , csi -> top , csi -> stack ) ;
 }
 fz_always ( ctx ) pdf_drop_pattern ( ctx , pat ) ;
 fz_catch ( ctx ) fz_rethrow ( ctx ) ;
 }
 }
 else if ( pdf_to_int ( ctx , type ) == 2 ) {
 if ( proc -> op_SC_shade && proc -> op_sc_shade ) {
 fz_shade * shade = pdf_load_shading ( ctx , csi -> doc , patobj ) ;
 fz_try ( ctx ) {
 if ( stroke ) proc -> op_SC_shade ( ctx , proc , csi -> name , shade ) ;
 else proc -> op_sc_shade ( ctx , proc , csi -> name , shade ) ;
 }
 fz_always ( ctx ) fz_drop_shade ( ctx , shade ) ;
 fz_catch ( ctx ) fz_rethrow ( ctx ) ;
 }
 }
 else {
 fz_throw ( ctx , FZ_ERROR_SYNTAX , "unknown pattern type: %d" , pdf_to_int ( ctx , type ) ) ;
 }
 }
 else {
 if ( proc -> op_SC_color && proc -> op_sc_color ) {
 if ( stroke ) proc -> op_SC_color ( ctx , proc , csi -> top , csi -> stack ) ;
 else proc -> op_sc_color ( ctx , proc , csi -> top , csi -> stack ) ;
 }
 }
 }


AvahiSDNSServerBrowser *avahi_s_dns_server_browser_new(
    AvahiServer *server,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    const char *domain,
    AvahiDNSServerType type,
    AvahiProtocol aprotocol,
    AvahiLookupFlags flags,
    AvahiSDNSServerBrowserCallback callback,
    void* userdata) {
        AvahiSDNSServerBrowser* b;

        b = avahi_s_dns_server_browser_prepare(server, interface, protocol, domain, type, aprotocol, flags, callback, userdata);
        avahi_s_dns_server_browser_start(b);

        return b;
}


AvahiSHostNameResolver *avahi_s_host_name_resolver_new(
    AvahiServer *server,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    const char *host_name,
    AvahiProtocol aprotocol,
    AvahiLookupFlags flags,
    AvahiSHostNameResolverCallback callback,
    void* userdata) {
        AvahiSHostNameResolver *b;

        b = avahi_s_host_name_resolver_prepare(server, interface, protocol, host_name, aprotocol, flags, callback, userdata);
        avahi_s_host_name_resolver_start(b);

        return b;
}


static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) { IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); IDEState *s = bus->ifs + dev->unit; Error *err = NULL; if (dev->conf.discard_granularity == -1) { dev->conf.discard_granularity = 512; } else if (dev->conf.discard_granularity && dev->conf.discard_granularity != 512) { error_report("discard_granularity must be 512 for ide"); blkconf_serial(&dev->conf, &dev->serial); if (kind != IDE_CD) { blkconf_geometry(&dev->conf, &dev->chs_trans, 65536, 16, 255, &err); if (err) { error_report("%s", error_get_pretty(err)); error_free(err); if (ide_init_drive(s, dev->conf.blk, kind, dev->version, dev->serial, dev->model, dev->wwn, dev->conf.cyls, dev->conf.heads, dev->conf.secs, dev->chs_trans) < 0) { if (!dev->version) { dev->version = g_strdup(s->version); if (!dev->serial) { dev->serial = g_strdup(s->drive_serial_str); add_boot_device_path(dev->conf.bootindex, &dev->qdev, dev->unit ? "/disk@1" : "/disk@0"); return 0;


static int writer_open(WriterContext **wctx, const Writer *writer, const char *args, const struct section *sections, int nb_sections) { int i, ret = 0; if (!(*wctx = av_malloc(sizeof(WriterContext)))) { ret = AVERROR(ENOMEM); goto fail; } if (!((*wctx)->priv = av_mallocz(writer->priv_size))) { ret = AVERROR(ENOMEM); goto fail; } (*wctx)->class = &writer_class; (*wctx)->writer = writer; (*wctx)->level = -1; (*wctx)->sections = sections; (*wctx)->nb_sections = nb_sections; if (writer->priv_class) { void *priv_ctx = (*wctx)->priv; *((const AVClass **)priv_ctx) = writer->priv_class; av_opt_set_defaults(priv_ctx); if (args && (ret = av_set_options_string(priv_ctx, args, "=", ":")) < 0) goto fail; } for (i = 0; i < SECTION_MAX_NB_LEVELS; i++) av_bprint_init(&(*wctx)->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED); if ((*wctx)->writer->init) ret = (*wctx)->writer->init(*wctx); if (ret < 0) goto fail; return 0; fail: writer_close(wctx); return ret; }