validate config map and initialize SinglePairCtx
| 181 | |
| 182 | // validate config map and initialize SinglePairCtx |
| 183 | static ProcedureResult validate_config |
| 184 | ( |
| 185 | SIValue config, |
| 186 | SinglePairCtx *ctx |
| 187 | ) { |
| 188 | SIValue start; // start node |
| 189 | SIValue end; // end node |
| 190 | SIValue relationships; // relationship types allowed |
| 191 | SIValue dir; // direction |
| 192 | SIValue max_length; // max traverse length |
| 193 | SIValue weight_prop; // weight attribute name |
| 194 | SIValue cost_prop; // cost attribute name |
| 195 | SIValue max_cost; // maximum cost |
| 196 | SIValue path_count; // # of paths to return |
| 197 | |
| 198 | bool start_exists = MAP_GET(config, "sourceNode", start); |
| 199 | bool end_exists = MAP_GET(config, "targetNode", end); |
| 200 | bool relationships_exists = MAP_GET(config, "relTypes", relationships); |
| 201 | bool dir_exists = MAP_GET(config, "relDirection", dir); |
| 202 | bool max_length_exists = MAP_GET(config, "maxLen", max_length); |
| 203 | bool weight_prop_exists = MAP_GET(config, "weightProp", weight_prop); |
| 204 | bool cost_prop_exists = MAP_GET(config, "costProp", cost_prop); |
| 205 | bool max_cost_exists = MAP_GET(config, "maxCost", max_cost); |
| 206 | bool path_count_exists = MAP_GET(config, "pathCount", path_count); |
| 207 | |
| 208 | |
| 209 | if(!start_exists || !end_exists) { |
| 210 | ErrorCtx_SetError("sourceNode and targetNode are required"); |
| 211 | return false; |
| 212 | } |
| 213 | if(SI_TYPE(start) != T_NODE || SI_TYPE(end) != T_NODE) { |
| 214 | ErrorCtx_SetError("sourceNode and targetNode must be of type Node"); |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | GRAPH_EDGE_DIR direction = GRAPH_EDGE_DIR_OUTGOING; |
| 219 | if(dir_exists) { |
| 220 | if(SI_TYPE(dir) != T_STRING) { |
| 221 | ErrorCtx_SetError("relDirection values must be 'incoming', 'outgoing' or 'both'"); |
| 222 | return false; |
| 223 | } |
| 224 | if(strcasecmp(dir.stringval, "incoming") == 0) { |
| 225 | direction = GRAPH_EDGE_DIR_INCOMING; |
| 226 | } else if(strcasecmp(dir.stringval, "outgoing") == 0) { |
| 227 | direction = GRAPH_EDGE_DIR_OUTGOING; |
| 228 | } else if(strcasecmp(dir.stringval, "both") == 0) { |
| 229 | direction = GRAPH_EDGE_DIR_BOTH; |
| 230 | } else { |
| 231 | ErrorCtx_SetError("relDirection values must be 'incoming', 'outgoing' or 'both'"); |
| 232 | return false; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | int64_t max_length_val = LONG_MAX - 1; |
| 237 | if(max_length_exists) { |
| 238 | if(SI_TYPE(max_length) != T_INT64) { |
| 239 | ErrorCtx_SetError("maxLen must be integer"); |
| 240 | return false; |
no test coverage detected