0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <stdlib.h>
0035 #include <string.h>
0036 #include <memory.h>
0037 #include <ctype.h>
0038 #include <errno.h>
0039
0040 #include <userlog.h>
0041
0042 #include <ndrstandard.h>
0043 #include <ndebug.h>
0044
0045 #include <exparson.h>
0046 #include <pgxa.h>
0047
0048
0049
0050
0051
0052 #define NDRX_ECPG_COMPAT_PGSQL 0
0053 #define NDRX_ECPG_COMPAT_INFORMIX 1
0054 #define NDRX_ECPG_COMPAT_INFORMIX_SE 1
0055
0056 #define CONF_URL 1
0057 #define CONF_USER 2
0058 #define CONF_PASS 3
0059 #define CONF_COMPAT 4
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 expublic int ndrx_pg_xa_cfgparse(char *buffer, ndrx_pgconnect_t *conndata)
0076 {
0077 int ret = EXSUCCEED;
0078 EXJSON_Value *root_value=NULL;
0079 EXJSON_Object *root_object;
0080 size_t i, cnt, j, n;
0081 char *name;
0082 char *str_val;
0083 int typ;
0084 int param;
0085
0086 NDRX_LOG(log_debug, "Parsing buffer: [%s]", buffer);
0087
0088 root_value = exjson_parse_string_with_comments(buffer);
0089
0090 if (exjson_value_get_type(root_value) != EXJSONObject)
0091 {
0092 NDRX_LOG(log_debug, "Failed to parse root element");
0093 EXFAIL_OUT(ret);
0094 goto out;
0095 }
0096
0097 memset(conndata, 0, sizeof(ndrx_pgconnect_t));
0098
0099 root_object = exjson_value_get_object(root_value);
0100
0101 cnt = exjson_object_get_count(root_object);
0102 NDRX_LOG(log_debug, "cnt = %d", cnt);
0103
0104 for (i=0; i<cnt; i++)
0105 {
0106 name = (char *)exjson_object_get_name(root_object, i);
0107
0108 if (
0109 ((param=CONF_URL) && 0==strcmp(name, "url")) ||
0110 ((param=CONF_USER) && 0==strcmp(name, "user")) ||
0111 ((param=CONF_PASS) && 0==strcmp(name, "password")) ||
0112 ((param=CONF_COMPAT) && 0==strcmp(name, "compat"))
0113 )
0114 {
0115
0116 typ = exjson_value_get_type(exjson_object_get_value_at(root_object, i));
0117
0118 if (EXJSONString!=typ)
0119 {
0120 NDRX_LOG(log_error, "Invalid type %d for `%s', must be string",
0121 typ, name);
0122 EXFAIL_OUT(ret);
0123 }
0124
0125 str_val = (char *)exjson_object_get_string(root_object, name);
0126
0127 NDRX_LOG(log_debug, "Got [%s] = [%s]", name, str_val);
0128
0129 switch (param)
0130 {
0131 case CONF_URL:
0132 NDRX_STRCPY_SAFE(conndata->url, str_val);
0133 break;
0134 case CONF_USER:
0135 NDRX_STRCPY_SAFE(conndata->user, str_val);
0136 break;
0137 case CONF_PASS:
0138 NDRX_STRCPY_SAFE(conndata->password, str_val);
0139 break;
0140 case CONF_COMPAT:
0141
0142 if (0==strncmp(str_val, "INFORMIX", 8))
0143 {
0144 if (0==strcmp(str_val, "INFORMIX"))
0145 {
0146 conndata->c = NDRX_ECPG_COMPAT_INFORMIX;
0147 }
0148 else
0149 {
0150 conndata->c = NDRX_ECPG_COMPAT_INFORMIX_SE;
0151 }
0152 }
0153 else if (0!=strcmp(str_val, "PGSQL"))
0154 {
0155 NDRX_LOG(log_error, "Invalid compat node [%s]", str_val);
0156 EXFAIL_OUT(ret);
0157 }
0158
0159 break;
0160 }
0161 }
0162 else
0163 {
0164 NDRX_LOG(log_warn, "Skipping [%s] - unsupported", name);
0165 }
0166 }
0167
0168 out:
0169
0170 if (NULL != root_value)
0171 {
0172 exjson_value_free(root_value);
0173 }
0174
0175 return ret;
0176 }
0177
0178