Updated on 2026-11-17 GMT+08:00

Viewing Event Notification Settings (SDK for C)

You can call get_notification_configuration to view event notification settings of a bucket.

Method

void get_notification_configuration(const obs_options *options,
        obs_smn_handler *handler,  void *callback_data);

Parameter Description

Field

Type

Mandatory or Optional

Description

options

Request for the context of the bucket, see Configuring option (SDK for C)

Mandatory

Bucket parameter

handler

obs_smn_handler *

Mandatory

Callback function

callback_data

void *

Optional

Callback data

The following table describes the callback function types of obs_smn_handler.

Field

Type

Description

response_handler

obs_response_handler

Callback function handler for response

get_smn_callback_func

obs_smn_callback *

Callback function for obtaining the notification configuration of a bucket

Code Examples

#include "eSDKOBS.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// The response callback function. In this callback, you can record the content of properties into callback_data (custom callback data).
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data);
// The completion callback function. In this callback, you can record the content of obs_status and obs_error_details into callback_data (custom callback data).
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data);
// The callback function for viewing event notification settings. It parses the returned notification_conf structure.
obs_status get_notification_info_callback(obs_smn_notification_configuration *notification_conf, void *callback_data);

int main()
{
    // The following example shows how to view event notification settings of a bucket:
    // Call the obs_initialize method at the program entry to initialize global resources such as the network and memory.
    obs_status ret_status = obs_initialize(OBS_INIT_ALL);
    if (OBS_STATUS_OK != ret_status) {
        printf("obs_initialize failed(%s).\n", obs_get_status_name(ret_status));
        return -1;
    }

    obs_options options;
    // Create and initialize options, including the access domain name (host_name), access keys (access_key_id and access_key_secret), bucket name (bucket_name), and bucket storage class (storage_class).
    init_obs_options(&options);
    
   
    // Enter the endpoint corresponding to the bucket for host_name. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    options.bucket_options.host_name = "obs.ap-southeast-1.myhuaweicloud.com";
   
   
    
    
    // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
    // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
    options.bucket_options.access_key = getenv("ACCESS_KEY_ID");
    options.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
    // Specify the bucket name, for example, example-bucket-name.
    char *bucketName = "example-bucket-name";
    options.bucket_options.bucket_name = bucketName;

    // Set callback functions (including response callback and data callback for viewing notification settings).
    obs_smn_handler notification_handler_info = {
        {&response_properties_callback, &response_complete_callback},
        &get_notification_info_callback};

    ret_status = OBS_STATUS_BUTT;
    // View the event notification settings of the bucket.
    get_notification_configuration(&options, &notification_handler_info, &ret_status);
    if (OBS_STATUS_OK == ret_status) {
        printf("get_notification_config success.\n");
    } else {
        printf("get_notification_config failed(%s).\n", obs_get_status_name(ret_status));
    }

    // Release the allocated global resources.
    obs_deinitialize();
    return 0;
}

// The callback function for viewing event notification settings. It parses the returned notification_conf structure.
obs_status get_notification_info_callback(obs_smn_notification_configuration *notification_conf, void *callback_data)
{
    int i = 0;
    int j = 0;
    (void)callback_data;
    if (notification_conf == NULL) {
        printf("notification_conf is null.\n");
        return OBS_STATUS_OK;
    }
    printf("topic_conf_num=%d\n", notification_conf->topic_conf_num);

    for (i = 0; i < notification_conf->topic_conf_num; i++) {
        printf("******************** num(%d) *************************\n", i);
        printf("id: %s\n", notification_conf->topic_conf[i].id ? notification_conf->topic_conf[i].id : "(null)");
        printf("topic: %s\n", notification_conf->topic_conf[i].topic ? notification_conf->topic_conf[i].topic : "(null)");
        printf("event_num: %d\n", notification_conf->topic_conf[i].event_num);
        for (j = 0; j < notification_conf->topic_conf[i].event_num; j++) {
            printf("    event: %d\n", notification_conf->topic_conf[i].event[j]);
        }
        printf("filter_rule_num: %d\n", notification_conf->topic_conf[i].filter_rule_num);
        for (j = 0; j < notification_conf->topic_conf[i].filter_rule_num; j++) {
            printf("    name: %d, value: %s\n",
                   notification_conf->topic_conf[i].filter_rule[j].name,
                   notification_conf->topic_conf[i].filter_rule[j].value ? notification_conf->topic_conf[i].filter_rule[j].value : "(null)");
        }
    }
    return OBS_STATUS_OK;
}

// The response callback function. In this callback, you can record the content of properties into callback_data (custom callback data).
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data)
{
    (void)callback_data;
    if (properties == NULL) {
        return OBS_STATUS_OK;
    }
    if (properties->request_id) {
        printf("request_id: %s\n", properties->request_id);
    }
    if (properties->request_id2) {
        printf("request_id2: %s\n", properties->request_id2);
    }
    return OBS_STATUS_OK;
}

// The completion callback function. In this callback, you can record the content of obs_status and obs_error_details into callback_data (custom callback data).
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data)
{
    obs_status *ret_status = (obs_status *)callback_data;
    if (ret_status) {
        *ret_status = status;
    }
    if (error && error->message) {
        printf("Error Message: %s\n", error->message);
    }
    if (error && error->resource) {
        printf("Error Resource: %s\n", error->resource);
    }
    if (error && error->extra_details_count) {
        int i;
        for (i = 0; i < error->extra_details_count; i++) {
            printf("Error Extra Detail(%d): %s:%s\n", i,
                   error->extra_details[i].name, error->extra_details[i].value);
        }
    }
}