/**
 *@file    sr_net_http.c
 *@brief   HTTP协议抽象接口
 *@details 提供HTTPC 创建/销毁、GET/POST请求、异步通知等功能的具体实现
 *@copyright Copyright (c) 2024 lierda. All rights reserved.
 *@author  Lierda-RDC
 *@date    2024-04-01
 *@example ZhaoyangSDK\example\component\net_http_example.c
 */

#include "sr_net_http.h"



SR_HTTP_CLIENT_T * SR_NetHttpcCreate(SR_NET_ADP_T *adp,HttpEventCb cb,void *cbArgs)
{
	SR_HTTP_CLIENT_T *httpc = SR_NULL;
	if((SR_NULL == adp) || (SR_NULL == cb)) return SR_NULL;

	SR_HTTPC_OPS_T *ops = (SR_HTTPC_OPS_T *)(adp->httpcOps);
 
    if ((SR_NULL == ops) ||(SR_NULL == ops->httpc_create))
    {
        return SR_NULL;
    }

	httpc = ops->httpc_create(cb,cbArgs);

	if(httpc) 
	{
		httpc->adapter = adp;
		return httpc;
	}
	else
		return SR_NULL;

}


int SR_NetHttpcDestroy(SR_HTTP_CLIENT_T *httpc)
{
	if((SR_NULL == httpc) || (SR_NULL == httpc->adapter)) return SR_INVALID;

    SR_HTTPC_OPS_T *ops = (SR_HTTPC_OPS_T *)httpc->adapter->httpcOps;

    if ((SR_NULL == ops) || (SR_NULL == ops->httpc_destroy))
    {
        return SR_NOIMPT;
    }

    return ops->httpc_destroy(httpc);


}



int SR_NetHttpcGet(SR_HTTP_CLIENT_T *httpc,char *url)
{
	if((SR_NULL == httpc) || (SR_NULL == httpc->adapter)) return SR_INVALID;

    SR_HTTPC_OPS_T *ops = (SR_HTTPC_OPS_T *)httpc->adapter->httpcOps;

    if ((SR_NULL == ops) || (SR_NULL == ops->httpc_get))
    {
        return SR_NOIMPT;
    }

    return ops->httpc_get(httpc,url);
}

int SR_NetHttpcStop(SR_HTTP_CLIENT_T *httpc)
{
	if((SR_NULL == httpc) || (SR_NULL == httpc->adapter)) return SR_INVALID;

    SR_HTTPC_OPS_T *ops = (SR_HTTPC_OPS_T *)httpc->adapter->httpcOps;

    if ((SR_NULL == ops) || (SR_NULL == ops->httpc_stop))
    {
        return SR_NOIMPT;
    }

    return ops->httpc_stop(httpc);
}


