Skip to content

Conversation

@UBiqube-ydu
Copy link
Contributor

No description provided.

@UBiqube-ydu UBiqube-ydu requested a review from a team as a code owner January 22, 2026 14:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances error management in the Stormshield adapter by adding XML response error checking and refactoring the curl command execution flow.

Changes:

  • Moved return code arrays to global scope for reuse between functions
  • Added new is_error_xml() function to check for errors in SimpleXMLElement responses
  • Refactored curl command handling to store the curl command as a class property and added XML error validation after API calls

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
adapters/stormshield/nsrpc.php Moved return code validation arrays to file scope and added new is_error_xml() function for XML response error checking
adapters/stormshield/connect.php Refactored curl command execution to validate XML responses and store curl command as instance property for better error reporting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 135 to 136
$rc = (int)$serverd['ret'];
if (empty($ok_return_code[$rc]) && empty($not_a_return_code[$rc]))
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type inconsistency in return code lookup. Line 135 casts the return code to int, but then line 136 uses this integer to look up values in arrays that have string keys ("100", "103", etc.). In PHP, array access with integer 100 will not match string key "100" in a reliable way. Either remove the (int) cast on line 135, or change the global array keys to integers to ensure consistent type handling.

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +160
$ret = is_error_xml($this->response);
if ($ret !== false)
{
throw new SmsException("Response to API {$this->curl_cmd} Failed: \n$ret", ERR_SD_CMDFAILED, $origin);
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference error. The function is_error_xml() is called with $this->response which may be null or unset. If the HTTP response is empty and the status code is 204, the response object is never initialized (see lines 229-231), but the error checking at line 157 will still execute. Add a check to ensure $this->response is set before calling is_error_xml(), or handle null/unset values within the is_error_xml() function.

Suggested change
$ret = is_error_xml($this->response);
if ($ret !== false)
{
throw new SmsException("Response to API {$this->curl_cmd} Failed: \n$ret", ERR_SD_CMDFAILED, $origin);
if ($this->response !== null && $this->response !== '') {
$ret = is_error_xml($this->response);
if ($ret !== false)
{
throw new SmsException("Response to API {$this->curl_cmd} Failed: \n$ret", ERR_SD_CMDFAILED, $origin);
}

Copilot uses AI. Check for mistakes.
throw new SmsException ("$origin: Response to API {$this->curl_cmd} Failed, expected json received empty response, header $header", ERR_SD_CMDFAILED);
}
}
debug_dump($this->response, "HTTP RESPONSE:\n");
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug output moved to after potential exception. The debug_dump for "HTTP RESPONSE" has been moved from before the error checking (original position) to after the curl execution at line 233. This means that if an error occurs at lines 212-215 or 229-230, the response debug output will not be shown. Consider whether this is the intended behavior, as it may make debugging failed requests more difficult.

Copilot uses AI. Check for mistakes.
}

/*
* Get return codes of SimpleXMLElement response from the ME
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete or unclear documentation. The comment states the function gets return codes "from the ME", but "ME" is not defined or explained. Consider clarifying what "ME" stands for (e.g., "Managed Entity" or the appropriate term) to improve code documentation.

Suggested change
* Get return codes of SimpleXMLElement response from the ME
* Get return codes of a SimpleXMLElement response from the Management Engine (ME)

Copilot uses AI. Check for mistakes.
"111" => true,
);

// intermediate return code, it is normaly followed by another return code
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'normaly' should be 'normally'.

Suggested change
// intermediate return code, it is normaly followed by another return code
// intermediate return code, it is normally followed by another return code

Copilot uses AI. Check for mistakes.
@UBiqube-ydu UBiqube-ydu merged commit bbdb94f into master Jan 22, 2026
2 checks passed
@UBiqube-ydu UBiqube-ydu deleted the 3.3.0/OPSLAB-245/ydu2 branch January 22, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants